Skip to content

Commit 448ee96

Browse files
authored
Merge pull request #867 from flant/feature/stderr-custom-error-type
[chore] add typed error for executor
2 parents ed1506f + 99433e9 commit 448ee96

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

pkg/executor/executor.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,16 @@ func Run(cmd *exec.Cmd) error {
3232
return cmd.Run()
3333
}
3434

35+
// StderrError is returned by RunAndLogLines when a command fails and produces
36+
// output on stderr. Callers can use errors.As to access the raw stderr content.
37+
type StderrError struct {
38+
Message string
39+
}
40+
41+
func (e *StderrError) Error() string {
42+
return e.Message
43+
}
44+
3545
type Executor struct {
3646
cmd *exec.Cmd
3747
logProxyHookJSON bool
@@ -147,7 +157,7 @@ func (e *Executor) RunAndLogLines(ctx context.Context, logLabels map[string]stri
147157
err := e.cmd.Run()
148158
if err != nil {
149159
if len(stdErr.Bytes()) > 0 {
150-
return nil, fmt.Errorf("stderr: %s", stdErr.String())
160+
return nil, &StderrError{Message: stdErr.String()}
151161
}
152162

153163
return nil, fmt.Errorf("cmd run: %w", err)

0 commit comments

Comments
 (0)