Skip to content

Conversation

@ymc9
Copy link
Member

@ymc9 ymc9 commented Sep 7, 2025

No description provided.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Sep 7, 2025

📝 Walkthrough

Walkthrough

Replaces direct v3-only Zod error formatting with a cross-version local helper getZodErrorMessage, adds zod-utils.ts and re-exports it, updates imports/usages across OpenAPI generator, runtime policy/validation, server REST, and schema CLI, and updates license header years.

Changes

Cohort / File(s) Summary
License headers
LICENSE, packages/LICENSE
Updated copyright years from 2022 to 2022-2025 in license headers; no license text or behavior changes.
Zod error formatting migration
packages/plugins/openapi/src/generator-base.ts, packages/runtime/src/enhancements/node/policy/handler.ts, packages/runtime/src/enhancements/node/policy/policy-utils.ts, packages/runtime/src/validation.ts, packages/server/src/api/rest/index.ts
Replaced usages of fromZodError (v3) with getZodErrorMessage(...); updated imports to use the new local helper; preserved control flow and error handling sites while changing message construction.
Local helpers / new util
packages/runtime/src/local-helpers/zod-utils.ts, packages/runtime/src/local-helpers/index.ts
Added zod-utils.ts exporting getZodErrorMessage(err: unknown): string (handles Zod v3/v4); re-exported it from local-helpers/index.ts; reordered some existing exports.
Schema CLI config error message
packages/schema/src/cli/config.ts
Removed fromZodError import and usage; now interpolates the Zod error message via the new helper or error directly in the config-load validation branch.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs


📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7efaa4d and bf72cf9.

📒 Files selected for processing (1)
  • packages/LICENSE (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • packages/LICENSE
⏰ 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)
  • GitHub Check: dependency-review
  • GitHub Check: OSSAR-Scan
  • GitHub Check: build-test (20.x)
  • GitHub Check: build-test (20.x)
  • GitHub Check: build-test (20.x)
✨ Finishing Touches
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch chore/zod3-4-errors

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a 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 feedback

Interpolating ${err} may produce less friendly output. Prefer the shared helper if dependency edges allow; otherwise, use err.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/schema can depend on @zenstackhq/runtime. If not, we’ll stick to err.message.

packages/runtime/src/enhancements/node/policy/policy-utils.ts (1)

448-472: Minor: guard merge path readability

No 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 assertion

getZodErrorMessage 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/name

This 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

📥 Commits

Reviewing files that changed from the base of the PR and between e798397 and 7efaa4d.

📒 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 LGTM

Header year updated to 2025; license body unchanged.

LICENSE (1)

3-3: Year range update LGTM

Header updated to 2022-2025; license body unchanged.

packages/plugins/openapi/src/generator-base.ts (1)

1-1: Consolidate Zod error formatting via helper — good change

Import 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 good

Import 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 messaging

Imports 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 — good

Helper 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 handling

Using getZodErrorMessage standardizes v3/v4 formatting across the runtime.

packages/runtime/src/local-helpers/index.ts (1)

4-8: Barrel update looks good

Re-export reordering plus adding zod-utils keeps a single import surface for helpers.

@ymc9 ymc9 merged commit 8bbe219 into dev Sep 8, 2025
12 checks passed
@ymc9 ymc9 deleted the chore/zod3-4-errors branch September 8, 2025 04:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant