Skip to content

Commit a7ff937

Browse files
committed
Add IsAborted query in results
1 parent 41e5a47 commit a7ff937

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

pipeline.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,13 @@ type (
1717
// Result is the object that is returned after each step and after running a pipeline.
1818
Result struct {
1919
// Err contains the step's returned error, nil otherwise.
20+
// In an aborted pipeline with ErrAbort it will still be nil.
2021
Err error
2122
// Name is an optional identifier for a result.
2223
// ActionFunc may set this property before returning to help a ResultHandler with further processing.
2324
Name string
25+
26+
aborted bool
2427
}
2528
// Step is an intermediary action and part of a Pipeline.
2629
Step struct {
@@ -144,7 +147,7 @@ func (p *Pipeline) doRun() Result {
144147
if err != nil {
145148
if errors.Is(err, ErrAbort) {
146149
// Abort pipeline without error
147-
return Result{}
150+
return Result{aborted: true}
148151
}
149152
if p.disableErrorWrapping {
150153
return Result{Err: err}

result.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import "errors"
66
var ErrAbort = errors.New("abort")
77

88
// IsSuccessful returns true if the contained error is nil.
9+
// Aborted pipelines (with ErrAbort) are still reported as success.
10+
// To query if a pipeline is aborted early, use IsAborted.
911
func (r Result) IsSuccessful() bool {
1012
return r.Err == nil
1113
}
@@ -14,3 +16,8 @@ func (r Result) IsSuccessful() bool {
1416
func (r Result) IsFailed() bool {
1517
return r.Err != nil
1618
}
19+
20+
// IsAborted returns true if the pipeline didn't stop with an error, but just aborted early with ErrAbort.
21+
func (r Result) IsAborted() bool {
22+
return r.aborted
23+
}

0 commit comments

Comments
 (0)