Skip to content

fix(cli): report command errors instead of exiting silently - #2430

Open
Athul Nambiar (athul-22) wants to merge 1 commit into
browseros-ai:mainfrom
athul-22:fix/cli-report-command-errors
Open

fix(cli): report command errors instead of exiting silently#2430
Athul Nambiar (athul-22) wants to merge 1 commit into
browseros-ai:mainfrom
athul-22:fix/cli-report-command-errors

Conversation

@athul-22

Copy link
Copy Markdown

Summary

browseros-cli exited with code 1 and no output at all on every command-line error — unknown flag, unknown shorthand, unknown subcommand, or any error returned from a RunE handler. A typo was indistinguishable from a crash or an unreachable server.

Fixes #2429.

Root cause

rootCmd set SilenceErrors: true, which tells Cobra not to print errors, but Execute() discarded the returned error rather than printing it itself:

err := rootCmd.Execute()
...
if err != nil {
    os.Exit(1)   // err is never printed
}

SilenceErrors is only safe when the caller reports the error. Nothing here did.

Fix

Drop SilenceErrors so Cobra reports the failure. Its default ErrPrefix() is already Error:, which matches the format output.Error already uses for in-command failures, so the two paths now read identically:

$ browseros-cli snapshot            # in-command error (unchanged)
Error: page id is required: pass -p/--page <id> ...

$ browseros-cli tabs --bogus        # Cobra-level error (was silent)
Error: unknown flag: --bogus

SilenceUsage: true is kept, so errors stay one line and don't dump the full usage block. Exit code 1 is unchanged.

Before / after

Command Before After
tabs --bogus exit 1, 0 bytes out Error: unknown flag: --bogus
snapshot -Z exit 1, 0 bytes out Error: unknown shorthand flag: 'Z' in -Z
definitely-not-a-command exit 1, 0 bytes out Error: unknown command "definitely-not-a-command" for "browseros-cli"

This also surfaces the wrapped errors config returns from its RunE (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 the Error: prefix. Confirmed it is a real regression test: with SilenceErrors restored it fails on all three cases with failed silently; the error must reach stderr, and passes with the fix.

Verified locally from packages/browseros-agent/apps/cli:

gofmt -l .   # clean
go vet ./... # clean
go build ./...
go test ./...
ok  browseros-cli
ok  browseros-cli/analytics
ok  browseros-cli/cmd
ok  browseros-cli/cmd/raw
ok  browseros-cli/mcp
ok  browseros-cli/update

Note

While reproducing this I noticed snapshot registers no flags, yet the agent guide shipped as browseros-cli --llm-txt documents snapshot -i five times (cmd/llm_txt.md lines 34, 36, 51, 61, 152) along with -c and -d N. The MCP snapshot tool does accept mode and depth, so the flags appear simply unwired. That is out of scope here and I'll file it separately.

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
@greptile-apps

greptile-apps Bot commented Aug 24, 2026

Copy link
Copy Markdown
Contributor

PR author is not in the allowed authors list.

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.

browseros-cli exits 1 with no message on any flag or command error

1 participant