Skip to content

fix(cli): remove duplicate error output and suppress usage on runtime errors#466

Merged
GenerQAQ merged 1 commit intodevfrom
fix/cli-double-error-print
Mar 22, 2026
Merged

fix(cli): remove duplicate error output and suppress usage on runtime errors#466
GenerQAQ merged 1 commit intodevfrom
fix/cli-double-error-print

Conversation

@GenerQAQ
Copy link
Copy Markdown
Contributor

Why we need this PR?

Running acontext whoami (or dash ping) when not logged in prints the error message twice — once by Cobra automatically and once by manual fmt.Fprintf in main(). Additionally, runtime errors incorrectly show Usage/help text.

Describe your solution

  1. Remove duplicate error printmain.go had fmt.Fprintf(os.Stderr, "Error: %v\n", cmdErr) which duplicated Cobra's built-in error output. Removed it; Cobra handles the printing.
  2. Add SilenceUsage: true on root command — runtime errors (e.g. API failures, not-logged-in) should not print Usage info. Usage is only useful for argument/syntax errors, which Cobra handles before RunE.
  3. whoami not-logged-in is informational, not an errorrunWhoami now prints the message and returns nil instead of returning an error. This matches runLogout's pattern which already does the same.
  4. dash ping state checks — "no project selected", "no API key", and ping failure now print info and return nil instead of returning errors. The ping failure case was double-printing (diagnostic output + separate error return).

Implementation Tasks

  • Add SilenceUsage: true to rootCmd in main.go
  • Remove manual fmt.Fprintf(os.Stderr, ...) error print in main()
  • Change runWhoami to treat not-logged-in as info output
  • Fix dash ping double-print and state-check error returns

Impact Areas

  • CLI Tool

Checklist

  • Open your pull request against the dev branch.
  • All tests pass in available continuous integration systems (e.g., GitHub Actions).
  • Tests are added or modified as needed to cover code changes.

🤖 Generated with Claude Code

… errors

- Add SilenceUsage to root command so runtime errors don't print usage info
- Remove manual error print in main() that duplicated Cobra's automatic output
- Make whoami print "not logged in" as info instead of returning it as error
- Fix dash ping double-printing error details then a separate "Error: ping failed"

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@GenerQAQ GenerQAQ requested a review from a team as a code owner March 22, 2026 09:56
@GenerQAQ GenerQAQ merged commit 8720f45 into dev Mar 22, 2026
7 checks passed
@GenerQAQ GenerQAQ deleted the fix/cli-double-error-print branch March 22, 2026 09:59
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