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

Function printError

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

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