Skip to content

exit 1 when a command fails, and print the error once - #1249

Merged
cdalar merged 1 commit into
mainfrom
exit-code-on-error
Oct 26, 2026
Merged

cdalar merged 1 commit into
mainfrom
exit-code-on-error

Conversation

@cdalar

@cdalar cdalar commented Oct 26, 2026

Copy link
Copy Markdown
Owner

Found while testing onctl -p ac without Apple's container CLI: the message was right, but

  • onctl -p ac claude printed it twice -- cobra's Error: plus the whole usage text, as if it were a typo, then main's log line -- and exited 0;
  • onctl -p ac ls logged it, printed an empty table and exited 0, so a script read "no VMs".

The cause is general, not ac's: main logged Execute's error and returned, and ls never returned one.

Changes:

  • main.go: os.Exit(1) after logging the error.
  • rootCmd: SilenceUsage and SilenceErrors, so a run-time failure is main's one line. A bad flag keeps a pointer to the usage through flagError: unknown flag: --kep / Run 'onctl claude --help' for usage.
  • ls: RunE, returning the provider's error after printing what the other call did return (as listVMs intends).

Checked by hand with the CLI path pointed at a missing binary: claude and ls exit 1 with one error line, an unknown flag exits 1 with the hint, a working ls still exits 0. Tests: TestListCmd_ProviderErrorIsTheResult, TestRootErrorsPrintOnce.

🤖 Generated with Claude Code

https://claude.ai/code/session_01FGfFdYSzrrKe3ySAVMPSNR

With Apple's container CLI missing, `onctl -p ac claude` printed the
error twice -- cobra's "Error:" with the whole usage text, as if it were
a typo, then main's log line -- and exited 0; `onctl -p ac ls` logged it,
printed an empty table and exited 0, so a script read "no VMs". The
cause was general: main logged Execute's error and returned, and ls
never returned one.

main exits 1 on an error. The root command silences cobra's usage and
error printing, so a run-time failure is main's one line; a bad flag
keeps a pointer to the usage (flagError: "Run 'onctl claude --help' for
usage."). ls returns the provider's error after showing what the other
call did return, as listVMs intends.

Claude-Session: https://claude.ai/code/session_01FGfFdYSzrrKe3ySAVMPSNR
@codecov

codecov Bot commented Oct 26, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 80.00000% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 47.77%. Comparing base (1d79ad2) to head (9babb68).
⚠️ Report is 4 commits behind head on main.

Files with missing lines Patch % Lines
main.go 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1249      +/-   ##
==========================================
+ Coverage   47.57%   47.77%   +0.19%     
==========================================
  Files          81       81              
  Lines        9341     9342       +1     
==========================================
+ Hits         4444     4463      +19     
+ Misses       4897     4879      -18     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@cdalar
cdalar merged commit ea36f0b into main Oct 26, 2026
13 checks passed
@cdalar
cdalar deleted the exit-code-on-error branch October 26, 2026 12:29
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

⌂ 换网址