fix(cli): report command errors instead of exiting silently - #2430
Open
Athul Nambiar (athul-22) wants to merge 1 commit into
Open
fix(cli): report command errors instead of exiting silently#2430Athul Nambiar (athul-22) wants to merge 1 commit into
Athul Nambiar (athul-22) wants to merge 1 commit into
Conversation
rootCmd set SilenceErrors, which tells Cobra not to print errors, but Execute() discarded the returned error and called os.Exit(1) without printing it. Every flag-parsing failure, unknown subcommand, and error returned from a RunE handler therefore terminated with exit code 1 and no output on stdout or stderr, leaving a typo indistinguishable from a crash or an unreachable server. Drop SilenceErrors so Cobra reports the failure. Its default ErrPrefix is already "Error:", matching the format output.Error already uses for in-command failures. SilenceUsage stays, so errors do not dump usage. Fixes browseros-ai#2429
Contributor
|
PR author is not in the allowed authors list. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
browseros-cliexited with code 1 and no output at all on every command-line error — unknown flag, unknown shorthand, unknown subcommand, or any error returned from aRunEhandler. A typo was indistinguishable from a crash or an unreachable server.Fixes #2429.
Root cause
rootCmdsetSilenceErrors: true, which tells Cobra not to print errors, butExecute()discarded the returned error rather than printing it itself:SilenceErrorsis only safe when the caller reports the error. Nothing here did.Fix
Drop
SilenceErrorsso Cobra reports the failure. Its defaultErrPrefix()is alreadyError:, which matches the formatoutput.Erroralready uses for in-command failures, so the two paths now read identically:SilenceUsage: trueis kept, so errors stay one line and don't dump the full usage block. Exit code 1 is unchanged.Before / after
tabs --bogusError: unknown flag: --bogussnapshot -ZError: unknown shorthand flag: 'Z' in -Zdefinitely-not-a-commandError: unknown command "definitely-not-a-command" for "browseros-cli"This also surfaces the wrapped errors
configreturns from itsRunE(loading config: %w,saving config: %w), which were swallowed the same way.Tests
Added
TestCommandErrorsAreReportedToStderr— a table test over unknown flag / unknown shorthand / unknown command that asserts the message reaches stderr and keeps theError:prefix. Confirmed it is a real regression test: withSilenceErrorsrestored it fails on all three cases withfailed silently; the error must reach stderr, and passes with the fix.Verified locally from
packages/browseros-agent/apps/cli:Note
While reproducing this I noticed
snapshotregisters no flags, yet the agent guide shipped asbrowseros-cli --llm-txtdocumentssnapshot -ifive times (cmd/llm_txt.mdlines 34, 36, 51, 61, 152) along with-cand-d N. The MCPsnapshottool does acceptmodeanddepth, so the flags appear simply unwired. That is out of scope here and I'll file it separately.