File tree Expand file tree Collapse file tree 3 files changed +49
-0
lines changed Expand file tree Collapse file tree 3 files changed +49
-0
lines changed Original file line number Diff line number Diff line change @@ -59,6 +59,11 @@ func (e *executionError) Error() string {
59
59
return fmt .Sprintf ("function %d error: %s" , e .index , e .err .Error ())
60
60
}
61
61
62
+ // Unwrap returns the inner error.
63
+ func (e * executionError ) Unwrap () error {
64
+ return e .err
65
+ }
66
+
62
67
// ExecutionErrors is an array of ExecutionError.
63
68
type ExecutionErrors []ExecutionError
64
69
@@ -76,6 +81,15 @@ func (ee ExecutionErrors) Error() string {
76
81
return strings .TrimSpace (buf .String ())
77
82
}
78
83
84
+ // Unwrap returns the execution errors.
85
+ func (ee ExecutionErrors ) Unwrap () []error {
86
+ errs := make ([]error , 0 , len (ee ))
87
+ for _ , e := range ee {
88
+ errs = append (errs , e )
89
+ }
90
+ return errs
91
+ }
92
+
79
93
// convertErrorListToExecutionErrors converts an array of the errors to the ExecutionErrors, it
80
94
// will set the index as the execution error's index. If the error in the list is nil, it will skip
81
95
// it and not add the error to the ExecutionErrors.
Original file line number Diff line number Diff line change
1
+ package async
2
+
3
+ import (
4
+ "errors"
5
+ "testing"
6
+
7
+ "github.com/ghosind/go-assert"
8
+ )
9
+
10
+ func TestUnwrapExecutionsError (t * testing.T ) {
11
+ a := assert .New (t )
12
+
13
+ innerErr := errors .New ("expected error" )
14
+ err := & executionError {
15
+ err : innerErr ,
16
+ index : 0 ,
17
+ }
18
+
19
+ errs := ExecutionErrors {err }
20
+ a .TrueNow (errors .Is (errs , err ))
21
+ a .TrueNow (errors .Is (errs , innerErr ))
22
+ }
Original file line number Diff line number Diff line change @@ -62,3 +62,16 @@ func TestConvertErrorListToExecutionErrors(t *testing.T) {
62
62
`function 0 error: expected error 1
63
63
function 1 error: expected error 2` )
64
64
}
65
+
66
+ func TestUnwrapExecutionError (t * testing.T ) {
67
+ a := assert .New (t )
68
+
69
+ innerErr := errors .New ("expected error" )
70
+ err := & executionError {
71
+ err : innerErr ,
72
+ index : 0 ,
73
+ }
74
+
75
+ a .TrueNow (errors .Is (err , innerErr ))
76
+ a .NotTrueNow (errors .Is (err , errors .New ("unexpected error" )))
77
+ }
You can’t perform that action at this time.
0 commit comments