diff --git a/pkg/executor/executor.go b/pkg/executor/executor.go index c43ea0a6..3c3967bb 100644 --- a/pkg/executor/executor.go +++ b/pkg/executor/executor.go @@ -32,6 +32,16 @@ func Run(cmd *exec.Cmd) error { return cmd.Run() } +// StderrError is returned by RunAndLogLines when a command fails and produces +// output on stderr. Callers can use errors.As to access the raw stderr content. +type StderrError struct { + Message string +} + +func (e *StderrError) Error() string { + return e.Message +} + type Executor struct { cmd *exec.Cmd logProxyHookJSON bool @@ -147,7 +157,7 @@ func (e *Executor) RunAndLogLines(ctx context.Context, logLabels map[string]stri err := e.cmd.Run() if err != nil { if len(stdErr.Bytes()) > 0 { - return nil, fmt.Errorf("stderr: %s", stdErr.String()) + return nil, &StderrError{Message: stdErr.String()} } return nil, fmt.Errorf("cmd run: %w", err)