Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEATURE] Add actual value to the error message #70

Open
shipurjan opened this issue Dec 23, 2024 · 2 comments
Open

[FEATURE] Add actual value to the error message #70

shipurjan opened this issue Dec 23, 2024 · 2 comments

Comments

@shipurjan
Copy link

shipurjan commented Dec 23, 2024

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.

@GoogleFeud
Copy link
Owner

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

@jirutka
Copy link

jirutka commented Jan 12, 2025

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants