MCPcopy Create free account
hub / github.com/github/gh-aw / enrichGHError

Function enrichGHError

pkg/workflow/github_cli.go:101–113  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

99// This function appends that message to the error so callers see useful
100// diagnostics instead of a bare "exit status 1".
101func 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.

Callers 4

TestEnrichGHErrorFunction · 0.85
runGHWithSpinnerContextFunction · 0.85
RunGHWithHostFunction · 0.85
RunGHContextWithHostFunction · 0.85

Calls 1

ErrorfMethod · 0.45

Tested by 1

TestEnrichGHErrorFunction · 0.68