Skip to content

Commit 5677b0d

Browse files
committed
Pipeline: prefer to report non-pipe errors to the caller
If a later stage of the pipeline fails, it is often the case that earlier stages fail with some sort of pipe-related error (because their `stdout` pipe gets closed). Those pipe errors are usually not very helpful in figuring out the underlying problem. So if there are any non-pipe errors, report the earliest one of those. If there are only pipe errors, report the latest one of those.
1 parent 1458ae5 commit 5677b0d

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

internal/pipe/pipeline.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -185,12 +185,17 @@ func (p *Pipeline) Wait() error {
185185
for i := len(p.stages) - 1; i >= 0; i-- {
186186
s := p.stages[i]
187187
err := s.Wait()
188-
if err != nil {
188+
189+
// We want to report the error that is most informative. We
190+
// take that to be the error from the earliest pipeline stage
191+
// that failed of a non-pipe error. If that didn't happen,
192+
// take the error from the last pipeline stage that failed due
193+
// to a pipe error.
194+
if err != nil && (earliestStageErr == nil || !IsPipeError(err)) {
189195
// Overwrite any existing values here so that we end up
190196
// retaining the last error that we see; i.e., the error
191197
// that happened earliest in the pipeline.
192-
earliestStageErr = err
193-
earliestFailedStage = s
198+
earliestFailedStage, earliestStageErr = s, err
194199
}
195200
}
196201

0 commit comments

Comments
 (0)