Skip to content

Commit

Permalink
add an Errors utility helper (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
gregwebs authored and lysu committed Sep 11, 2018
1 parent 9316aeb commit 0548e8c
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions group.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,15 @@ type ErrorGroup interface {
Errors() []error
}

// Errors uses the ErrorGroup interface to return a slice of errors.
// If the ErrorGroup interface is not implemented it returns an array containing just the given error.
func Errors(err error) []error {
if eg, ok := err.(ErrorGroup); ok {
return eg.Errors()
}
return []error{err}
}

// WalkDeep does a depth-first traversal of all errors.
// Any ErrorGroup is traversed (after going deep).
// The visitor function can return true to end the traversal early
Expand Down

0 comments on commit 0548e8c

Please sign in to comment.