MCPcopy Create free account
hub / github.com/cli/cli / printError

Function printError

internal/ghcmd/cmd.go:281–307  ·  view source on GitHub ↗

printError writes err to out, followed by usage information when the error is the result of command misuse. When fullHelp is set the complete help text is written instead of the terse usage string, giving AI agents the examples, JSON fields and environment variables they need to correct themselves w

(out io.Writer, cs *iostreams.ColorScheme, err error, cmd *cobra.Command, debug, fullHelp bool)

Source from the content-addressed store, hash-verified

279// JSON fields and environment variables they need to correct themselves without
280// a second round trip.
281func printError(out io.Writer, cs *iostreams.ColorScheme, err error, cmd *cobra.Command, debug, fullHelp bool) {
282 if dnsError, ok := errors.AsType[*net.DNSError](err); ok {
283 fmt.Fprintf(out, "error connecting to %s\n", dnsError.Name)
284 if debug {
285 fmt.Fprintln(out, dnsError)
286 }
287 fmt.Fprintln(out, "check your internet connection or https://githubstatus.com")
288 return
289 }
290
291 fmt.Fprintln(out, err)
292
293 var flagError *cmdutil.FlagError
294 if errors.As(err, &flagError) || strings.HasPrefix(err.Error(), "unknown command ") {
295 if !strings.HasSuffix(err.Error(), "\n") {
296 fmt.Fprintln(out)
297 }
298 if fullHelp {
299 // Render into out rather than calling cmd.Help(), which would send
300 // the help text to stdout and split a single failure across two
301 // streams.
302 root.WriteHelp(out, cs, cmd)
303 return
304 }
305 fmt.Fprintln(out, cmd.UsageString())
306 }
307}
308
309func authRecoveryCommand(cfg gh.Config, httpErr api.HTTPError) string {
310 if httpErr.RequestURL == nil {

Callers 2

MainFunction · 0.70
Test_printErrorFunction · 0.70

Calls 2

WriteHelpFunction · 0.92
ErrorMethod · 0.45

Tested by 1

Test_printErrorFunction · 0.56