-
-
Notifications
You must be signed in to change notification settings - Fork 169
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
Throw any error unrelated to Zod #504
Conversation
Error should be associated to a field (by its name). That's how work resolvers with react-hook-form. |
Yes, @jorisre let's keep it that way unless we have a general implementation for all resolvers. This would create inconsistency between all. |
Thank you for the quick reply! I'm not sure I understand. Are you saying instead of checking whether an error is of type |
Thank you for your contributions! This Pull Request has been automatically marked as stale because it has not had any recent activity. It will be closed if no further activity occurs. Best, RHF Team ❤️ |
Let me know what changes are required for this to get through, or whether you want to close this, thank you! |
@stephan281094 resolvers return errors that are linked to a field by its path. In your case, your refine isn't linked to a field. https://zod.dev/?id=customize-error-path schema.refine((obj) => obj.password === obj.repeatPassword, {
message: 'Passwords do not match',
path: ['confirm'], // 👈 reference the field
}) |
Thanks for clarifying, Joris. I understand that errors thrown when For example, the following piece of code: schema.refine((obj) => {
return obj.non.existing.property
}) throws:
when it should be throwing:
The Zod resolver currently, incorrectly assumes the error that gets caught, is always a Zod Error. In the code you can see I hope I've been able to better clarify the issue this pull request is solving. |
That's correct, we do something similar for the yup resolver. Can you fix conflicts? Thank you |
Here is #528 that fix all resolvers |
Cloising in favor of #528 |
Amazing, thank you! 🙌 |
This pull request makes sure that errors that are not of type
ZodError
are thrown. It's possible for errors other thanZodError
to occur when using things like.refine
(for instance by referencing the property of a non-existent item in an array). Currently, when this happens, you get the following error:This took me a long time to debug today, because it was not clear where this error was coming from, nor was it very descriptive. Hopefully this change will save someone's time in the future!
Please let me know if any changes are necessary. I'll gladly update the pull request.