Skip to content

Commit fb12329

Browse files
committed
feat: add ExecutionErrors.
1 parent 6f228c6 commit fb12329

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

error.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
package async
22

33
import (
4+
"bytes"
45
"errors"
56
"fmt"
7+
"strings"
68
)
79

810
var (
@@ -45,3 +47,18 @@ func (e *executionError) Err() error {
4547
func (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+
}

error_test.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff 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+
}

0 commit comments

Comments
 (0)