File tree Expand file tree Collapse file tree 2 files changed +35
-0
lines changed Expand file tree Collapse file tree 2 files changed +35
-0
lines changed Original file line number Diff line number Diff line change 11package async
22
33import (
4+ "bytes"
45 "errors"
56 "fmt"
7+ "strings"
68)
79
810var (
@@ -45,3 +47,18 @@ func (e *executionError) Err() error {
4547func (e * executionError ) Error () string {
4648 return fmt .Sprintf ("function %d error: %s" , e .index , e .err )
4749}
50+
51+ // ExecutionErrors is an array of ExecutionError.
52+ type ExecutionErrors []ExecutionError
53+
54+ // Error combines and returns all of the execution errors' message.
55+ func (ee ExecutionErrors ) Error () string {
56+ buf := bytes .NewBufferString ("" )
57+
58+ for _ , e := range ee {
59+ buf .WriteString (e .Error ())
60+ buf .WriteByte ('\n' )
61+ }
62+
63+ return strings .TrimSpace (buf .String ())
64+ }
Original file line number Diff line number Diff line change @@ -20,3 +20,21 @@ func TestExecutionError(t *testing.T) {
2020 a .EqualNow (err .Index (), 0 )
2121 a .EqualNow (err .Err (), innerErr )
2222}
23+
24+ func TestExecutionErrors (t * testing.T ) {
25+ a := assert .New (t )
26+
27+ var ee ExecutionErrors = []ExecutionError {
28+ & executionError {
29+ index : 0 ,
30+ err : errors .New ("inner error 1" ),
31+ },
32+ & executionError {
33+ index : 1 ,
34+ err : errors .New ("inner error 2" ),
35+ },
36+ }
37+
38+ a .EqualNow (ee .Error (), `function 0 error: inner error 1
39+ function 1 error: inner error 2` )
40+ }
You can’t perform that action at this time.
0 commit comments