Skip to content

fix(cli): avoid duplicate error output in ExitNicelyOnError#6366

Open
isha822 wants to merge 1 commit intomindersec:mainfrom
isha822:fix-cli-error-stutter
Open

fix(cli): avoid duplicate error output in ExitNicelyOnError#6366
isha822 wants to merge 1 commit intomindersec:mainfrom
isha822:fix-cli-error-stutter

Conversation

@isha822
Copy link
Copy Markdown

@isha822 isha822 commented Apr 14, 2026

Summary

This PR resolves an issue where the mindev CLI outputs duplicated error messages upon command failure. Previously, the ExitNicelyOnError utility printed identical strings for both the Message and Details fields. Additionally, the Cobra framework's default error handling printed the raw error before the custom formatter executed, creating redundant terminal output.

Changes introduced:

  • Added a validation guard in internal/util/cli/cli.go to only print Details if the string differs from Message.
  • Configured SilenceErrors: true in the root command (cmd/dev/app/root.go) to prevent Cobra from redundantly printing the error, deferring entirely to the custom CLI formatter.

Dependencies: None

Testing

Changes were verified locally via manual CLI execution and existing unit tests.

Steps to reproduce:

  1. Build the local developer CLI: go build -o bin/mindev ./cmd/dev
  2. Trigger a standard file omission error: ./bin/mindev ruletype lint -r fake.yaml

Output Verification:
The CLI now outputs a single Message and Details block without the preceding Error: from Cobra or duplicated detail lines.

Before:

Error: error expanding file args: error getting file info: stat fake.yaml: no such file or directory
Message: Error on execute
Details: error expanding file args: error getting file info: stat fake.yaml: no such file or directory

After:

Message: Error on execute
Details: error expanding file args: error getting file info: stat fake.yaml: no such file or directory

Unit Tests:

  • go test ./internal/util/cli/... - PASS

When details and message contain the same string, the CLI prints the same information twice. Added a guard so Details is only printed when it differs from Message. Also set SilenceErrors in the mindev root command to prevent Cobra from redundantly printing the error before the custom formatter.
@isha822 isha822 requested a review from a team as a code owner April 14, 2026 18:33
@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Apr 14, 2026

CLA assistant check
All committers have signed the CLA.

Copy link
Copy Markdown
Member

@evankanderson evankanderson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your contribution (sorry, it got stuck behind a bunch of other PRs while I was on vacation). You'll need to sign the CLA to grant OpenSSF permissions to use your contributions before this can be merged.

@coveralls
Copy link
Copy Markdown

Coverage Status

coverage: 59.542% (+0.003%) from 59.539% — isha822:fix-cli-error-stutter into mindersec:main

@isha822
Copy link
Copy Markdown
Author

isha822 commented May 3, 2026

Thanks for the review! @evankanderson I've just signed the CLA. Let me know if there is anything else needed from my end to get this merged

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.

4 participants