Skip to content

Clubbing .parse and .refine errors/issues in v3 #437

Answered by colinhacks
maneetgoyal asked this question in Q&A
Discussion options

You must be logged in to vote

I understand the need for something like this, but it's not likely in the short term. Zod doesn't catch errors that are thrown inside of refinements, so passing an invalid value into a refinement function is likely to throw an unexpected error. Zod schemas validate types first, then pass that value through a chain of refinements/transformations. Passing invalid data into this chain is not the intended behavior.

The "right" way to solve this is to differentiate between fatal and non-fatal validation issues. That way if there is a minor validation issue "inside" an object, we could still run the outer refinements.

z.object({
  name: z.string().min(5, { nonfatal: true }),
}).refine(val => /*…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@maneetgoyal
Comment options

@colinhacks
Comment options

Answer selected by maneetgoyal
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants