From 7dc49f02b789a291021448b27e9abbadd331624b Mon Sep 17 00:00:00 2001 From: Artem Kuleshov Date: Mon, 13 Apr 2026 14:04:27 +0300 Subject: [PATCH 1/2] [shell-operator] add StderrError type for typed stderr error handling --- pkg/executor/executor.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/pkg/executor/executor.go b/pkg/executor/executor.go index c43ea0a6..88ff2749 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 { + Stderr string +} + +func (e *StderrError) Error() string { + return fmt.Sprintf("stderr: %s", e.Stderr) +} + 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{Stderr: stdErr.String()} } return nil, fmt.Errorf("cmd run: %w", err) From 99433e958cddd43f14c006e3fb9d0c5504343fef Mon Sep 17 00:00:00 2001 From: Artem Kuleshov Date: Tue, 14 Apr 2026 14:49:14 +0300 Subject: [PATCH 2/2] [shell-operator] add StderrError type for typed stderr error handling --- pkg/executor/executor.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pkg/executor/executor.go b/pkg/executor/executor.go index 88ff2749..3c3967bb 100644 --- a/pkg/executor/executor.go +++ b/pkg/executor/executor.go @@ -35,11 +35,11 @@ func Run(cmd *exec.Cmd) error { // 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 { - Stderr string + Message string } func (e *StderrError) Error() string { - return fmt.Sprintf("stderr: %s", e.Stderr) + return e.Message } type Executor struct { @@ -157,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, &StderrError{Stderr: stdErr.String()} + return nil, &StderrError{Message: stdErr.String()} } return nil, fmt.Errorf("cmd run: %w", err)