-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
97 additions
and
10 deletions.
There are no files selected for viewing
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
//go:build go1.20 | ||
// +build go1.20 | ||
|
||
package multierror | ||
|
||
// Split returns the underlying list of errors wrapped in a multierror. | ||
// | ||
// A multierror is an error tha implements Unwrap() []error (see https://pkg.go.dev/errors) | ||
// Errors produced by multierror.Join implement Unwrap() []error. | ||
func Split(err error) []error { | ||
u, ok := err.(interface { | ||
Unwrap() []error | ||
}) | ||
if !ok { | ||
return []error{err} | ||
} | ||
return u.Unwrap() | ||
} | ||
|
||
func (e *Error) Unwrap() []error { | ||
return e.errs | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package multierror_test | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
|
||
"github.com/mkmik/multierror" | ||
) | ||
|
||
// multierror.Split works also with multierrors produced by the new stdlib errors.Join | ||
func ExampleErrorsSplit() { | ||
err := errors.Join(fmt.Errorf("foo"), fmt.Errorf("bar"), fmt.Errorf("baz")) | ||
Check failure on line 12 in after_go120_test.go
|
||
|
||
fmt.Printf("%q", multierror.Split(err)) | ||
// Output: | ||
// ["foo" "bar" "baz"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
//go:build !go1.20 | ||
// +build !go1.20 | ||
|
||
package multierror | ||
|
||
// Split returns the underlying list of errors wrapped in a multierror. | ||
// If err is not a multierror, then a singleton list is returned. | ||
func Split(err error) []error { | ||
if me, ok := err.(*Error); ok { | ||
return me.errs | ||
} else { | ||
return []error{err} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.