Zod exception should include the input data
See original GitHub issueHello.
When I run validator on incorrect data I get ZodError
that does not contain the original data, only Zod info about what went wrong and on what path etc.
I think it would be beneficial to have the original data also included in the ZodError, since it would make the debugging much easier.
My use case:
I am communicating with API that is not well documented. The APIs responses are big and complicated (union types) and the structure of the responses is not documented at all, so I have to guess little bit. When there is an exception, the Zod error itself does not have enough information for me to fix it. So I had to wrap the Zod library, and in cases when the validation does not pass, I log the original data, along with the ZodError.
So my line of thinking was that adding the original data into the ZodError could make the errors much easier to understand and it would remove the need for wrapping the Zod library for me and probably other people.
Proposal
Add input data into the ZodError
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (1 by maintainers)
Top GitHub Comments
@scotttrinh Should be safe to add an
inputData
property on ZodError as long as it doesn’t get logged by the.message
getter. Then users who want to inspect/print the input can do so, but it’s unlikely to get logged accidentally.This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.