Skip to content

Commit

Permalink
Merge pull request #9 from runreveal/alan/command-errors
Browse files Browse the repository at this point in the history
command: surface errors to caller
  • Loading branch information
abraithwaite authored Jun 17, 2024
2 parents 2bd5e1c + a890fc3 commit 9f87e79
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 9f87e79

Please sign in to comment.