Skip to content

docs(parser): document reporting errors from schema transforms - #5838

Merged
dreamorosi merged 2 commits into
mainfrom
docs/parser-transform-errors
Oct 23, 2026
Merged

dreamorosi merged 2 commits into
mainfrom
docs/parser-transform-errors

Conversation

@svozza

@svozza svozza commented Oct 23, 2026

Copy link
Copy Markdown
Contributor

Summary

Zod doesn't catch errors thrown inside a transform, so they are thrown even when safeParse is used ("Transform functions should never throw", Zod docs). This PR documents that behaviour in the parser docs and shows how to report a transform failure as a validation error with ctx.issues and z.NEVER, the same way the built-in helpers like JSONStringified do.

Changes

  • Add a "Reporting errors from transforms" subsection under "Custom validation" in docs/features/parser.md, explaining that thrown errors aren't caught and showing the ctx.issues.push / z.NEVER pattern.
  • Add the examples/snippets/parser/transformIssues.ts snippet, a transform that catches the URIError from decodeURIComponent and reports it as a custom issue.
  • Add a note to the "Safe parsing" section that safeParse doesn't catch errors thrown by a schema's transform, linking to the new subsection.

Issue number: closes #5769


By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Disclaimer: We value your time and bandwidth. As such, any pull requests created on non-triaged issues might not be successful.

🤖 Generated with Claude Code

@dreamorosi
dreamorosi merged commit b2cb8db into main Oct 23, 2026
41 checks passed
@dreamorosi
dreamorosi deleted the docs/parser-transform-errors branch October 23, 2026 23:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/M PR between 30-99 LOC

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: envelope safeParse throws when a schema transform throws

2 participants