Error checking for visit() shared pointers have to be valid

Signed-off-by: Vinzenz Feenstra <evilissimo@gmail.com>