Skip to content

cli: stop dumping help on every error#334

Open
cpcloud wants to merge 1 commit into
kenn-io:mainfrom
cpcloud:worktree-transient-snacking-petal
Open

cli: stop dumping help on every error#334
cpcloud wants to merge 1 commit into
kenn-io:mainfrom
cpcloud:worktree-transient-snacking-petal

Conversation

@cpcloud
Copy link
Copy Markdown
Contributor

@cpcloud cpcloud commented May 21, 2026

Summary

Cobra's default behavior dumps the full usage block on every RunE error, which buries actual error messages under a wall of help text. Four import commands worked around this by scattering SilenceUsage: true on their cobra.Command structs, but every other RunE handler still printed the help wall on, e.g., a failed sync or a missing OAuth token.

Mirrors the cleanup done in roborev (roborev-dev/roborev#727).

What changed

  • Root PersistentPreRunE sets cmd.SilenceUsage = true at the top. Cobra runs flag parsing and Args validators before PersistentPreRunE, so unknown flags / bad arg counts still get usage. Anything reached via RunE runs with usage silenced.
  • usageErr(cmd, err) flips SilenceUsage back to false for RunE-internal invocation-contract errors (mutex flags, bad enums, missing required values, bad date/phone formats). Applied across syncfull, stats, search, import (whatsapp), export-attachment, deletions, delete-deduped, create-subset, add-imap, add-account.
  • Drop the now-redundant SilenceUsage assignments from the four import_* commands.

Resulting behavior

invocation output
msgvault sync-full --bogus Error: unknown flag: --bogus + usage (cobra default)
msgvault sync-full --limit=-1 ... Error: --limit must be a non-negative number + usage
msgvault sync-incremental missing@... Error: ...no source found... only (no usage)

@roborev-ci
Copy link
Copy Markdown

roborev-ci Bot commented May 21, 2026

roborev: Combined Review (33c3f11)

Summary verdict: One medium CLI regression remains; no high or critical findings were reported.

Medium

  • cmd/msgvault/cmd/root.go:59 - cmd.SilenceUsage = true is set before Cobra’s required-flag and mutually-exclusive flag validation runs, so built-in invocation errors from MarkFlagRequired / MarkFlagsMutuallyExclusive no longer show usage output.
    • Fix: Avoid silencing usage before Cobra’s built-in validation completes, or customize error handling so only runtime errors suppress usage.

Synthesized from 3 reviews (agents: codex, gemini | types: default, security)

Cobra's default behavior dumps the full usage block on every RunE error,
which buries actual error messages under a wall of help text. Four import
commands had been working around this by scattering SilenceUsage: true on
their cobra.Command structs, but every other RunE handler still printed
the help wall on, e.g., a failed sync or a missing OAuth token.

Centralize the policy:

- Root PersistentPreRunE sets cmd.SilenceUsage = true at the top.
  Cobra runs flag parsing and Args validators before PersistentPreRunE,
  so unknown flags / bad arg counts still get usage. Everything reached
  via RunE runs with usage silenced.

- usageErr(cmd, err) flips SilenceUsage back to false for RunE-internal
  invocation-contract errors (mutex flags, bad enums, missing required
  values, bad date/phone formats). Applied across syncfull, stats,
  search, import (whatsapp), export-attachment, deletions,
  delete-deduped, create-subset, add-imap, and add-account.

- Drop the now-redundant SilenceUsage assignments from the four
  import_* commands.

Resulting behavior:

  msgvault sync-full --bogus           Error + usage (cobra default)
  msgvault sync-full --limit=-1        Error + usage (usageErr)
  msgvault sync-incremental missing@   Error only (runtime)
@cpcloud cpcloud force-pushed the worktree-transient-snacking-petal branch from 33c3f11 to 9b88169 Compare May 22, 2026 09:40
@roborev-ci
Copy link
Copy Markdown

roborev-ci Bot commented May 22, 2026

roborev: Combined Review (9b88169)

No Medium, High, or Critical findings were reported.

All review outputs are clean at the requested severity threshold.


Synthesized from 3 reviews (agents: codex, gemini | types: default, security)

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