Skip to content

修复/update-config 指令报错: Error: Undefined cannot be represented in JS…#1283

Open
xiaoFjun-eng wants to merge 1 commit into
claude-code-best:mainfrom
xiaoFjun-eng:fixType
Open

修复/update-config 指令报错: Error: Undefined cannot be represented in JS…#1283
xiaoFjun-eng wants to merge 1 commit into
claude-code-best:mainfrom
xiaoFjun-eng:fixType

Conversation

@xiaoFjun-eng

@xiaoFjun-eng xiaoFjun-eng commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

…ON Schema。

Summary by CodeRabbit

  • Bug Fixes
    • Improved validation for plugin settings configuration to prevent invalid states and ensure more robust plugin handling.

@coderabbitai

coderabbitai Bot commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

In SettingsSchema, the Zod union for enabledPlugins record values had z.undefined() removed, narrowing accepted values from boolean | string[] | undefined to boolean | string[]. The enabledPlugins field itself remains .optional(). The inferred SettingsJson type reflects this narrowing.

Changes

Settings Schema Type Tightening

Layer / File(s) Summary
Remove undefined from enabledPlugins value union
src/utils/settings/types.ts
z.undefined() is dropped from the Zod union for enabledPlugins record values; the union now contains only z.array(z.string()) and z.boolean(), narrowing the inferred SettingsJson type.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~2 minutes

Poem

A rabbit hopped through fields of types,
And snipped away the undefined hype.
"Why allow what shouldn't be there?"
It clipped one line with utmost care. 🐇✂️
Now boolean | string[] stands alone, fair.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title is partially related to the changeset. It mentions fixing an error in the /update-config command and addresses the 'Undefined cannot be represented' issue, which aligns with the fix's goal of removing undefined values from the schema. However, the title is in Chinese and uses a format that's more technical/command-focused rather than describing the primary code change (tightening the enabledPlugins schema type).
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with 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.

❤️ Share

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

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/utils/settings/types.ts`:
- Line 571: The schema union at line 571 that validates enabledPlugins and
similar fields no longer accepts z.undefined() due to JSON Schema generation
conflicts, but the deletion semantics in updateSettingsForSource and
validateSettingsFileContent still expect to pass undefined values for field
deletion. Align this contract by filtering out undefined entries from the record
object before it reaches schema validation in validateSettingsFileContent, so
that the strict schema validation succeeds while preserving the deletion
semantics that rely on detecting undefined values in the update logic.
Alternatively, update the deletion logic in updateSettingsForSource to detect
and handle deletions differently (without relying on undefined values) before
validation occurs.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 711960d9-dfc9-408d-9547-71fd0e327832

📥 Commits

Reviewing files that changed from the base of the PR and between d3121f0 and fe6e4da.

📒 Files selected for processing (1)
  • src/utils/settings/types.ts

.record(
z.string(),
z.union([z.array(z.string()), z.boolean(), z.undefined()]),
z.union([z.array(z.string()), z.boolean()]), // , z.undefined() 导致报错:Undefined cannot be represented in JSON Schema

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🗄️ Data Integrity & Integration | 🟠 Major | 🏗️ Heavy lift

Schema/value contract now conflicts with record-key deletion semantics (Line 571).

Removing z.undefined() here breaks the documented delete-by-undefined path for record fields (including enabledPlugins), and strict validation will now reject those in-flight values. This creates a cross-file contract break between SettingsSchema and updateSettingsForSource/validateSettingsFileContent.

Consider aligning the contract in the same PR: either (a) migrate deletion semantics away from explicit undefined values before validation/serialization, or (b) strip undefined record entries pre-parse so strict schema validation still succeeds while keeping JSON Schema generation valid.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/utils/settings/types.ts` at line 571, The schema union at line 571 that
validates enabledPlugins and similar fields no longer accepts z.undefined() due
to JSON Schema generation conflicts, but the deletion semantics in
updateSettingsForSource and validateSettingsFileContent still expect to pass
undefined values for field deletion. Align this contract by filtering out
undefined entries from the record object before it reaches schema validation in
validateSettingsFileContent, so that the strict schema validation succeeds while
preserving the deletion semantics that rely on detecting undefined values in the
update logic. Alternatively, update the deletion logic in
updateSettingsForSource to detect and handle deletions differently (without
relying on undefined values) before validation occurs.

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