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