Skip to content

fix(cli): exit 2 for arg-count misuse on review submit and preview#2393

Open
abhay-codes07 wants to merge 1 commit into
AgentWrapper:mainfrom
abhay-codes07:fix/cli-arg-count-usage-exit-code
Open

fix(cli): exit 2 for arg-count misuse on review submit and preview#2393
abhay-codes07 wants to merge 1 commit into
AgentWrapper:mainfrom
abhay-codes07:fix/cli-arg-count-usage-exit-code

Conversation

@abhay-codes07

Copy link
Copy Markdown

Closes #2391.

What

ao review submit and ao preview (and ao preview clear) exited 1 instead of 2 when given too many positional args, breaking the usageError → exit-2 convention in AGENTS.md ("Return usage errors as usageError so CLI misuse exits 2; runtime/daemon failures should exit 1.").

Why

Their Args validators were a bare cobra.MaximumNArgs(1) / cobra.NoArgs. Cobra's arg-count error is a plain error, and the root's SetFlagErrorFunc only wraps flag-parse errors as usageError — not Args validation — so ExitCode returned 1. Every other command wraps its validator (noArgs, oneSessionIDArg, the inline wrappers in project.go / completion.go).

Change

Wrap the validators so arg-count misuse returns usageError (exit 2), and reuse the existing noArgs helper for preview clear.

Tests

  • Added TestReviewSubmitTooManyArgsIsUsageError, TestPreview_TooManyArgsIsUsageError, and TestPreviewClear_TooManyArgsIsUsageError. Each fails before the change (exit 1) and passes after (exit 2).
  • These match the commands' existing usage-error tests, which already assert exit 2 for other misuse.
  • go test ./internal/cli/... green; go vet and gofmt clean.

cc @harshitsinghbhandari — matches the existing usage-error tests on these commands; happy to tweak.

The usageError convention (AGENTS.md) requires CLI misuse to exit 2 and
runtime/daemon failures to exit 1. `ao review submit` and `ao preview`
declared their positional-arg validators as a bare cobra.MaximumNArgs(1)
(and `preview clear` as cobra.NoArgs), whose validation error is a plain
cobra error, not a usageError. Passing too many positional args therefore
exited 1 instead of 2 — inconsistent with every other command
(noArgs, oneSessionIDArg, project, completion) and with these commands'
own usage-error tests, which already assert exit 2 for other misuse.

Wrap the validators so arg-count misuse returns usageError (exit 2), and
reuse the existing noArgs helper for `preview clear`. Add tests covering
the too-many-args path for review submit, preview, and preview clear.
Copilot AI review requested due to automatic review settings July 3, 2026 21:38

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

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.

bug(cli): ao review submit and ao preview exit 1 (not 2) on arg-count misuse

2 participants