Skip to content

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

Description

@abhay-codes07

Summary

AGENTS.md states the convention: "Return usage errors as usageError so CLI misuse exits 2; runtime/daemon failures should exit 1." Two commands don't follow it for argument-count misuse — they exit 1 instead of 2.

Where

ao review submit and ao preview declare their positional-arg validators with a bare Cobra validator:

  • backend/internal/cli/review.goArgs: cobra.MaximumNArgs(1)
  • backend/internal/cli/preview.goArgs: cobra.MaximumNArgs(1) (and preview clearArgs: cobra.NoArgs)

Cobra's arg-count error is a plain errors.New(...). The root's SetFlagErrorFunc only wraps flag-parse errors as usageError, not Args validation, so a too-many-args error is not a usageError and ExitCode returns 1.

Every other command wraps its validator so arg-count misuse becomes a usageError (exit 2): noArgs (root.go), oneSessionIDArg / the claim-pr and rename validators (session.go), and the inline wrappers in project.go and completion.go.

Repro

$ ao review submit mer-1 mer-2
Error: accepts at most 1 arg(s), received 2
$ echo $?
1        # expected 2

Same for ao preview a b and ao preview clear extra.

This is inconsistent with the commands' own tests, which already assert exit 2 for their other usage errors (TestReviewSubmitMissing*IsUsageError, TestPreview_*IsUsageError). A caller that distinguishes usage misuse (2) from a daemon/runtime failure (1) misclassifies these.

Suggested fix

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions