From a890fc30015a737dea9d18358a2a8cddebe5e7d0 Mon Sep 17 00:00:00 2001 From: Alan Braithwaite Date: Mon, 17 Jun 2024 10:26:27 -0700 Subject: [PATCH] command: surface errors to caller --- internal/sources/command/command.go | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/internal/sources/command/command.go b/internal/sources/command/command.go index ef1c850..0946da6 100644 --- a/internal/sources/command/command.go +++ b/internal/sources/command/command.go @@ -98,7 +98,8 @@ func (s *Command) recvLoop(ctx context.Context) error { slog.Error(fmt.Sprintf("Error getting stdout pipe: %s", err)) return err } - _, err = cmd.StderrPipe() + + stderr, err := cmd.StderrPipe() if err != nil { slog.Error(fmt.Sprintf("Error getting stderr pipe: %s", err)) return err @@ -110,6 +111,18 @@ func (s *Command) recvLoop(ctx context.Context) error { return err } + go func() { + errScan := bufio.NewScanner(stderr) + for errScan.Scan() { + ll := errScan.Text() + slog.Error(fmt.Sprintf("command: %s", ll)) + } + + if err := errScan.Err(); err != nil { + slog.Error(fmt.Sprintf("scanning err: %+v", err)) + } + }() + scanner := bufio.NewScanner(stdout) for scanner.Scan() { line := scanner.Bytes() @@ -134,7 +147,7 @@ func (s *Command) recvLoop(ctx context.Context) error { } if err := scanner.Err(); err != nil { - slog.Info(fmt.Sprintf("scanning err: %+v", err)) + slog.Error(fmt.Sprintf("scanning err: %+v", err)) return err } err = cmd.Wait()