mirror of
https://github.com/edgelesssys/constellation.git
synced 2025-07-20 22:08:53 -04:00
deps: replace multierr with native errors.Join
Signed-off-by: Paul Meyer <49727155+katexochen@users.noreply.github.com>
This commit is contained in:
parent
955316c661
commit
12c866bcb9
32 changed files with 173 additions and 159 deletions
|
@ -8,10 +8,9 @@ package cloudcmd
|
|||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
|
||||
"go.uber.org/multierr"
|
||||
)
|
||||
|
||||
// rollbacker does a rollback.
|
||||
|
@ -28,7 +27,7 @@ func rollbackOnError(ctx context.Context, w io.Writer, onErr *error, roll rollba
|
|||
fmt.Fprintf(w, "An error occurred: %s\n", *onErr)
|
||||
fmt.Fprintln(w, "Attempting to roll back.")
|
||||
if err := roll.rollback(ctx); err != nil {
|
||||
*onErr = multierr.Append(*onErr, fmt.Errorf("on rollback: %w", err)) // TODO: print the error, or return it?
|
||||
*onErr = errors.Join(*onErr, fmt.Errorf("on rollback: %w", err)) // TODO: print the error, or return it?
|
||||
return
|
||||
}
|
||||
fmt.Fprintln(w, "Rollback succeeded.")
|
||||
|
@ -40,9 +39,9 @@ type rollbackerTerraform struct {
|
|||
|
||||
func (r *rollbackerTerraform) rollback(ctx context.Context) error {
|
||||
var err error
|
||||
err = multierr.Append(err, r.client.Destroy(ctx))
|
||||
err = errors.Join(err, r.client.Destroy(ctx))
|
||||
if err == nil {
|
||||
err = multierr.Append(err, r.client.CleanUpWorkspace())
|
||||
err = errors.Join(err, r.client.CleanUpWorkspace())
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
@ -56,9 +55,9 @@ type rollbackerQEMU struct {
|
|||
func (r *rollbackerQEMU) rollback(ctx context.Context) error {
|
||||
var err error
|
||||
if r.createdWorkspace {
|
||||
err = multierr.Append(err, r.client.Destroy(ctx))
|
||||
err = errors.Join(err, r.client.Destroy(ctx))
|
||||
}
|
||||
err = multierr.Append(err, r.libvirt.Stop(ctx))
|
||||
err = errors.Join(err, r.libvirt.Stop(ctx))
|
||||
if err == nil {
|
||||
err = r.client.CleanUpWorkspace()
|
||||
}
|
||||
|
|
|
@ -24,7 +24,6 @@ import (
|
|||
"github.com/edgelesssys/constellation/v2/internal/cloud/cloudprovider"
|
||||
"github.com/edgelesssys/constellation/v2/internal/config"
|
||||
"github.com/spf13/cobra"
|
||||
"go.uber.org/multierr"
|
||||
)
|
||||
|
||||
// Validator validates Platform Configuration Registers (PCRs).
|
||||
|
@ -84,10 +83,7 @@ func (v *Validator) updatePCR(pcrIndex uint32, encoded string) error {
|
|||
hexErr := err
|
||||
decoded, err = base64.StdEncoding.DecodeString(encoded)
|
||||
if err != nil {
|
||||
return multierr.Append(
|
||||
fmt.Errorf("input [%s] is not hex encoded: %w", encoded, hexErr),
|
||||
fmt.Errorf("input [%s] is not base64 encoded: %w", encoded, err),
|
||||
)
|
||||
return fmt.Errorf("input [%s] could neither be hex decoded (%w) nor base64 decoded (%w)", encoded, hexErr, err)
|
||||
}
|
||||
}
|
||||
// new_pcr_value := hash(old_pcr_value || data_to_extend)
|
||||
|
|
|
@ -8,6 +8,7 @@ package cmd
|
|||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/url"
|
||||
|
@ -80,8 +81,12 @@ func (cfm *configFetchMeasurementsCmd) configFetchMeasurements(
|
|||
|
||||
cfm.log.Debugf("Loading configuration file from %q", flags.configPath)
|
||||
conf, err := config.New(fileHandler, flags.configPath, flags.force)
|
||||
var configValidationErr *config.ValidationError
|
||||
if errors.As(err, &configValidationErr) {
|
||||
cmd.PrintErrln(configValidationErr.LongMessage())
|
||||
}
|
||||
if err != nil {
|
||||
return config.DisplayValidationErrors(cmd.ErrOrStderr(), err)
|
||||
return err
|
||||
}
|
||||
|
||||
if !conf.IsReleaseImage() {
|
||||
|
|
|
@ -73,8 +73,12 @@ func (c *createCmd) create(cmd *cobra.Command, creator cloudCreator, fileHandler
|
|||
|
||||
c.log.Debugf("Loading configuration file from %q", flags.configPath)
|
||||
conf, err := config.New(fileHandler, flags.configPath, flags.force)
|
||||
var configValidationErr *config.ValidationError
|
||||
if errors.As(err, &configValidationErr) {
|
||||
cmd.PrintErrln(configValidationErr.LongMessage())
|
||||
}
|
||||
if err != nil {
|
||||
return config.DisplayValidationErrors(cmd.ErrOrStderr(), err)
|
||||
return err
|
||||
}
|
||||
|
||||
c.log.Debugf("Checking configuration for warnings")
|
||||
|
|
|
@ -104,8 +104,12 @@ func (i *initCmd) initialize(cmd *cobra.Command, newDialer func(validator *cloud
|
|||
i.log.Debugf("Using flags: %+v", flags)
|
||||
i.log.Debugf("Loading configuration file from %q", flags.configPath)
|
||||
conf, err := config.New(fileHandler, flags.configPath, flags.force)
|
||||
var configValidationErr *config.ValidationError
|
||||
if errors.As(err, &configValidationErr) {
|
||||
cmd.PrintErrln(configValidationErr.LongMessage())
|
||||
}
|
||||
if err != nil {
|
||||
return config.DisplayValidationErrors(cmd.ErrOrStderr(), err)
|
||||
return err
|
||||
}
|
||||
|
||||
i.log.Debugf("Checking cluster ID file")
|
||||
|
|
|
@ -17,7 +17,6 @@ import (
|
|||
"github.com/edgelesssys/constellation/v2/internal/file"
|
||||
"github.com/spf13/afero"
|
||||
"github.com/spf13/cobra"
|
||||
"go.uber.org/multierr"
|
||||
)
|
||||
|
||||
func newMiniDownCmd() *cobra.Command {
|
||||
|
@ -39,7 +38,7 @@ func runDown(cmd *cobra.Command, args []string) error {
|
|||
|
||||
err := runTerminate(cmd, args)
|
||||
if removeErr := os.Remove(constants.MasterSecretFilename); removeErr != nil && !os.IsNotExist(removeErr) {
|
||||
err = multierr.Append(err, removeErr)
|
||||
err = errors.Join(err, removeErr)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -187,8 +187,12 @@ func (m *miniUpCmd) prepareConfig(cmd *cobra.Command, fileHandler file.Handler)
|
|||
// check for existing config
|
||||
if configPath != "" {
|
||||
conf, err := config.New(fileHandler, configPath, force)
|
||||
var configValidationErr *config.ValidationError
|
||||
if errors.As(err, &configValidationErr) {
|
||||
cmd.PrintErrln(configValidationErr.LongMessage())
|
||||
}
|
||||
if err != nil {
|
||||
return nil, config.DisplayValidationErrors(cmd.ErrOrStderr(), err)
|
||||
return nil, err
|
||||
}
|
||||
if conf.GetProvider() != cloudprovider.QEMU {
|
||||
return nil, errors.New("invalid provider for MiniConstellation cluster")
|
||||
|
|
|
@ -8,6 +8,7 @@ package cmd
|
|||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"net"
|
||||
|
@ -80,9 +81,14 @@ func (r *recoverCmd) recover(
|
|||
|
||||
r.log.Debugf("Loading configuration file from %q", flags.configPath)
|
||||
conf, err := config.New(fileHandler, flags.configPath, flags.force)
|
||||
if err != nil {
|
||||
return config.DisplayValidationErrors(cmd.ErrOrStderr(), err)
|
||||
var configValidationErr *config.ValidationError
|
||||
if errors.As(err, &configValidationErr) {
|
||||
cmd.PrintErrln(configValidationErr.LongMessage())
|
||||
}
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
provider := conf.GetProvider()
|
||||
r.log.Debugf("Got provider %s", provider.String())
|
||||
if provider == cloudprovider.Azure {
|
||||
|
|
|
@ -13,7 +13,6 @@ import (
|
|||
|
||||
"github.com/spf13/afero"
|
||||
"github.com/spf13/cobra"
|
||||
"go.uber.org/multierr"
|
||||
|
||||
"github.com/edgelesssys/constellation/v2/cli/internal/cloudcmd"
|
||||
"github.com/edgelesssys/constellation/v2/internal/constants"
|
||||
|
@ -79,11 +78,11 @@ func terminate(cmd *cobra.Command, terminator cloudTerminator, fileHandler file.
|
|||
|
||||
var retErr error
|
||||
if err := fileHandler.Remove(constants.AdminConfFilename); err != nil && !errors.Is(err, fs.ErrNotExist) {
|
||||
retErr = multierr.Append(err, fmt.Errorf("failed to remove file: '%s', please remove it manually", constants.AdminConfFilename))
|
||||
retErr = errors.Join(err, fmt.Errorf("failed to remove file: '%s', please remove it manually", constants.AdminConfFilename))
|
||||
}
|
||||
|
||||
if err := fileHandler.Remove(constants.ClusterIDsFileName); err != nil && !errors.Is(err, fs.ErrNotExist) {
|
||||
retErr = multierr.Append(err, fmt.Errorf("failed to remove file: '%s', please remove it manually", constants.ClusterIDsFileName))
|
||||
retErr = errors.Join(err, fmt.Errorf("failed to remove file: '%s', please remove it manually", constants.ClusterIDsFileName))
|
||||
}
|
||||
|
||||
return retErr
|
||||
|
|
|
@ -74,8 +74,12 @@ func (u *upgradeApplyCmd) upgradeApply(cmd *cobra.Command, imageFetcher imageFet
|
|||
return fmt.Errorf("parsing flags: %w", err)
|
||||
}
|
||||
conf, err := config.New(fileHandler, flags.configPath, flags.force)
|
||||
var configValidationErr *config.ValidationError
|
||||
if errors.As(err, &configValidationErr) {
|
||||
cmd.PrintErrln(configValidationErr.LongMessage())
|
||||
}
|
||||
if err != nil {
|
||||
return config.DisplayValidationErrors(cmd.ErrOrStderr(), err)
|
||||
return err
|
||||
}
|
||||
|
||||
if err := u.handleServiceUpgrade(cmd, conf, flags); err != nil {
|
||||
|
|
|
@ -127,8 +127,12 @@ type upgradeCheckCmd struct {
|
|||
// upgradePlan plans an upgrade of a Constellation cluster.
|
||||
func (u *upgradeCheckCmd) upgradeCheck(cmd *cobra.Command, fileHandler file.Handler, flags upgradeCheckFlags) error {
|
||||
conf, err := config.New(fileHandler, flags.configPath, flags.force)
|
||||
var configValidationErr *config.ValidationError
|
||||
if errors.As(err, &configValidationErr) {
|
||||
cmd.PrintErrln(configValidationErr.LongMessage())
|
||||
}
|
||||
if err != nil {
|
||||
return config.DisplayValidationErrors(cmd.ErrOrStderr(), err)
|
||||
return err
|
||||
}
|
||||
u.log.Debugf("Read configuration from %q", flags.configPath)
|
||||
// get current image version of the cluster
|
||||
|
|
|
@ -76,8 +76,12 @@ func (v *verifyCmd) verify(cmd *cobra.Command, fileHandler file.Handler, verifyC
|
|||
|
||||
v.log.Debugf("Loading configuration file from %q", flags.configPath)
|
||||
conf, err := config.New(fileHandler, flags.configPath, flags.force)
|
||||
var configValidationErr *config.ValidationError
|
||||
if errors.As(err, &configValidationErr) {
|
||||
cmd.PrintErrln(configValidationErr.LongMessage())
|
||||
}
|
||||
if err != nil {
|
||||
return config.DisplayValidationErrors(cmd.ErrOrStderr(), err)
|
||||
return err
|
||||
}
|
||||
|
||||
provider := conf.GetProvider()
|
||||
|
|
|
@ -23,7 +23,6 @@ import (
|
|||
"github.com/spf13/afero"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
"go.uber.org/multierr"
|
||||
)
|
||||
|
||||
func TestPrepareCluster(t *testing.T) {
|
||||
|
@ -682,10 +681,13 @@ func TestCleanupWorkspace(t *testing.T) {
|
|||
"files are cleaned up": {
|
||||
provider: cloudprovider.QEMU,
|
||||
prepareFS: func(f file.Handler) error {
|
||||
var err error
|
||||
err = multierr.Append(err, f.Write("terraform.tfvars", someContent))
|
||||
err = multierr.Append(err, f.Write("terraform.tfstate", someContent))
|
||||
return multierr.Append(err, f.Write("terraform.tfstate.backup", someContent))
|
||||
if err := f.Write("terraform.tfvars", someContent); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := f.Write("terraform.tfstate", someContent); err != nil {
|
||||
return err
|
||||
}
|
||||
return f.Write("terraform.tfstate.backup", someContent)
|
||||
},
|
||||
},
|
||||
"no error if files do not exist": {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue