Check if specified target is valid

See #518.

Signed-off-by: Timothy Gu <timothygu99@gmail.com>