JSON icon indicating copy to clipboard operation
JSON copied to clipboard

Suggested improvement on errror reporting

Open jackdeguest opened this issue 3 years ago • 0 comments

In JSON, when encoding, and when dealing with a blessed object and all attempts have failed, the module yields something like: encountered object 'XXX', but neither allow_blessed, convert_blessed nor allow_tags settings are enabled (or TO_JSON/FREEZE method missing) where XXX is the object reference.

When the object has overload stringification capability, this error message becomes unhelpful, because we do not know the source of the issue, i.e. which package is at fault. Thus, I would recommend changing the error to use overload::StrVal( $obj ). Maybe something like:

encode_error( sprintf("encountered object '%s', but neither allow_blessed, convert_blessed nor allow_tags settings are enabled (or TO_JSON/FREEZE method missing)", overload::StrVal($obj))

jackdeguest avatar Sep 06 '21 18:09 jackdeguest