Skip to content

prevent printing usages on error#457

Merged
nabuskey merged 1 commit intocnoe-io:mainfrom
nabuskey:silent-usage
Nov 22, 2024
Merged

prevent printing usages on error#457
nabuskey merged 1 commit intocnoe-io:mainfrom
nabuskey:silent-usage

Conversation

@nabuskey
Copy link
Copy Markdown
Collaborator

Set SilenceUsage: true, for commands to prevent usages from being printed every time an error occurs.

before:

idpbuilder get secrets
Error: getting kube config: invalid configuration: no configuration has been provided, try setting KUBERNETES_MASTER environment variable
Usage:
  idpbuilder get secrets [flags]

Flags:
  -h, --help   help for secrets

Global Flags:
      --color              Enable colored log messages.
  -l, --log-level string   Set the log verbosity. Supported values are: debug, info, warn, and error. (default "info")
  -o, --output string      Output format. json or yaml.
  -p, --packages strings   names of packages.

getting kube config: invalid configuration: no configuration has been provided, try setting KUBERNETES_MASTER environment variable

After:

idpbuilder get secrets
Error: getting kube config: invalid configuration: no configuration has been provided, try setting KUBERNETES_MASTER environment variable
getting kube config: invalid configuration: no configuration has been provided, try setting KUBERNETES_MASTER environment variable

fixes: #439

Signed-off-by: Manabu McCloskey <manabu.mccloskey@gmail.com>
Copy link
Copy Markdown
Contributor

@cmoulliard cmoulliard left a comment

Choose a reason for hiding this comment

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

I did a test where I provided a wrong package to the command

Before:

❯ ./idpbuilder get secrets -p argocdddd
Error: listing secrets: failed to get API group resources: unable to retrieve the complete list of server APIs: v1: Get "https://127.0.0.1:51605/api/v1": dial tcp 127.0.0.1:51605: connect: connection refused
Usage:
  idpbuilder get secrets [flags]

Flags:
  -h, --help   help for secrets

Global Flags:
      --color              Enable colored log messages.
  -l, --log-level string   Set the log verbosity. Supported values are: debug, info, warn, and error. (default "info")
  -o, --output string      Output format. json or yaml.
  -p, --packages strings   names of packages.

listing secrets: failed to get API group resources: unable to retrieve the complete list of server APIs: v1: Get "https://127.0.0.1:51605/api/v1": dial tcp 127.0.0.1:51605: connect: connection refused

After:

❯ ./idpbuilder get secrets -p argocdddd
Error: listing secrets: failed to get API group resources: unable to retrieve the complete list of server APIs: v1: Get "https://127.0.0.1:51605/api/v1": dial tcp 127.0.0.1:51605: connect: connection refused
listing secrets: failed to get API group resources: unable to retrieve the complete list of server APIs: v1: Get "https://127.0.0.1:51605/api/v1": dial tcp 127.0.0.1:51605: connect: connection refused

Note: We should review how we log messages too as error is reported twice. This ticket could be used for that purpose: #450

@nabuskey
Copy link
Copy Markdown
Collaborator Author

Yeah we should definitely look into why errors are being printed twice.

@nabuskey nabuskey merged commit 4d9f1a0 into cnoe-io:main Nov 22, 2024
@nabuskey nabuskey deleted the silent-usage branch November 22, 2024 15:40
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.

[Suggestion]: Remove usage from message logged when error occurs

2 participants