Skip to content

Commit

Permalink
Fix double task execution with quiet runner option (#132)
Browse files Browse the repository at this point in the history
When the `WithRunnerQuiet` option [1] of the `golang` runner [3] or
`WithQuiet` option [2] of the `gotool` runner [4] was set to `true`,
the task passed to their `Run` method [5] was running twice. This was
caused by a missing return statement when the execution finished with a
`error` of value `nil` [^1] [^2].

To fix this bug both code blocks are now returning early with `nil`
instead of keep going on in the code flow.

[1]: https://pkg.go.dev/github.com/svengreb/wand@v0.8.0/pkg/task/golang#WithRunnerQuiet
[2]: https://pkg.go.dev/github.com/svengreb/wand@v0.8.0/pkg/task/gotool#WithQuiet
[3]: https://pkg.go.dev/github.com/svengreb/wand@v0.8.0/pkg/task/golang#Runner
[4]: https://pkg.go.dev/github.com/svengreb/wand@v0.8.0/pkg/task/gotool#Runner
[5]: https://pkg.go.dev/github.com/svengreb/wand/pkg/task@v0.8.0#Runner.Run

[^1]: https://github.com/svengreb/wand/blob/v0.8.0/pkg/task/golang/golang.go#L43-L50
[^2]: https://github.com/svengreb/wand/blob/v0.8.0/pkg/task/gotool/gotool.go#L218-L225

GH-131
  • Loading branch information
svengreb committed Jul 9, 2023
1 parent 48c5316 commit 3fffd9e
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pkg/task/golang/golang.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,14 @@ func (r *Runner) Run(t task.Task) error {
Kind: task.ErrRun,
}
}
return nil
}
if err := sh.RunWithV(r.opts.Env, r.opts.Exec, tExec.BuildParams()...); err != nil {
return &task.ErrRunner{
Err: fmt.Errorf("run task %q: %w", t.Name(), err),
Kind: task.ErrRun,
}
}

return nil
}

Expand Down
1 change: 1 addition & 0 deletions pkg/task/gotool/gotool.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ func (r *Runner) Run(t task.Task) error {
Kind: task.ErrRun,
}
}
return nil
}
if err := sh.RunWithV(r.opts.Env, execPath, tGM.BuildParams()...); err != nil {
return &task.ErrRunner{
Expand Down

0 comments on commit 3fffd9e

Please sign in to comment.