zod-validation-error

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

Library
npm
v5.0.0
1,024 stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum. How we score it →
78 /100 Good
Development Activity 80
Maintenance 80
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
70%
Other

Budibase

Low Code Platforms · No Code Platforms

28,324

Build AI agents, automations, and internal apps on a single open-source platform with full self-hosting control.

View details
91
Repo Health
81
Technical
63
Dependency
Built with
TypeScript 70%
Svelte 26%
Updated 1 weeks ago
TypeScript
79%
Other

Directus

CMS · Low Code Platforms

37,987

Connect any SQL database and get instant REST and GraphQL APIs, a visual management Studio, and a native MCP server for AI agents — free for most organizations.

View details
92
Repo Health
82
Technical
76
Dependency
Built with
TypeScript 79%
Vue 19%
Updated 1 weeks ago
TypeScript
99%
MIT

GraphQL Hive

Developer Tools · Devops · Monitoring

484

Open-source GraphQL schema registry and observability platform with breaking change detection, federation support, and CI/CD integration for teams of any size.

View details
90
Repo Health
81
Technical
69
Dependency
Built with
TypeScript 99%
Updated 4 days ago
Python
64%
Other

Keep

Automation · Devops · Monitoring

12,359

The open-source AIOps and alert management platform that unifies 130+ monitoring tools into a single pane of glass with AI-powered correlation, deduplication, and workflow automation.

View details
89
Repo Health
79
Technical
66
Dependency
Built with
Python 64%
TypeScript 36%
Updated 1 weeks ago
TypeScript
88%
MIT

medusa

Ecommerce

36,494

The most flexible open-source commerce platform — build B2C, B2B, and marketplace applications with modular, composable commerce primitives.

View details
93
Repo Health
87
Technical
63
Dependency
Built with
TypeScript 88%
JavaScript 12%
Updated 1 weeks ago
Ruby
62%
MIT

OnetimeSecret

Security

2,947

Generate self-destructing single-use links to share passwords and sensitive data without leaving traces in inboxes or chat logs.

View details
92
Repo Health
81
Technical
72
Dependency
Built with
Ruby 62%
TypeScript 25%
Updated 4 days ago
JavaScript
64%
AGPL 3.0

overleaf

Collaboration · Productivity

18,188

Open-source, real-time collaborative LaTeX editor with sandboxed compilation and full TeXLive support for self-hosted academic and research teams.

View details
87
Repo Health
80
Technical
62
Dependency
Built with
JavaScript 64%
TypeScript 30%
Updated 2 weeks ago
TypeScript
99%
AGPL 3.0

Pangolin

Networking

22,937

An open-source, identity-based zero-trust remote access platform built on WireGuard — a self-hostable alternative to Cloudflare Tunnel and Twingate with SSO, OIDC, and tunneled reverse proxying.

View details
87
Repo Health
68
Technical
68
Dependency
Built with
TypeScript 99%
Updated 4 days ago
TypeScript
95%
MIT

sigle

Blogging

489

A decentralized, open-source writing platform that permanently stores your stories on the Stacks blockchain and Arweave — where Web3 content creators own their words forever.

View details
81
Repo Health
78
Technical
69
Dependency
Built with
TypeScript 95%
Updated 6 days 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