feat(spec): improve error messages for invalid locale codes#2144
feat(spec): improve error messages for invalid locale codes#2144jaya6400 wants to merge 7 commits into
Conversation
- Add validateConfigSemantics() to check locales, empty/duplicate targets, and buckets. - Map v1/v1.1 bucket types to catch unknown IDs correctly. - Add schema min(1) defense to targets. - All 35 tests pass.
- Extract and display the unsupported locale value in error messages (e.g., "Unsupported locale: xxxx" instead of generic Zod errors) - Add isLocaleError and getValueAtPath helpers for clean, type‑safe extraction - Keep validation behavior identical to main branch: - Only hard errors for invalid locale codes (same as before) - All other issues (missing source, unknown bucket types) attempt upgrade - Remove the incorrectly added missing‑source hard error that was introduced earlier - All unit tests pass; no new breaking changes
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
📝 WalkthroughWalkthroughAdds two internal helper functions ( ChangesLocale validation error improvement
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 ESLint
ESLint install failed: private package registry requires authentication. Disable ESLint in CodeRabbit settings or use public packages. 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 |
|
Hey @moygospadin, I've reworked the changes based on your feedback from #2112 (comment). This new PR (#2144) only improves error messages and removes all the strict validation rules that were causing breaking changes. The default config now parses correctly, and the error string duplication is fixed. |
|
Hi @moygospadin , I see one CI check is failing, I checked it is a pre existed failure on "main" branch as well not related to my changes. |
|
Hey @jaya6400, thanks for sticking with this! I dug into the current diff and it actually comes out behavior-identical to |
Summary
This PR improves the error message shown when a user specifies an unsupported or invalid locale code in their i18n.json config. Instead of a generic Zod validation error, the parser now extracts and displays the exact invalid locale value, making the error more actionable.
Crucially, this PR does not change any validation behavior – only the error message is improved. The parser continues to throw only for invalid locale codes (same as main), and all other validation issues (missing source, unknown bucket types, etc.) still attempt an upgrade.
Changes:
Added isLocaleError helper to cleanly identify Zod issues related to invalid locale codes.
Added getValueAtPath helper to safely extract the actual invalid locale value from the raw config object.
Updated the parse function in extendConfigDefinition to build error messages that include the unsupported locale(s), e.g.:
instead of a generic Zod message.
Testing
Logic tests added:
should throw an error for unsupported locales – verifies that multiple invalid locales are reported in the error message with their values.
should throw for invalid locale codes with clear error – confirms that a single invalid locale displays the exact value.
should parse the default config without errors – ensures the built‑in default config is still accepted.
Existing upgrade tests (v0 → latest, v1 → latest) pass, verifying backward compatibility.
All 34 unit tests in @lingo.dev/_spec pass locally.

Checklist:
Changeset added – included as @lingo.dev/_spec patch bump.
Tests cover business logic (not just happy path) – the added tests explicitly cover invalid locale edge cases and ensure no regression.
No breaking changes – validation behavior is identical to main. Only the error message is improved.
Closes #561
Summary by CodeRabbit