File tree Expand file tree Collapse file tree 2 files changed +57
-1
lines changed Expand file tree Collapse file tree 2 files changed +57
-1
lines changed Original file line number Diff line number Diff line change 11package async
22
3- import "errors"
3+ import (
4+ "errors"
5+ "fmt"
6+ )
47
58var (
69 // ErrContextCanceled to indicate the context was canceled or timed out.
1114 // ErrNotFunction indicates the value is not a function.
1215 ErrNotFunction error = errors .New ("not function" )
1316)
17+
18+ type ExecutionError interface {
19+ // Index returns the function's index in the parameters list that the function had returned an
20+ // error or panicked.
21+ Index () int
22+ // Err returns the original error that was returned or panicked by the function.
23+ Err () error
24+ // Error returns the execution error message.
25+ Error () string
26+ }
27+
28+ type executionError struct {
29+ index int
30+ err error
31+ }
32+
33+ // Index returns the function's index in the parameters list that the function had returned an
34+ // error or panicked.
35+ func (e * executionError ) Index () int {
36+ return e .index
37+ }
38+
39+ // Err returns the original error that was returned or panicked by the function.
40+ func (e * executionError ) Err () error {
41+ return e .err
42+ }
43+
44+ // Error returns the execution error message.
45+ func (e * executionError ) Error () string {
46+ return fmt .Sprintf ("function %d error: %s" , e .index , e .err )
47+ }
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 TestExecutionError (t * testing.T ) {
11+ a := assert .New (t )
12+
13+ innerErr := errors .New ("inner error" )
14+ err := & executionError {
15+ index : 0 ,
16+ err : innerErr ,
17+ }
18+
19+ a .EqualNow (err .Error (), "function 0 error: inner error" )
20+ a .EqualNow (err .Index (), 0 )
21+ a .EqualNow (err .Err (), innerErr )
22+ }
You can’t perform that action at this time.
0 commit comments