Skip to content

fix(cli): fail when excess positional arguments are provided#6619

Closed
wasim-builds wants to merge 4 commits into
Effect-TS:mainfrom
wasim-builds:main
Closed

fix(cli): fail when excess positional arguments are provided#6619
wasim-builds wants to merge 4 commits into
Effect-TS:mainfrom
wasim-builds:main

Conversation

@wasim-builds

@wasim-builds wasim-builds commented Jul 25, 2026

Copy link
Copy Markdown

Fixes #6594

This throws a ValidationError when there are unconsumed positional arguments after parsing all parameters. Previously, excess positionals were silently discarded.

Summary by CodeRabbit

  • New Features
    • Added an UnrecognizedArgument CLI error type for invalid command-line input.
  • Bug Fixes
    • Commands now error when extra positional arguments remain after parsing.
    • Error messages include the unexpected tokens (e.g., Excess arguments: ...).
  • Tests
    • Added coverage for fixed vs. variadic positional arguments, ensuring excess operands are handled correctly.

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

changeset-bot Bot commented Jul 25, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: adee9f1

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

This PR includes changesets to release 28 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/docgen 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

@github-actions github-actions Bot added the 4.0 label Jul 25, 2026
@coderabbitai

coderabbitai Bot commented Jul 25, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 99ddfd50-a3be-46dd-a48f-63882ae7a6a0

📥 Commits

Reviewing files that changed from the base of the PR and between 1c87f5c and adee9f1.

📒 Files selected for processing (1)
  • packages/effect/test/unstable/cli/Command.test.ts

📝 Walkthrough

Walkthrough

The CLI adds an UnrecognizedArgument error and rejects unconsumed positional arguments after parsing configured parameters. Tests cover commands with no, fixed, and variadic positional arguments.

Changes

CLI excess argument validation

Layer / File(s) Summary
Validation error contract
packages/effect/src/unstable/cli/CliError.ts
Adds the tagged UnrecognizedArgument class and includes it in the CliError and NonShowHelpErrors unions.
Leftover argument rejection and coverage
packages/effect/src/unstable/cli/internal/command.ts, packages/effect/test/unstable/cli/Command.test.ts, .changeset/unrecognized-arguments.md
Rejects remaining positional arguments with an Excess arguments: ... error, tests fixed and variadic behavior, and documents the patch release.

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

Possibly related PRs

  • Effect-TS/effect#6561: Modifies CLI positional-argument parsing and error handling for excess operands.

Suggested labels: bug

Suggested reviewers: imax153

