Improved error handling message for type-checked return type.