enrichGHError enriches an error returned from a gh CLI command with the stderr output captured in *exec.ExitError. When cmd.Output() (stdout-only capture) fails, Go populates ExitError.Stderr with the command's stderr, which typically contains the human-readable error message from gh. This function
(err error)
| 99 | // This function appends that message to the error so callers see useful |
| 100 | // diagnostics instead of a bare "exit status 1". |
| 101 | func enrichGHError(err error) error { |
| 102 | if err == nil { |
| 103 | return nil |
| 104 | } |
| 105 | var exitErr *exec.ExitError |
| 106 | if errors.As(err, &exitErr) && len(exitErr.Stderr) > 0 { |
| 107 | stderr := strings.TrimSpace(string(exitErr.Stderr)) |
| 108 | if stderr != "" { |
| 109 | return fmt.Errorf("%w: %s", err, stderr) |
| 110 | } |
| 111 | } |
| 112 | return err |
| 113 | } |
| 114 | |
| 115 | // runGHWithSpinnerContext executes a gh CLI command with context support, a spinner, |
| 116 | // and returns the output. This is the core implementation for all RunGH* functions. |