Preserve capture failures when a run is canceled
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"path"
|
||||
"sort"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
@@ -401,7 +402,27 @@ func classifyLaneError(lane, sentinel int, err error) orderedRunError {
|
||||
|
||||
func selectRunError(parent context.Context, values []orderedRunError) error {
|
||||
if err := parent.Err(); err != nil {
|
||||
return err
|
||||
// Cancellation stays primary, but drained jobs can also have failed
|
||||
// required capture. Retain those scoped errors, not ordinary siblings.
|
||||
var captureFailures []orderedRunError
|
||||
for _, value := range values {
|
||||
var captured *contracts.CaptureError
|
||||
if errors.As(value.err, &captured) {
|
||||
captureFailures = append(captureFailures, value)
|
||||
}
|
||||
}
|
||||
if len(captureFailures) == 0 {
|
||||
return err
|
||||
}
|
||||
sort.SliceStable(captureFailures, func(i, j int) bool {
|
||||
left, right := captureFailures[i], captureFailures[j]
|
||||
return left.stage < right.stage || left.stage == right.stage && (left.lane < right.lane || left.lane == right.lane && left.chunk < right.chunk)
|
||||
})
|
||||
causes := []error{err}
|
||||
for _, failure := range captureFailures {
|
||||
causes = append(causes, failure.err)
|
||||
}
|
||||
return errors.Join(causes...)
|
||||
}
|
||||
if len(values) == 0 {
|
||||
return nil
|
||||
|
||||
Reference in New Issue
Block a user