Show an error message if an incorrect AS handler is used

Fixes a crash if the input to the AS is nil.

See the comments at #1048

Merge target is release