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

Function printError

internal/ghcmd/cmd.go:308–334  ·  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

306// JSON fields and environment variables they need to correct themselves without
307// a second round trip.
308func printError(out io.Writer, cs *iostreams.ColorScheme, err error, cmd *cobra.Command, debug, fullHelp bool) {
309 if dnsError, ok := errors.AsType[*net.DNSError](err); ok {
310 fmt.Fprintf(out, "error connecting to %s\n", dnsError.Name)
311 if debug {
312 fmt.Fprintln(out, dnsError)
313 }
314 fmt.Fprintln(out, "check your internet connection or https://githubstatus.com")
315 return
316 }
317
318 fmt.Fprintln(out, err)
319
320 var flagError *cmdutil.FlagError
321 if errors.As(err, &flagError) || strings.HasPrefix(err.Error(), "unknown command ") {
322 if !strings.HasSuffix(err.Error(), "\n") {
323 fmt.Fprintln(out)
324 }
325 if fullHelp {
326 // Render into out rather than calling cmd.Help(), which would send
327 // the help text to stdout and split a single failure across two
328 // streams.
329 root.WriteHelp(out, cs, cmd)
330 return
331 }
332 fmt.Fprintln(out, cmd.UsageString())
333 }
334}
335
336func authRecoveryCommand(cfg gh.Config, httpErr api.HTTPError) string {
337 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