Skip to content

fix(cli): print each error once - #44

Merged
thanhleviet merged 2 commits into
mainfrom
fix/double-error-print
Aug 5, 2026
Merged

thanhleviet merged 2 commits into
mainfrom
fix/double-error-print

Conversation

@thanhleviet

Copy link
Copy Markdown
Collaborator

Every error from atb reached the user twice.

$ atb query --runs ERR9999999999 --columns sample_accession
Warning: 1 of 1 run accession(s) are not in run.parquet: ERR9999999999
Error: none of the 1 run accession(s) are in run.parquet
none of the 1 run accession(s) are in run.parquet

internal/cli/root.go set SilenceUsage but not SilenceErrors, so cobra
printed the Error: ... line when the command returned, and cmd/atb/main.go
printed the same message again. One failure looked like two. It affected every
error path, not one command.

The fix

Silence cobra's reporting and leave main as the only printer.

The alternative - dropping main's print and letting cobra report - puts the
error before WaitForUpdateCheck() runs, and that check also writes to
stderr, so a failure could end up buried above the update banner. Printing from
main keeps the error as the last line. It keeps the Error: prefix, which
matters because atb writes progress and warnings to stderr too; without a
prefix a bare error line is indistinguishable from Resolved 99 run accession(s)....

run() is extracted from main() so the exit path is testable. Behavior of
main is otherwise unchanged.

After

$ atb query --runs ERR9999999999 --columns sample_accession
Warning: 1 of 1 run accession(s) are not in run.parquet: ERR9999999999
Error: none of the 1 run accession(s) are in run.parquet

Verification

  • 3 new tests in cmd/atb/main_test.go, written first and watched fail
    (error reported 2 time(s), want 1). cmd/atb was previously untested, so
    the suite goes from 21 to 22 covered packages.
  • Checked on a real binary across four error paths - unknown column, unresolved
    run accession, unknown flag, unknown command - each prints once and exits 1.
    Unknown-command takes a different cobra branch, so it is covered separately.
  • Success paths are byte-identical to released v0.21.0 on both stdout and
    stderr; only error output changed.
  • go vet clean, gofmt clean on the touched files, make docs produces no
    diff.

Cobra printed the "Error: ..." line when a command returned and main
printed the same message again, so a single failure was reported twice.

Silence cobra's reporting and keep main as the only printer. Main runs
after the background update check has finished writing to stderr, so the
error stays the last line the user sees. It keeps the "Error: " prefix,
which separates a failure from the progress and warning output atb also
writes to stderr.

Extract run() from main so the exit path can be tested.
@thanhleviet
thanhleviet merged commit 82b2fbb into main Aug 5, 2026
6 checks passed
@thanhleviet
thanhleviet deleted the fix/double-error-print branch August 5, 2026 16:22
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