zod-validation-error

Turns raw Zod validation issues into clear, human-readable error messages.

Library
npm
v5.0.0
1,021 stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum. How we score it →
84 /100 Excellent
Development Activity 92
Maintenance 92
Community 56
Maturity 56
Momentum 40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation. How we score it →
79 /100 Good
Architecture 82
Code Quality 88
Innovation 62
Learning Curve 85

zod-validation-error wraps the raw issue arrays that Zod schemas throw on failed validation into a single, readable ValidationError with a friendly .message string, while preserving the original issues on .details for programmatic handling or logging. Rather than exposing Zod’s internal issue codes and paths directly to end users, it renders them into natural-language sentences (“Number must be greater than 0 at “id"") that are safe to surface in an API response, form validation UI, or CLI error output.

The library ships a configurable MessageBuilder and createErrorMap factory so teams can control path inclusion, title-casing, issue and union separators, localization of dates/numbers, and how many issues get concatenated into one message. It supports both Zod v3 (via the /v3 subpath export) and Zod v4 (default export) side by side, letting consumers migrate between Zod major versions without rewriting their error-formatting layer. Utility guards like isZodErrorLike and isValidationError let calling code branch safely on error shape without importing Zod’s internal types directly.

What You Get

  • fromError/fromZodError helpers that convert any caught error or ZodError into a ValidationError with a readable .message
  • A ValidationError class extending native Error, exposing the original Zod issues via .details for logging or programmatic use
  • createErrorMap/createMessageBuilder factories with fine-grained formatting options (prefix, separators, path inclusion, title-casing, locale-aware date/number formatting)
  • Type guards (isZodErrorLike, isValidationError, isValidationErrorLike) to safely narrow unknown errors without importing Zod’s internal error types
  • Parallel /v3 and /v4 (default) subpath exports so the same package supports either major version of Zod

Common Use Cases

  • Formatting API request validation failures into a single user-facing message returned in an HTTP error response
  • Displaying friendly inline error text under form fields after a Zod schema fails to parse form input
  • Wiring createErrorMap() into zod.config({ customError }) so every Zod parse failure across an app already produces readable messages
  • Logging or reporting the original structured Zod issues (via .details) to an error tracker while showing a simplified message to the user

Under The Hood

Architecture

The package is organized as two structurally identical, version-scoped modules (lib/v3 and lib/v4), each exporting the same public surface (ValidationError, fromError, fromZodError, fromZodIssue, toValidationError, createErrorMap, createMessageBuilder, type guards) built against that Zod major version’s internal issue types, plus a shared lib/utils module (joinPath, joinValues, titleCase, stringify, isPrimitive, NonEmptyArray) used by both. toValidationError is the core dispatcher: it narrows an unknown thrown value with isZodErrorLike, delegates to fromZodErrorWithoutRuntimeCheck for genuine Zod errors, wraps any other Error instance directly, and falls back to a generic ValidationError('Unknown error') otherwise — so the library never throws while formatting an error. createErrorMap’s v4 implementation further composes one small pure-function parser per Zod issue code (invalid_type, too_big, invalid_union, etc.) behind a lookup table, keeping each issue-to-message mapping isolated and independently testable. Nothing in the design would break under swapping the core abstraction — the version split itself is the intentional seam for supporting two incompatible upstream schemas.

Tech Stack

Written entirely in TypeScript targeting esnext/nodenext module resolution with erasableSyntaxOnly and allowImportingTsExtensions, compiled to dual CJS/ESM output via tsup and typed via a separate emitDeclarationOnly pass. Its only runtime dependency is a peer dependency on zod itself (^3.25.0 || ^4.0.0), keeping the package dependency-free otherwise. Testing runs on Vitest with the vitest/globals types, releases are managed via Changesets with a GitHub changelog generator, and commit messages are enforced by commitlint plus Husky pre-commit hooks running lint-staged (ESLint + Prettier).

Code Quality

Test coverage is extensive and colocated — nearly every source file under lib/v3 and lib/v4 (and each error-map issue parser) has a matching .test.ts file exercising it directly with Vitest. ESLint is configured with @typescript-eslint/recommended, enforced consistent-type-imports, import ordering, and Prettier integration; strict: true is set in tsconfig.json. Error handling favors defensive narrowing (isZodErrorLike, instanceof Error checks) over assuming well-typed input, and a CI workflow builds, typechecks, and runs the unit test suite on every pull request before merge.

What Makes It Unique

Rather than a single formatter, the library provides a fully composable, per-issue-code error-map architecture that lets consumers override formatting behavior (locale-aware dates/numbers, quoting of allowed values, union deduplication, title-casing) issue-by-issue while still producing one clean message, and it does so for two incompatible major versions of its host library (Zod v3 and v4) from the same published package via subpath exports — a maintenance approach few small validation-adjacent utilities attempt.

Used by 14 apps in this directory

TypeScript
99%
Other

Teable

Databases · No Code Platforms

21,920

A no-code PostgreSQL database with spreadsheet UX, real-time collaboration, and native AI agents — built for teams that outgrow Airtable.

View details
78
Repo Health
76
Technical
62
Dependency
Built with
TypeScript 99%
Updated 1 weeks ago
TypeScript
99%
Apache 2.0

Trigger.dev

AI Development · Automation · Developer Tools

16,606

Build and deploy fully-managed AI agents and background jobs in TypeScript — with no timeouts, durable retries, real-time observability, and elastic scaling built in.

View details
90
Repo Health
9
Technical
63
Dependency
Built with
TypeScript 99%
Updated 6 days ago
TypeScript
65%
Other

Typebot

AI Assistants · AI Development · Developer Tools

10,576

Build sophisticated chatbots visually, embed them anywhere without iframes, and own your data — fully self-hostable with a modular block system and 30+ integrations.

View details
94
Repo Health
82
Technical
64
Dependency
Built with
TypeScript 65%
MDX 34%
Updated 1 weeks ago
TypeScript
63%
AGPL 3.0

undb

Databases · No Code Platforms

2,975

Self-hosted no-code database and BaaS that lets you manage structured data visually with multi-database support, formula fields, and auto-generated OpenAPI endpoints.

View details
58
Repo Health
66
Technical
65
Dependency
Built with
TypeScript 63%
Svelte 35%
Updated 1 months ago
TypeScript
99%
AGPL 3.0

Webstudio

Design Tools · No Code Platforms

9,103

Open source visual development platform with complete CSS control, headless CMS integration, and full infrastructure ownership

View details
91
Repo Health
79
Technical
60
Dependency
Built with
TypeScript 99%
Updated 1 weeks ago

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers