{"id":31259985,"url":"https://github.com/async3619/better-zod-errors","last_synced_at":"2026-04-28T21:34:46.218Z","repository":{"id":315252908,"uuid":"1058644288","full_name":"async3619/better-zod-errors","owner":"async3619","description":"formatted and more descriptive error messages for Zod validation","archived":false,"fork":false,"pushed_at":"2025-09-17T15:52:07.000Z","size":237,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"dev","last_synced_at":"2025-10-20T07:31:59.020Z","etag":null,"topics":["cli","codeframe","json","yaml","zod"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/async3619.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-09-17T11:08:07.000Z","updated_at":"2025-09-18T00:42:44.000Z","dependencies_parsed_at":"2025-09-17T15:40:28.153Z","dependency_job_id":"2ddcbe5c-6522-42e2-b128-34bca3437bb4","html_url":"https://github.com/async3619/better-zod-errors","commit_stats":null,"previous_names":["async3619/better-zod-errors"],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/async3619/better-zod-errors","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/async3619%2Fbetter-zod-errors","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/async3619%2Fbetter-zod-errors/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/async3619%2Fbetter-zod-errors/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/async3619%2Fbetter-zod-errors/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/async3619","download_url":"https://codeload.github.com/async3619/better-zod-errors/tar.gz/refs/heads/dev","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/async3619%2Fbetter-zod-errors/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32400867,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-28T19:38:08.556Z","status":"ssl_error","status_checked_at":"2026-04-28T19:37:55.688Z","response_time":56,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cli","codeframe","json","yaml","zod"],"created_at":"2025-09-23T08:45:22.771Z","updated_at":"2026-04-28T21:34:46.208Z","avatar_url":"https://github.com/async3619.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003ch1 align=\"center\"\u003e\n  \u003cbr /\u003e\n  💎\n  \u003cbr /\u003e\n  better-zod-errors\n  \u003csup\u003e\n    \u003cbr /\u003e\n    \u003cbr /\u003e\n  \u003c/sup\u003e    \n\u003c/h1\u003e\n\n\u003cdiv align=\"center\"\u003e\n    \u003ca href=\"https://github.com/async3619/better-zod-errors/blob/main/LICENSE\"\u003e\n        \u003cimg src=\"https://img.shields.io/github/license/async3619/better-zod-errors?style=flat-square\" alt=\"MIT License\" /\u003e\n    \u003c/a\u003e\n    \u003ca href=\"https://codecov.io/gh/async3619/better-zod-errors\"\u003e\n        \u003cimg alt=\"Codecov\" src=\"https://img.shields.io/codecov/c/github/async3619/better-zod-errors?style=flat-square\"\u003e\n    \u003c/a\u003e\n    \u003ca href=\"https://www.npmjs.com/package/better-zod-errors\"\u003e\n        \u003cimg alt=\"npm\" src=\"https://img.shields.io/npm/v/better-zod-errors?style=flat-square\" /\u003e\n    \u003c/a\u003e\n    \u003cbr /\u003e\n    \u003csup\u003eformatted and more descriptive error messages for Zod validation\u003c/sup\u003e\n    \u003cbr /\u003e\n    \u003cbr /\u003e\n\u003c/div\u003e\n\n## Introduction\n\nThis library provides set of functions to format and enhance error messages generated by [Zod](https://zod.dev/) with code frames.\n\n|             with JSON              |             with YAML              |\n|:----------------------------------:|:----------------------------------:|\n| ![JSON Example](./assets/json.png) | ![YAML Example](./assets/yaml.png) |\n\n## Installation\n\n```bash\n$ npm install better-zod-errors\n# or\n$ yarn add better-zod-errors\n# or\n$ pnpm add better-zod-errors\n```\n\n## Usage\n\nThis library provides two main functions to format Zod errors with code frames:\n\n### JSON Format\n\nYou can format JSON data validation errors using the `formatJsonError` function:\n\n```typescript\nimport { z } from \"zod\";\nimport { formatJsonError } from \"better-zod-errors\";\n\nconst schema = z.object({\n  name: z.string().min(2, \"Name must be at least 2 characters long\"),\n  age: z.number().min(0, \"Age must be a positive number\"),\n});\n\nconst payload = {\n  name: \"A\",\n  age: -5,\n};\n\ntry {\n  schema.parse(payload);\n} catch (e) {\n  if (e instanceof z.ZodError) {\n    for (const issue of e.issues) {\n      const formattedError = formatJsonError(issue, payload);\n      console.log(formattedError); // formatted error message with code frame\n    }\n  } else {\n    // handle other errors\n  }\n}\n```\n\n### YAML Format\n\nYou can also format YAML data validation errors using the `formatYamlError` function:\n\n```typescript\nimport { z } from \"zod\";\nimport { formatYamlError } from \"better-zod-errors\";\n\nconst schema = z.object({\n  name: z.string().min(2, \"Name must be at least 2 characters long\"),\n  age: z.number().min(0, \"Age must be a positive number\"),\n  address: z.object({\n    street: z.string(),\n    city: z.string(),\n  }),\n});\n\nconst payload = {\n  name: \"John\",\n  age: -5,\n  address: {\n    street: \"123 Main St\",\n    city: 456, // Invalid type\n  },\n};\n\ntry {\n  schema.parse(payload);\n} catch (e) {\n  if (e instanceof z.ZodError) {\n    for (const issue of e.issues) {\n      const formattedError = formatYamlError(issue, payload);\n      console.log(formattedError); // formatted YAML error message with code frame\n    }\n  } else {\n    // handle other errors\n  }\n}\n```\n\n## API\n\n### `formatJsonError(issue: z.ZodIssue, data: any, [options: FormatJsonErrorOptions]): string`\n\nFormats a single Zod issue into a more readable error message with a code frame.\n\n#### `issue`\n\nType: `z.ZodIssue`\n\nThe Zod issue to format thrown during validation with `ZodError`.\n\n#### `data`\n\nType: `any`\n\nThe original data that was validated. If the data was not matched with the original structure, it may throw an error.\n\n#### `options`\n\nType: `FormatJsonErrorOptions` (optional)\n\n##### `useColor`\n\nType: `boolean` (default: `true`)\n\nWhether to use ANSI colors in the output. Set to `false` to disable colors.\n\n##### `syntaxHighlighting`\n\nType: `boolean` (default: `true`)\n\nWhether to use syntax highlighting in the code frame. Set to `false` to disable syntax highlighting.\n\n### `formatYamlError(issue: z.ZodIssue, payload: any, [options: FormatYamlErrorOptions]): string`\n\nFormats a single Zod issue into a more readable error message with a YAML code frame.\n\n#### `issue`\n\nType: `z.ZodIssue`\n\nThe Zod issue to format thrown during validation with `ZodError`.\n\n#### `payload`\n\nType: `number | bigint | boolean | string | object`\n\nThe original data that was validated in YAML format. The function will serialize this data to YAML and create a source map to locate error positions.\n\n#### `options`\n\nType: `FormatYamlErrorOptions` (optional)\n\n##### `useColor`\n\nType: `boolean` (default: `true`)\n\nWhether to use ANSI colors in the output. Set to `false` to disable colors.\n\n##### `syntaxHighlighting`\n\nType: `boolean` (default: `true`)\n\nWhether to use syntax highlighting in the YAML code frame. Set to `false` to disable syntax highlighting.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fasync3619%2Fbetter-zod-errors","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fasync3619%2Fbetter-zod-errors","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fasync3619%2Fbetter-zod-errors/lists"}