zod icon indicating copy to clipboard operation
zod copied to clipboard

Reporting errors of the preprocess that is the second property of object

Open yukukotani opened this issue 2 years ago • 6 comments

Fix https://github.com/colinhacks/zod/issues/2904

This behavior was introduced in #2426. ctx.common.issues includes the errors of previous properties, so that they affects the status of preprocess.

yukukotani avatar Oct 27 '23 17:10 yukukotani

Deploy Preview for guileless-rolypoly-866f8a ready!

Name Link
Latest commit 152bfdb796ff89594a0177bd4697785f19c3e817
Latest deploy log https://app.netlify.com/sites/guileless-rolypoly-866f8a/deploys/65fc90d2ad067c0008589605
Deploy Preview https://deploy-preview-2912--guileless-rolypoly-866f8a.netlify.app
Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

netlify[bot] avatar Oct 27 '23 17:10 netlify[bot]

I'm not confident in my understanding of the whole codebase and the change in #2426.

@Pingviinituutti Could you take a look at this PR?

yukukotani avatar Oct 27 '23 17:10 yukukotani

Looks good to me, seems the simple fix is enough to :)

Are the current test cases enough to ensure it works as intended?

Pingviinituutti avatar Oct 28 '23 10:10 Pingviinituutti

@Pingviinituutti Thanks!

Are the current test cases enough to ensure it works as intended?

The current test cases are fail on master branch, so I think it's minimum but enough.

yukukotani avatar Oct 28 '23 15:10 yukukotani

Is there any movement on this? This is causing major issues for us.

Austin-Love avatar Nov 30 '23 15:11 Austin-Love

@Austin-Love This is ready and waiting for getting review

yukukotani avatar Nov 30 '23 16:11 yukukotani

Great stuff @yukukotani and apologies to everyone who waited so long for this.

I made some fairly major changes to ctx.addIssue in preprocess, so it behaved identically to .superRefine and .transform. Namely, all issues are considered non-fatal — validation will continue even if .addIssue was called during the preprocess. This behavior can be modified by indicating fatal: true in ctx.addIssue:

    const schema = z.preprocess((data, ctx) => {
      ctx.addIssue({
        code: "custom",
        message: `bad thing happened`,
        fatal: true
      });
      return data;
    }, z.string())

colinhacks avatar Mar 21 '24 00:03 colinhacks