Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Silence cobra usage and errors #4404

Closed
Tracked by #3791
wdbaruni opened this issue Sep 11, 2024 · 1 comment
Closed
Tracked by #3791

Silence cobra usage and errors #4404

wdbaruni opened this issue Sep 11, 2024 · 1 comment

Comments

@wdbaruni
Copy link
Member

wdbaruni commented Sep 11, 2024

When we face an error, cobra prints the whole command usage, and also the error again, which is noisy.

Example

→ bacalhau job describe j033
11:58:29.663 | INF ProtocolLabs/workspace/bacalhau/pkg/repo/fs.go:92 > Initializing repo at '/var/folders/vz/pk7pk9qx1c5gbktg8nhyl88h0000gn/T/tmp.t9RCAPgQtw' for environment 'production'
Error: could not get job j033: Unexpected response code: 500 ({
  "error": "Job not found. ID: j033",
  "message": "Internal Server Error"
})
Usage:
  bacalhau job describe [id] [flags]

Examples:
  # Describe a job with the full ID
  bacalhau job describe j-e3f8c209-d683-4a41-b840-f09b88d087b9

  # Describe a job with the a shortened ID
  bacalhau job describe j-47805f5c

  # Describe a job with json output
  bacalhau job describe --output json --pretty j-b6ad164a

Flags:
  -h, --help            help for describe
      --output format   The output format for the command (one of ["json" "yaml"])
      --pretty          Pretty print the output. Only applies to json and yaml output formats.

Global Flags:
      --api-host string         The host for the client and server to communicate on (via REST).
                                Ignored if BACALHAU_API_HOST environment variable is set. (default "bootstrap.production.bacalhau.org")
      --api-port int            The port for the client and server to communicate on (via REST).
                                Ignored if BACALHAU_API_PORT environment variable is set. (default 1234)
      --cacert string           The location of a CA certificate file when self-signed certificates
                                	are used by the server
  -c, --config string           config file(s) or dot separated path(s) to config values
      --insecure                Enables TLS but does not verify certificates
      --log-mode logging-mode   Log format: 'default','station','json','combined','event' (default default)
  -r, --repo string             filesystem path to bacalhau repo (default "/var/folders/vz/pk7pk9qx1c5gbktg8nhyl88h0000gn/T/tmp.t9RCAPgQtw")
      --tls                     Instructs the client to use TLS

could not get job j033: Unexpected response code: 500 ({
  "error": "Job not found. ID: j033",
  "message": "Internal Server Error"
})

Desired Behaviour

Just print the error, and make it clear that this is an error, by either prefixing with Error: or in a different color like we do when we print errors in job history events

if j.event.Details[models.DetailsKeyIsError] == "true" {
res = output.RedStr(res)
}

@wdbaruni wdbaruni changed the title Silence cobra usage and e Silence cobra usage and errors Sep 11, 2024
@frrist
Copy link
Member

frrist commented Sep 11, 2024

Agreed! And adding to this, we currently print the error message twice, e.g.

> bacalhau job describe j033

<the error message>

<usage>

<the error message again>

I think we might need a mixture of: https://github.com/spf13/cobra/blob/371ae25d2c82e519feb48c82d142e6a696fd06dd/command.go#L232-L236

// SilenceErrors is an option to quiet errors down stream.
	SilenceErrors bool

	// SilenceUsage is an option to silence usage when an error occurs.
	SilenceUsage bool

on each command.

@udsamani udsamani moved this from Inbox to Done in Engineering Planning Sep 16, 2024
@udsamani udsamani closed this as completed by moving to Done in Engineering Planning Sep 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

No branches or pull requests

3 participants