Cobra prints full usage on internal failures, burying the actual error #41
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
From the 1.0 security survey.
Problem
internal/cli/root.go:36-38sets both flags off explicitly:No subcommand overrides this. So every
RunEthat returns an internal error — a failed decrypt, a missing unlocker, an I/O error, a wrong passphrase — dumps the entire usage block after the error message.Two consequences. The mild one is noise. The one that matters for a secrets tool: the actual error is pushed far up the scrollback behind a wall of flag documentation, so a user who mistypes a passphrase and one who has a corrupted or unreadable vault get visually near-identical output, and the second is easy to miss. Usage text is the correct response to "you called this wrong" and actively unhelpful for "your key material could not be read".
Definition of done
RunEbodies.SilenceErrors: trueis that nothing prints the error afterward, or that it prints twice.RunEfailure shows the error without usage.make checkgreen.TODO.mdupdated in the same commit.Implementation requirements
SilenceUsage: trueon the root command, which suppresses usage forRunEerrors while cobra still prints usage for argument and flag parsing errors it raises itself. Verify that is actually the observed behavior for this cobra version rather than assuming it — test both paths.SilenceErrors. Leaving itfalselets cobra print the error, which is usually what you want; setting ittruemeansEntry()must print the error itself. Do not set ittruewithout adding that print, or failures will exit non-zero silently — which in a secrets tool is a genuinely dangerous outcome, since a script would see a failure with no indication of what went wrong.Entry(). If both land, keep the error-printing and the purge ordering coherent: print the error, then purge, then exit.// Ensure usage is shown after errorscomment.