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

Better errors for wrong schema #3408

Open
cdtut opened this issue Apr 16, 2024 · 2 comments
Open

Better errors for wrong schema #3408

cdtut opened this issue Apr 16, 2024 · 2 comments

Comments

@cdtut
Copy link

cdtut commented Apr 16, 2024

If you use {} instead of z.object({}) you get TypeError: keyValidator._parse is not a function which is not clear. There should be understandable error message that says you need z.object({}) instead of plain object.

Same thing on z.enum('value', 'value') there is error TypeError: array.map is not a function instead of telling you to wrap it in array like z.enum(['value', 'value']).

@cdtut
Copy link
Author

cdtut commented Apr 17, 2024

Also argument validation should be there for example if you pass arguments like z.string(pattern) when you meant z.string().regex(pattern) it works but should be error saying wrong arguments passed.

@capaj
Copy link

capaj commented May 11, 2024

Thanks for opening this @cdtut.
Took me like 45 minutes to debug-I was passing zod.object instead of plain object into schema.extend()

I mean TS types did warn me, but in case you have the line ignored the error is mindboggling. Why doesn't it throw right there on the line where I call extend()?

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

2 participants