mirror of
https://github.com/kemko/nomad.git
synced 2026-01-01 16:05:42 +03:00
allow FlattenMultierror to accept standard error
This commit is contained in:
@@ -528,7 +528,12 @@ func Merge[T comparable](a, b T) T {
|
||||
|
||||
// FlattenMultierror takes a multierror and unwraps it if there's only one error
|
||||
// in the output, otherwise returning the multierror or nil.
|
||||
func FlattenMultierror(mErr *multierror.Error) error {
|
||||
func FlattenMultierror(err error) error {
|
||||
mErr, ok := err.(*multierror.Error)
|
||||
if !ok {
|
||||
return err
|
||||
}
|
||||
// note: mErr is a pointer so we still need to nil-check even after the cast
|
||||
if mErr == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -488,11 +488,21 @@ func Test_SliceSetEq(t *testing.T) {
|
||||
|
||||
func TestFlattenMultiError(t *testing.T) {
|
||||
|
||||
err := FlattenMultierror(nil)
|
||||
must.Nil(t, err)
|
||||
|
||||
err0 := errors.New("oh no!")
|
||||
err = FlattenMultierror(err0)
|
||||
must.Eq(t, `oh no!`, err.Error())
|
||||
|
||||
var mErr0 *multierror.Error
|
||||
err = FlattenMultierror(mErr0)
|
||||
must.Nil(t, err)
|
||||
|
||||
mErr0 = multierror.Append(mErr0, func() error {
|
||||
return nil
|
||||
}())
|
||||
err := FlattenMultierror(mErr0)
|
||||
err = FlattenMultierror(mErr0)
|
||||
must.Nil(t, err)
|
||||
|
||||
var mErr1 *multierror.Error
|
||||
|
||||
Reference in New Issue
Block a user