Skip to content

Commit

Permalink
command: surface errors to caller
Browse files Browse the repository at this point in the history
  • Loading branch information
abraithwaite committed Jun 17, 2024
1 parent 2bd5e1c commit a890fc3
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions internal/sources/command/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()
Expand All @@ -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()
Expand Down

0 comments on commit a890fc3

Please sign in to comment.