makamaka / JSON

perl implementation of JSON encoder/decoder
42 stars 40 forks source link

Suggested improvement on errror reporting #50

Open jackdeguest opened 3 years ago

jackdeguest commented 3 years ago

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))