MCPcopy Create free account
hub / github.com/dropbox/dbxcli / renderCommandErrorWithJSON

Function renderCommandErrorWithJSON

cmd/output.go:332–352  ·  view source on GitHub ↗
(cmd *cobra.Command, err error, forceJSON bool)

Source from the content-addressed store, hash-verified

330}
331
332func renderCommandErrorWithJSON(cmd *cobra.Command, err error, forceJSON bool) {
333 if err == nil {
334 return
335 }
336 if cmd == nil {
337 cmd = RootCmd
338 }
339
340 if forceJSON || commandOutputFormat(cmd) == output.FormatJSON {
341 renderErr := output.New(cmd.OutOrStdout(), cmd.ErrOrStderr(), output.FormatJSON).Render(nil, newJSONErrorResponse(cmd, err))
342 if renderErr == nil {
343 return
344 }
345 err = renderErr
346 }
347
348 _, _ = fmt.Fprintf(cmd.ErrOrStderr(), "Error: %v\n", err)
349 if jsonErrorCode(err) == jsonErrorCodeUnknownCommand {
350 _, _ = fmt.Fprintf(cmd.ErrOrStderr(), "Run '%s --help' for usage.\n", cmd.CommandPath())
351 }
352}
353
354func exitCodeForError(err error) int {
355 if err == nil {

Callers 3

renderCommandErrorFunction · 0.85
ExecuteFunction · 0.85

Calls 5

NewFunction · 0.92
commandOutputFormatFunction · 0.85
newJSONErrorResponseFunction · 0.85
jsonErrorCodeFunction · 0.85
RenderMethod · 0.80