Skip to content

Commit 0548e8c

Browse files
gregwebslysu
authored andcommitted
add an Errors utility helper (#8)
1 parent 9316aeb commit 0548e8c

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

group.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,15 @@ type ErrorGroup interface {
66
Errors() []error
77
}
88

9+
// Errors uses the ErrorGroup interface to return a slice of errors.
10+
// If the ErrorGroup interface is not implemented it returns an array containing just the given error.
11+
func Errors(err error) []error {
12+
if eg, ok := err.(ErrorGroup); ok {
13+
return eg.Errors()
14+
}
15+
return []error{err}
16+
}
17+
918
// WalkDeep does a depth-first traversal of all errors.
1019
// Any ErrorGroup is traversed (after going deep).
1120
// The visitor function can return true to end the traversal early

0 commit comments

Comments
 (0)