-
-
Couldn't load subscription status.
- Fork 126
chore: extract a zod error format utility for v3/v4 uniform handling #2232
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
Conversation
📝 WalkthroughWalkthroughReplaces direct v3-only Zod error formatting with a cross-version local helper Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (1)
✅ Files skipped from review due to trivial changes (1)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (5)
✨ Finishing Touches🧪 Generate unit tests
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🧹 Nitpick comments (4)
packages/schema/src/cli/config.ts (1)
30-31: Use unified Zod error formatting (or at least err.message) for CLI feedbackInterpolating
${err}may produce less friendly output. Prefer the shared helper if dependency edges allow; otherwise, useerr.message.Apply one of:
- throw new CliError(`Config file ${filename} is not valid: ${err}`); + throw new CliError(`Config file ${filename} is not valid: ${err.message}`);Or, if adding a dep on runtime local-helpers is acceptable:
+import { getZodErrorMessage } from '@zenstackhq/runtime/local-helpers'; ... - throw new CliError(`Config file ${filename} is not valid: ${err}`); + throw new CliError(`Config file ${filename} is not valid: ${getZodErrorMessage(err)}`);To ensure we don’t introduce a circular dependency, please confirm whether
packages/schemacan depend on@zenstackhq/runtime. If not, we’ll stick toerr.message.packages/runtime/src/enhancements/node/policy/policy-utils.ts (1)
448-472: Minor: guard merge path readabilityNo functional issue. Consider extracting the field-update guard merging into a tiny helper to reduce nesting in this hot path.
packages/runtime/src/validation.ts (2)
18-18: Remove unnecessary type assertiongetZodErrorMessage accepts unknown; the cast reduces type-safety and can mask non-Zod errors.
- throw new ValidationError(getZodErrorMessage(err as z.ZodError)); + throw new ValidationError(getZodErrorMessage(err));
7-9: Have ValidationError extend Error to preserve stack/nameThis improves debuggability and interoperability with error tooling.
-export class ValidationError { - constructor(public readonly message: string) {} -} +export class ValidationError extends Error { + constructor(message: string) { + super(message); + this.name = 'ValidationError'; + } +}
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (10)
LICENSE(1 hunks)packages/LICENSE(1 hunks)packages/plugins/openapi/src/generator-base.ts(2 hunks)packages/runtime/src/enhancements/node/policy/handler.ts(3 hunks)packages/runtime/src/enhancements/node/policy/policy-utils.ts(3 hunks)packages/runtime/src/local-helpers/index.ts(1 hunks)packages/runtime/src/local-helpers/zod-utils.ts(1 hunks)packages/runtime/src/validation.ts(2 hunks)packages/schema/src/cli/config.ts(1 hunks)packages/server/src/api/rest/index.ts(4 hunks)
🧰 Additional context used
🧬 Code graph analysis (6)
packages/plugins/openapi/src/generator-base.ts (2)
packages/sdk/src/types.ts (1)
PluginError(115-119)packages/runtime/src/local-helpers/zod-utils.ts (1)
getZodErrorMessage(9-23)
packages/runtime/src/validation.ts (1)
packages/runtime/src/local-helpers/zod-utils.ts (1)
getZodErrorMessage(9-23)
packages/runtime/src/enhancements/node/policy/handler.ts (1)
packages/runtime/src/local-helpers/zod-utils.ts (1)
getZodErrorMessage(9-23)
packages/runtime/src/enhancements/node/policy/policy-utils.ts (1)
packages/runtime/src/local-helpers/zod-utils.ts (1)
getZodErrorMessage(9-23)
packages/schema/src/cli/config.ts (1)
packages/schema/src/cli/cli-error.ts (1)
CliError(4-4)
packages/server/src/api/rest/index.ts (1)
packages/runtime/src/local-helpers/zod-utils.ts (1)
getZodErrorMessage(9-23)
🔇 Additional comments (8)
packages/LICENSE (1)
3-3: Year range update LGTMHeader year updated to 2025; license body unchanged.
LICENSE (1)
3-3: Year range update LGTMHeader updated to 2022-2025; license body unchanged.
packages/plugins/openapi/src/generator-base.ts (1)
1-1: Consolidate Zod error formatting via helper — good changeImport switch and usage look correct; keeps messages consistent across Zod versions.
Also applies to: 97-97
packages/server/src/api/rest/index.ts (1)
14-15: REST error details now use centralized formatter — looks goodImport and three call-site replacements are correct; 422 mapping is preserved where intended.
Also applies to: 823-827, 1025-1028, 1053-1059
packages/runtime/src/enhancements/node/policy/handler.ts (1)
17-18: Policy errors migrated to helper — consistent messagingImports and denial messages updated correctly for create/update validation failures.
Also applies to: 423-425, 1269-1272
packages/runtime/src/enhancements/node/policy/policy-utils.ts (1)
16-22: Policy utils: consistent Zod formatting and logging — goodHelper import and usages in validation logging and denial messaging look correct.
Also applies to: 944-946, 1448-1449
packages/runtime/src/validation.ts (1)
2-2: Good switch to centralized Zod error handlingUsing getZodErrorMessage standardizes v3/v4 formatting across the runtime.
packages/runtime/src/local-helpers/index.ts (1)
4-8: Barrel update looks goodRe-export reordering plus adding zod-utils keeps a single import surface for helpers.
No description provided.