🚥 Pre-merge checks | ✅ 2
✅ Passed checks (2 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The PR now fails on excess positional arguments and covers no-arg, fixed, and variadic command cases as requested.
Out of Scope Changes check ✅ Passed The changes stay focused on CLI excess-argument handling, related error wiring, tests, and the required changeset.

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

@coderabbitai coderabbitai Bot added the bug Something isn't working label Jul 25, 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/src/unstable/cli/internal/command.ts (1)

294-299: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Add regression tests for excess-argument validation.

Cover commands with no positional parameters, fixed parameters at maximum cardinality, multiple leftovers, and variadic parameters that should still consume all arguments. Assert both the ValidationError tag and rendered message.

🤖 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/src/unstable/cli/internal/command.ts` around lines 294 - 299,
Add regression tests for the excess-argument branch in the command argument
validation flow, covering no positional parameters, fixed parameters at maximum
cardinality, multiple leftover arguments, and variadic parameters consuming all
arguments. Assert each failure has the ValidationError tag and the rendered
“Excess arguments” message, while variadic commands succeed without an error.
🤖 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 `@packages/effect/src/unstable/cli/CliError.ts`:
- Line 96: Add ValidationError to the NonShowHelpErrors union so ShowHelp.errors
includes validation failures in its help-rendering schema. Preserve the existing
error members and type structure.

---

Nitpick comments:
In `@packages/effect/src/unstable/cli/internal/command.ts`:
- Around line 294-299: Add regression tests for the excess-argument branch in
the command argument validation flow, covering no positional parameters, fixed
parameters at maximum cardinality, multiple leftover arguments, and variadic
parameters consuming all arguments. Assert each failure has the ValidationError
tag and the rendered “Excess arguments” message, while variadic commands succeed
without an error.
🪄 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

Review profile: CHILL

Plan: Pro Plus

Run ID: fe339596-05e1-4654-b776-071fa809b1a8

📥 Commits

Reviewing files that changed from the base of the PR and between 9d8d85c and 9088b67.

📒 Files selected for processing (2)
  • packages/effect/src/unstable/cli/CliError.ts
  • packages/effect/src/unstable/cli/internal/command.ts

| UnknownSubcommand
| ShowHelp
| UserError
| ValidationError

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🗄️ Data Integrity & Integration | 🟡 Minor | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
rg -n -A25 -B5 'NonShowHelpErrors|ShowHelp|ValidationError' \
  packages/effect/src/unstable/cli/CliError.ts

Repository: Effect-TS/effect

Length of output: 5432


Add ValidationError to NonShowHelpErrors. CliError now includes ValidationError, but ShowHelp.errors still uses NonShowHelpErrors, which currently excludes it. That leaves validation failures out of the help-rendering schema.

🤖 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/src/unstable/cli/CliError.ts` at line 96, Add ValidationError
to the NonShowHelpErrors union so ShowHelp.errors includes validation failures
in its help-rendering schema. Preserve the existing error members and type
structure.

@github-project-automation github-project-automation Bot moved this from Discussion Ongoing to Waiting on Author in PR Backlog Jul 25, 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.

This PR will also need a changeset - you can generate one with pnpm changeset. It can just be a patch.

Comment thread packages/effect/src/unstable/cli/internal/command.ts Outdated
Comment thread packages/effect/src/unstable/cli/CliError.ts
@wasim-builds

Copy link
Copy Markdown
Author

Thanks for the review! I've renamed ValidationError to UnrecognizedArgument and added it to NonShowHelpErrors as requested. I also added the patch changeset. I opted to skip the regression tests on this pass just to keep the PR minimal and focused on resolving the uncaught arguments, but let me know if you'd still like me to add those!

@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.

🧹 Nitpick comments (1)
packages/effect/src/unstable/cli/internal/command.ts (1)

294-297: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Add regression tests for excess positional arguments.

Cover commands with no positional parameters, fixed-cardinality parameters already at their maximum, and multiple leftover arguments. Assert the resulting UnrecognizedArgument error and message so this validation behavior remains protected.

🤖 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/src/unstable/cli/internal/command.ts` around lines 294 - 297,
Add regression tests for the excess-argument validation in the command execution
flow around the currentArguments check: cover commands with no positional
parameters, fixed-cardinality positional parameters already at their maximum,
and multiple leftover arguments. Assert that each case produces an
UnrecognizedArgument error with the expected “Excess arguments” message,
including all remaining arguments.
🤖 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.

Nitpick comments:
In `@packages/effect/src/unstable/cli/internal/command.ts`:
- Around line 294-297: Add regression tests for the excess-argument validation
in the command execution flow around the currentArguments check: cover commands
with no positional parameters, fixed-cardinality positional parameters already
at their maximum, and multiple leftover arguments. Assert that each case
produces an UnrecognizedArgument error with the expected “Excess arguments”
message, including all remaining arguments.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: b3dec45a-69b3-4d2d-a0e4-a4ca64151dd7

📥 Commits

Reviewing files that changed from the base of the PR and between 9088b67 and 1c87f5c.

📒 Files selected for processing (3)
  • .changeset/unrecognized-arguments.md
  • packages/effect/src/unstable/cli/CliError.ts
  • packages/effect/src/unstable/cli/internal/command.ts

@IMax153

IMax153 commented Jul 25, 2026

Copy link
Copy Markdown
Member

@wasim-builds thank you! We also need a series of regression tests as described by the CodeRabbit review.

@wasim-builds

Copy link
Copy Markdown
Author

Alright, since CodeRabbit kept nagging for them, I went ahead and added the full suite of regression tests in Command.test.ts for the UnrecognizedArgument path, covering commands with no positional arguments, commands with fixed cardinality arguments, and commands with variadic arguments. Everything should be completely good to go now!

@wasim-builds

Copy link
Copy Markdown
Author

By the way, I've really been enjoying diving into the Effect codebase! My goal is to get more involved in open source to help maintain projects and learn from great engineering teams. Is there a process or pathway for becoming a member of the Effect-TS GitHub organization? I'd love to continue helping out where I can!

@IMax153

IMax153 commented Jul 25, 2026

Copy link
Copy Markdown
Member

@wasim-builds - I apologize, I realized there was a pre-existing PR here: #6561 to fix the issue.

I'm going to give precedence to the PR that was opened earlier - plus it also addresses a few more edge cases.

Please let me know if it addresses your issues, and if not feel free to re-open a PR / issue.

@IMax153 IMax153 closed this Jul 25, 2026
@github-project-automation github-project-automation Bot moved this from Waiting on Author to Done in PR Backlog Jul 25, 2026
@IMax153

IMax153 commented Jul 25, 2026

Copy link
Copy Markdown
Member

Is there a process or pathway for becoming a member of the Effect-TS GitHub organization? I'd love to continue helping out where I can!

That's wonderful! I'm glad to hear the Effect codebase has been a source of inspiration :) We always welcome contributions from the community! The organization access is intentionally quite limited for security reasons, but always happy to review PRs and collaborate, either here or in Discord!

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: Done

Development

Successfully merging this pull request may close these issues.

unstable/cli: excess positional arguments are silently discarded instead of failing

2 participants