ts-runtime-checks icon indicating copy to clipboard operation
ts-runtime-checks copied to clipboard

[FEATURE] Add actual value to the error message

Open shipurjan opened this issue 1 year ago • 2 comments

Is your feature request related to a problem? Please describe. Currently the error message doesn't specify what value was received, only what was expected

Describe the solution you'd like An error message similar to Expected value.name to be a string, but received ${JSON.stringify(value.name)} instead of Expected value.name to be a string

Describe alternatives you've considered Creating my own type with overridden error, but it takes some boilerplate and I think it would be good to have in the main type too. Also I could just create a try/catch block and append it to the error myself, but then I would not have access to atomic values of the specific check, only to the entire object.

I'm just requesting, maybe it'll be useful as a feature. Or maybe it's too bloated for the scope of this lib.

shipurjan avatar Dec 23 '24 16:12 shipurjan

I think this is a good idea, but it has to be made optional.

For now you could use try/catch and raw errors, it'll give you the specific value and the expected value and you could build the error message yourself

GoogleFeud avatar Dec 23 '24 16:12 GoogleFeud

This is a must-have feature for me. It’s very unnecessarily difficult to troubleshoot what went wrong when a check in some deeply nested object fails.

It'll give you the specific value and the expected value and you could build the error message yourself.

I don’t see how’s that possible – the raw error object (ValidationError) contains just the result of error[0].getRawTypeData(), not the Validator instance that provides the translate() method used to generate a human-readable description of the expected type.

jirutka avatar Jan 12 '25 17:01 jirutka