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

Error Handling: differentiating .errors and .issues on ZodError #3856

Open
ducin opened this issue Nov 18, 2024 · 0 comments
Open

Error Handling: differentiating .errors and .issues on ZodError #3856

ducin opened this issue Nov 18, 2024 · 0 comments

Comments

@ducin
Copy link

ducin commented Nov 18, 2024

Whenever working with zod errors/issues I find out that issues and errors have exactly the same content, like below:

image

sample code below:

try {
Schema.parse(something);
} catch (e) {
  if (e instanceof z.ZodError) {
    for (const zodIssue of e.issues) { // A
    for (const zodIssue of e.errors) { // B
      console.error(zodIssue.code);
      console.error(zodIssue.message);
      console.error(zodIssue.path);
    }
  }
}

and inside internal TS zod types, both properties relate to the same ZodIssue type:

export declare class ZodError<T = any> extends Error {
    issues: ZodIssue[];
    get errors(): ZodIssue[];

My question is: what's the difference between them? Why are they separate? I see docs relate to issues (and methods such as addIssue/addIssues exist). What's the point of errors anyway?

I've read error handling but it doesn't answer this question.

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

1 participant