Skip to content

Commit

Permalink
command/run: handle errors returned from parallel.Manager (peak#351)
Browse files Browse the repository at this point in the history
Co-authored-by: İbrahim Güngör <[email protected]>

Updates peak#304
  • Loading branch information
sonmezonur committed Sep 24, 2021
1 parent 1e7234a commit d69bc37
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
10 changes: 5 additions & 5 deletions command/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"os"
"strings"

"github.com/hashicorp/go-multierror"
"github.com/kballard/go-shellquote"
"github.com/urfave/cli/v2"

Expand Down Expand Up @@ -63,12 +64,11 @@ func NewRunCommand() *cli.Command {
waiter := parallel.NewWaiter()

var errDoneCh = make(chan bool)
var merrorWaiter error
go func() {
defer close(errDoneCh)
for range waiter.Err() {
// app.ExitErrHandler is called after each command.Run
// invocation. Ignore the errors returned from parallel.Run,
// just drain the channel for synchronization.
for err := range waiter.Err() {
merrorWaiter = multierror.Append(merrorWaiter, err)
}
}()

Expand Down Expand Up @@ -130,7 +130,7 @@ func NewRunCommand() *cli.Command {
waiter.Wait()
<-errDoneCh

return scanner.Err()
return multierror.Append(merrorWaiter, scanner.Err()).ErrorOrNil()
},
}
}
Expand Down
2 changes: 1 addition & 1 deletion e2e/run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func TestRunFromStdinWithErrors(t *testing.T) {
cmd := s5cmd("run")
result := icmd.RunCmd(cmd, icmd.WithStdin(input))

result.Assert(t, icmd.Success)
result.Assert(t, icmd.Expected{ExitCode: 1})

assertLines(t, result.Stdout(), map[int]compareFunc{})

Expand Down

0 comments on commit d69bc37

Please sign in to comment.