Skip to content

ZodError[] doesn't contain error from refine() or superRefine() #2971

Discussion options

You must be logged in to vote

superRefine, transform, and refine, don't run if the prior schema fails. I'm pretty sure this is intended behavior.

Here is a much more simplified example to better illustrate the issue:

const schema = z.object( { foo: z.string() } )
    .superRefine( () => { console.log( 'superRefine' ) } )

console.log( 'test1' )
schema.safeParse( {} ) // doesn't run superRefine because the z.object fails

console.log()
console.log( 'test2' )
schema.safeParse( { foo: undefined } ) // doesn't run superRefine because the z.object fails

console.log()
console.log( 'test3' )
schema.safeParse( { foo: 'bar' } ) // runs superRefine because the z.object passes

/* 
console:
test1

test2

test3
superRefine
*/

If…

Replies: 5 comments 6 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@scotttrinh
Comment options

Comment options

You must be logged in to vote
5 replies
@wkd-kapsule
Comment options

@JacobWeisenburger
Comment options

@wkd-kapsule
Comment options

@JacobWeisenburger
Comment options

@spiasecki
Comment options

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

This discussion was converted from issue #2957 on November 16, 2023 14:31.