Skip to content

Stop dumping usage on every failed check - #214

Merged
vertti merged 2 commits into
mainfrom
quiet-usage-on-check-failure
Aug 11, 2026
Merged

Stop dumping usage on every failed check#214
vertti merged 2 commits into
mainfrom
quiet-usage-on-check-failure

Conversation

@vertti

@vertti vertti commented Aug 11, 2026

Copy link
Copy Markdown
Owner

A failing check is preflight's normal operating mode. Cobra treats any error from RunE as a usage mistake, so every failure printed Error: check failed plus the command's entire flag list:

$ preflight env NOPE_XYZ
[FAIL] env: NOPE_XYZ
       not set
Error: check failed
Usage:
  preflight env <variable> [flags]
Flags:
      --allow-empty          pass if defined but empty
      ... 23 more flag lines ...

30 lines to say one thing. In a Docker RUN layer or a CI log — where stdout and stderr are merged — five failing checks bury the messages under ~150 lines of flag reference. The Error: check failed line is also pure redundancy; [FAIL] and exit 1 already said it.

Change

rootCmd sets SilenceUsage and SilenceErrors. main routes the error through reportExecuteError, which distinguishes the two cases:

  • ErrCheckFailed → nothing further. The [FAIL] line and exit 1 are the complete signal.
  • anything else → message plus usage. Unknown flag, missing argument, bad flag combination — these are the user getting the invocation wrong, and usage is exactly what helps.

It uses ExecuteC rather than Execute so a usage error shows the failing subcommand's usage, not the root command's.

Result

Invocation Before After
env NOPE_XYZ 30 lines 2 lines
file /nonexistent 22 lines 2 lines
cmd definitelynotreal 17 lines 2 lines
env PATH --nope (unknown flag) 27 lines 27 lines — unchanged

Verified unaffected: --version, --help, unknown command, run with a missing .preflight, the exec refusal from #210, and the flag-combination error in cmd_json.go — which now correctly shows the json command's usage.

No doc change needed

docs/usage.md's "Output Format" section already showed clean [OK]/[FAIL] blocks with no usage dump. The docs described the intended behavior all along; this makes the binary match them.

Tests

TestReportExecuteError, written first and confirmed red, covers: a bare ErrCheckFailed prints nothing; a wrapped ErrCheckFailed also prints nothing (so the behavior survives future %w wrapping); a usage error prints both message and usage; and a nil command doesn't panic.

A failing check is preflight's normal operating mode, but cobra treats any
error from RunE as a usage mistake, so every failure printed "Error: check
failed" plus the command's full flag list. `preflight env NOPE` produced 30
lines to say one thing, and in a Docker RUN layer or CI log that buries the
message it exists to deliver.

rootCmd sets SilenceUsage and SilenceErrors, and main routes the error
through reportExecuteError: ErrCheckFailed prints nothing further, since
[FAIL] and exit 1 already said it. Everything else — unknown flag, missing
argument, bad flag combination — still prints the message and usage, which
is where usage actually helps.

Uses ExecuteC so a usage error shows the failing subcommand's usage rather
than the root command's.

    env NOPE_XYZ          30 lines -> 2
    env PATH --nope       27 lines -> 27 (unchanged, as intended)
@coderabbitai

coderabbitai Bot commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

@vertti, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 55 minutes

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 7b4331ba-198d-481f-b7e5-a610789b5683

📥 Commits

Reviewing files that changed from the base of the PR and between 5df1002 and c8b7654.

📒 Files selected for processing (3)
  • cmd/preflight/main.go
  • cmd/preflight/main_entry.go
  • cmd/preflight/main_test.go

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.

@codecov

codecov Bot commented Aug 11, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 75.00000% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 93.00%. Comparing base (5df1002) to head (c8b7654).

Files with missing lines Patch % Lines
cmd/preflight/main_entry.go 0.00% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #214      +/-   ##
==========================================
- Coverage   93.06%   93.00%   -0.07%     
==========================================
  Files          49       49              
  Lines        1861     1872      +11     
==========================================
+ Hits         1732     1741       +9     
- Misses         92       94       +2     
  Partials       37       37              
Files with missing lines Coverage Δ
cmd/preflight/main.go 100.00% <100.00%> (ø)
cmd/preflight/main_entry.go 0.00% <0.00%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@vertti
vertti merged commit af6f474 into main Aug 11, 2026
18 of 19 checks passed
@vertti
vertti deleted the quiet-usage-on-check-failure branch August 11, 2026 12:55
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