Use uber/multierr for error composition

This commit is contained in:
katexochen 2022-08-01 11:54:29 +02:00 committed by Paul Meyer
parent a859accf1f
commit f28e00659c
2 changed files with 4 additions and 40 deletions

View file

@ -7,7 +7,6 @@ import (
"errors"
"fmt"
"math/big"
"strings"
compute "cloud.google.com/go/compute/apiv1"
admin "cloud.google.com/go/iam/admin/apiv1"
@ -15,6 +14,7 @@ import (
"github.com/edgelesssys/constellation/internal/cloud/cloudprovider"
"github.com/edgelesssys/constellation/internal/cloud/cloudtypes"
"github.com/edgelesssys/constellation/internal/state"
"go.uber.org/multierr"
"golang.org/x/oauth2/google"
)
@ -461,25 +461,9 @@ func closeAll(closers []closer) error {
// close operations, even if a previous operation failed. The if multiple
// errors occur, the returned error will be composed of the error messages
// of those errors.
var errs []error
var err error
for _, closer := range closers {
errs = append(errs, closer.Close())
err = multierr.Append(err, closer.Close())
}
return composeErr(errs)
}
// composeErr composes a list of errors to a single error.
//
// If all errs are nil, the returned error is also nil.
func composeErr(errs []error) error {
var composed strings.Builder
for i, err := range errs {
if err != nil {
composed.WriteString(fmt.Sprintf("%d: %s", i, err.Error()))
}
}
if composed.Len() != 0 {
return errors.New(composed.String())
}
return nil
return err
}