-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
feat: Add typed error codes for i18n support #5395
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
base: main
Are you sure you want to change the base?
Conversation
WalkthroughThis pull request introduces optional custom error codes throughout the Zod validation library. It adds a Pre-merge checks❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (5)
🧰 Additional context used📓 Path-based instructions (13)**/*.{js,jsx,ts,tsx,mjs,cjs,json}📄 CodeRabbit inference engine (CLAUDE.md)
Files:
**/*.{js,jsx,ts,tsx,mjs,cjs}📄 CodeRabbit inference engine (CLAUDE.md)
Files:
**/*.{ts,tsx}📄 CodeRabbit inference engine (CLAUDE.md)
Files:
**/*.{ts,tsx,js,jsx,mjs,cjs}📄 CodeRabbit inference engine (CLAUDE.md)
Files:
**/*.{js,mjs,ts,tsx}📄 CodeRabbit inference engine (.cursor/rules/development-setup.mdc)
Files:
**/*.{js,mjs,cjs,jsx,ts,tsx}📄 CodeRabbit inference engine (.cursor/rules/guidelines.mdc)
Files:
packages/**/src/**/*.{ts,tsx}📄 CodeRabbit inference engine (.cursor/rules/zod-project-guide.mdc)
Files:
packages/zod/**📄 CodeRabbit inference engine (.cursor/rules/zod-project-guide.mdc)
Files:
**/src/*/tests/**📄 CodeRabbit inference engine (CLAUDE.md)
Files:
packages/zod/src/{v4/classic/tests,v4/core/tests,v3/tests}/**/*📄 CodeRabbit inference engine (.cursor/rules/testing-guidelines.mdc)
Files:
packages/zod/src/{v4/classic/tests,v4/core/tests,v3/tests}/**/*.test.ts📄 CodeRabbit inference engine (.cursor/rules/testing-guidelines.mdc)
Files:
packages/**/*.test.ts📄 CodeRabbit inference engine (.cursor/rules/zod-project-guide.mdc)
Files:
play.ts📄 CodeRabbit inference engine (CLAUDE.md)
Files:
🧠 Learnings (19)📓 Common learnings📚 Learning: 2025-10-21T17:27:32.492ZApplied to files:
📚 Learning: 2025-10-21T17:27:32.492ZApplied to files:
📚 Learning: 2025-10-21T17:27:32.492ZApplied to files:
📚 Learning: 2025-10-21T17:27:32.492ZApplied to files:
📚 Learning: 2025-10-21T17:26:08.288ZApplied to files:
📚 Learning: 2025-10-21T17:26:08.288ZApplied to files:
📚 Learning: 2025-10-21T17:27:32.492ZApplied to files:
📚 Learning: 2025-10-21T17:26:08.288ZApplied to files:
📚 Learning: 2025-10-21T17:26:08.288ZApplied to files:
📚 Learning: 2025-10-21T17:26:08.288ZApplied to files:
📚 Learning: 2025-10-21T17:26:08.288ZApplied to files:
📚 Learning: 2025-10-21T17:26:08.288ZApplied to files:
📚 Learning: 2025-10-21T17:26:08.288ZApplied to files:
📚 Learning: 2025-10-21T17:26:08.288ZApplied to files:
📚 Learning: 2025-10-21T17:26:32.924ZApplied to files:
📚 Learning: 2025-10-21T17:26:08.288ZApplied to files:
📚 Learning: 2025-10-21T17:27:32.492ZApplied to files:
📚 Learning: 2025-10-21T17:24:39.708ZApplied to files:
🧬 Code graph analysis (3)packages/zod/src/v3/tests/typed-error-codes.test.ts (2)
play.ts (2)
packages/zod/src/v3/types.ts (2)
🔇 Additional comments (5)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Overview
Adds support for custom, typed error codes to enable proper internationalization (i18n) of validation errors. This allows developers to specify semantic error identifiers that can be mapped to localized messages at runtime.
Problem
too_small,too_big, etc.) but they're untyped.refine()custom validations only get a generic"custom"codeSolution
Extends Zod's error system to support optional
codeparameter in validators and refinements, enabling type-safe, semantic error identifiers.Changes
Core Type Updates
customCode?: stringtoZodIssueBase(inherited by all issue types)errorUtil.ErrMessageto accept{ message?: string; code?: string }ZodStringCheckandZodNumberCheckto support optionalcodefieldValidator Updates
String validators:
.min(),.max(),.length(),.email(),.url(),.uuid(), etc.Number validators:
.min(),.max(),.int(),.positive(),.negative(), etc.Custom validators:
.refine()and.superRefine()now acceptcustomCodeparameterAPI Usage
Built-in validators: