Skip to content

fix(cli): remove doubled Expected prefix from InvalidValue messages#6487

Open
rvaccone wants to merge 5 commits into
Effect-TS:mainfrom
rvaccone:fix/cli-invalid-value-expected-prefix
Open

fix(cli): remove doubled Expected prefix from InvalidValue messages#6487
rvaccone wants to merge 5 commits into
Effect-TS:mainfrom
rvaccone:fix/cli-invalid-value-expected-prefix

Conversation

@rvaccone

@rvaccone rvaccone commented Jul 18, 2026

Copy link
Copy Markdown
Contributor

Type

  • Refactor
  • Feature
  • Bug Fix
  • Optimization
  • Documentation Update

Description

CliError.InvalidValue.message rendered a doubled Expected: Expected ... prefix for values backed by Primitive.choice or the schema backed primitives (integer, float, boolean, date), and for choices it also repeated the offending value twice.

Before:

Invalid value for flag --size: "bogus". Expected: Expected "small" | "medium" | "large", got "bogus"

After:

Invalid value for flag --size: "bogus". Expected: "small" | "medium" | "large"
Invalid value for argument <count>: "3.14". Expected an integer, got 3.14

This combines both directions suggested in the issue:

  1. Primitive.choice now fails with a bare description of the accepted values. The offending value and the Expected: label are added by InvalidValue.message, so the value is no longer shown twice.
  2. InvalidValue.message only prepends its Expected: label when expected does not already start with Expected or Expected:. Failure texts that are already complete sentences (schema decode messages, user supplied strings like the Param.filter doc examples) are appended as their own sentence instead of being double labeled.

The schema backed primitives keep their full schema decode sentence. Extracting a bare expected description from a schema issue would mean duplicating the SchemaIssue formatter traversal inside the CLI package, because the AnyOf branch of the default formatter hardcodes the Expected X, got Y sentence and is not reachable through the leafHook/checkHook extension points. The decoded actual after got is also genuinely informative when it differs from the raw input (got Invalid Date, got NaN).

Tests: updated the Primitive.choice assertions, added unit coverage for both InvalidValue.message branches, added a test asserting the rendered stderr line through Command.runWith, and corrected a stale inline snapshot in Arguments.test.ts that encoded wording which no longer exists in the codebase.

Related

Closes #6312

Summary by CodeRabbit

  • Bug Fixes
    • Fixed CLI invalid-value and missing-value error formatting to avoid duplicated “Expected” prefixes.
    • Improved invalid-choice error output to focus on the allowed options without repeating the invalid “got” framing.
    • Standardized CLI argument/flag validation wording for more consistent messaging.
  • Tests
    • Expanded CLI test coverage for invalid value, invalid choice, and argument/primitive parsing error messages.
  • Documentation
    • Updated the release notes entry describing the corrected “Expected” prefix behavior.

@github-project-automation github-project-automation Bot moved this to Discussion Ongoing in PR Backlog Jul 18, 2026
@changeset-bot

changeset-bot Bot commented Jul 18, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: b8f34bf

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 27 packages
Name Type
effect Patch
@effect/opentelemetry Patch
@effect/platform-browser Patch
@effect/platform-bun Patch
@effect/platform-node-shared Patch
@effect/platform-node Patch
@effect/vitest Patch
@effect/ai-anthropic Patch
@effect/ai-openai-compat Patch
@effect/ai-openai Patch
@effect/ai-openrouter Patch
@effect/atom-react Patch
@effect/atom-solid Patch
@effect/atom-vue Patch
@effect/sql-clickhouse Patch
@effect/sql-d1 Patch
@effect/sql-libsql Patch
@effect/sql-mssql Patch
@effect/sql-mysql2 Patch
@effect/sql-pg Patch
@effect/sql-pglite Patch
@effect/sql-sqlite-bun Patch
@effect/sql-sqlite-do Patch
@effect/sql-sqlite-node Patch
@effect/sql-sqlite-react-native Patch
@effect/sql-sqlite-wasm Patch
@effect/openapi-generator Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@coderabbitai

coderabbitai Bot commented Jul 18, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

CLI invalid-value formatting now avoids duplicated Expected prefixes. Choice primitives return allowed-value descriptions, while InvalidValue normalizes expectation text. Tests and a patch changeset cover the updated CLI messages.

Changes

CLI invalid-value handling

Layer / File(s) Summary
Choice primitive failure contract
packages/effect/src/unstable/cli/Primitive.ts, packages/effect/test/unstable/cli/Primitive.test.ts
Primitive.choice now reports only allowed choices, and invalid-choice tests reflect the shared message.
InvalidValue formatting and CLI coverage
packages/effect/src/unstable/cli/CliError.ts, packages/effect/test/unstable/cli/Errors.test.ts, packages/effect/test/unstable/cli/Command.test.ts, packages/effect/test/unstable/cli/Arguments.test.ts, .changeset/fix-invalid-value-doubled-expected.md
InvalidValue avoids duplicate prefixes for arguments, flags, and missing flag values; tests and the patch changeset cover the updated output.

Estimated code review effort: 2 (Simple) | ~10 minutes

Suggested labels: bug

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The changes normalize InvalidValue.expected/message formatting and update choice/schema-backed tests as requested in #6312.
Out of Scope Changes check ✅ Passed All code and test changes relate to the InvalidValue prefix/duplicate-value fix; no unrelated scope is evident.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main fix: removing duplicated "Expected" prefixes in CLI InvalidValue messages.

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

@rvaccone
rvaccone marked this pull request as ready for review July 18, 2026 21:30
@coderabbitai coderabbitai Bot added the bug Something isn't working label Jul 18, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

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 (1)
packages/effect/test/unstable/cli/Errors.test.ts (1)

151-190: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Cover missing flag values.

CliError.InvalidValue.message has a separate missing-value path at Line 377-379, but these tests only use non-empty values. Add a value: "" case, including an already-prefixed expectation, to verify normalization for missing-flag errors.

🤖 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 `@packages/effect/test/unstable/cli/Errors.test.ts` around lines 151 - 190, Add
a missing-value test in the InvalidValue suite using value: "" and a flag kind,
with an expected message already prefixed by “Expected”. Assert that
CliError.InvalidValue.message normalizes the prefix correctly for the
missing-flag path without duplicating it, alongside the existing non-empty value
cases.
🤖 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 @.changeset/fix-invalid-value-doubled-expected.md:
- Around line 11-12: Add a language identifier to each fenced code block in this
changeset document, including the examples around the invalid-value message, so
the fences satisfy markdownlint MD040. Use text or another appropriate non-code
language identifier consistently.

---

Nitpick comments:
In `@packages/effect/test/unstable/cli/Errors.test.ts`:
- Around line 151-190: Add a missing-value test in the InvalidValue suite using
value: "" and a flag kind, with an expected message already prefixed by
“Expected”. Assert that CliError.InvalidValue.message normalizes the prefix
correctly for the missing-flag path without duplicating it, alongside the
existing non-empty value cases.
🪄 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: Repository UI (base), Organization UI (inherited)

Review profile: CHILL

Plan: Pro

Run ID: 88ca4934-481a-40e3-a71a-45a7117f4a17

📥 Commits

Reviewing files that changed from the base of the PR and between ce95d88 and 8b3e749.

📒 Files selected for processing (7)
  • .changeset/fix-invalid-value-doubled-expected.md
  • packages/effect/src/unstable/cli/CliError.ts
  • packages/effect/src/unstable/cli/Primitive.ts
  • packages/effect/test/unstable/cli/Arguments.test.ts
  • packages/effect/test/unstable/cli/Command.test.ts
  • packages/effect/test/unstable/cli/Errors.test.ts
  • packages/effect/test/unstable/cli/Primitive.test.ts

Comment thread .changeset/fix-invalid-value-doubled-expected.md Outdated
@github-project-automation github-project-automation Bot moved this from Discussion Ongoing to Waiting on Author in PR Backlog Jul 18, 2026
@IMax153 IMax153 self-assigned this Jul 19, 2026
@IMax153 IMax153 added the 4.0 label Jul 19, 2026

@IMax153 IMax153 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks good, let's just trim down the verbosity in the changeset / jsdocs.

Comment thread .changeset/fix-invalid-value-doubled-expected.md Outdated
Comment thread packages/effect/src/unstable/cli/CliError.ts Outdated
rvaccone and others added 2 commits July 19, 2026 16:14
Co-authored-by: Maxwell Brown <maxwellbrown1990@gmail.com>
Co-authored-by: Maxwell Brown <maxwellbrown1990@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

4.0 bug Something isn't working

Projects

Status: Waiting on Author

Development

Successfully merging this pull request may close these issues.

CliError.InvalidValue.message doubles the "Expected: Expected ..." prefix for choice/schema-backed primitives

2 participants