errors: extract type detection & use in ERR_INVALID_RETURN_VALUE
#43558
+187
−30
ERR_INVALID_RETURN_VALUE
#43558