fix (events): convert multierror to stdlib error (#3743)

* fix (events): convert multierror to stdlib error

multierror errors will be converted to a stdlib error (because
multierror doesn't support json marshaling).

* refact (errors): convert from multierror to stdlib errors.Join(...)

* refact: convert from pkg/errors to stdlib error wrapping
This commit is contained in:
Jim authored and GitHub committed 2023-09-17 19:35:43 -04:00
1 parent 98f8383a2b
commit 0d19892e03
28 files changed
+142 -152

No files matched your search

+2 -2
View File
@@ -6,6 +6,7 @@ package base
import (
"bytes"
"context"
"errors"
"flag"
"fmt"
"io"
@@ -27,7 +28,6 @@ import (
"github.com/hashicorp/go-secure-stdlib/parseutil"
"github.com/hashicorp/go-secure-stdlib/pluginutil/v2"
"github.com/mitchellh/cli"
"github.com/pkg/errors"
"github.com/posener/complete"
)
@@ -246,7 +246,7 @@ func (c *Command) Client(opt ...Option) (*api.Client, error) {
if modifiedTLS {
// Setup TLS config
if err := c.client.SetTLSConfig(tlsConfig); err != nil {
return nil, errors.Wrap(err, "failed to setup TLS config")
return nil, fmt.Errorf("failed to setup TLS config: %w", err)
}
}
+6 -6
View File
@@ -6,6 +6,7 @@ package base
import (
"context"
"crypto/ed25519"
"errors"
"fmt"
"net"
"net/url"
@@ -24,7 +25,6 @@ import (
"github.com/hashicorp/boundary/internal/types/scope"
"github.com/hashicorp/boundary/testing/dbtest"
capoidc "github.com/hashicorp/cap/oidc"
"github.com/hashicorp/go-multierror"
"github.com/jimlambrt/gldap"
"github.com/jimlambrt/gldap/testdirectory"
)
@@ -75,7 +75,7 @@ func (b *Server) CreateDevDatabase(ctx context.Context, opt ...Option) error {
if err != nil {
err = fmt.Errorf("unable to initialize dev database with dialect %s: %w", dialect, err)
if c != nil {
err = multierror.Append(err, c())
err = errors.Join(err, c())
}
return err
}
@@ -87,7 +87,7 @@ func (b *Server) CreateDevDatabase(ctx context.Context, opt ...Option) error {
if _, err := schema.MigrateStore(ctx, schema.Dialect(dialect), b.DatabaseUrl); err != nil {
err = fmt.Errorf("error initializing store: %w", err)
if c != nil {
err = multierror.Append(err, c())
err = errors.Join(err, c())
}
return err
}
@@ -102,21 +102,21 @@ func (b *Server) CreateDevDatabase(ctx context.Context, opt ...Option) error {
if err := b.OpenAndSetServerDatabase(ctx, dialect); err != nil {
if c != nil {
err = multierror.Append(err, c())
err = errors.Join(err, c())
}
return err
}
if err := b.CreateGlobalKmsKeys(ctx); err != nil {
if c != nil {
err = multierror.Append(err, c())
err = errors.Join(err, c())
}
return err
}
if _, err := b.CreateInitialLoginRole(ctx); err != nil {
if c != nil {
err = multierror.Append(err, c())
err = errors.Join(err, c())
}
return err
}
+1 -1
View File
@@ -5,6 +5,7 @@ package base
import (
"encoding/json"
"errors"
"fmt"
"os"
"sort"
@@ -18,7 +19,6 @@ import (
"github.com/hashicorp/boundary/version"
"github.com/mitchellh/cli"
"github.com/mitchellh/go-wordwrap"
"github.com/pkg/errors"
)
// This is adapted from the code in the strings package for TrimSpace
+1 -1
View File
@@ -6,6 +6,7 @@ package base
import (
"encoding/base64"
"encoding/json"
"errors"
"fmt"
"os"
"runtime"
@@ -13,7 +14,6 @@ import (
"github.com/hashicorp/boundary/api/authtokens"
nkeyring "github.com/jefferai/keyring"
"github.com/pkg/errors"
zkeyring "github.com/zalando/go-keyring"
)
+3 -4
View File
@@ -38,7 +38,6 @@ import (
"github.com/hashicorp/go-hclog"
wrapping "github.com/hashicorp/go-kms-wrapping/v2"
"github.com/hashicorp/go-kms-wrapping/v2/extras/multi"
"github.com/hashicorp/go-multierror"
configutil "github.com/hashicorp/go-secure-stdlib/configutil/v2"
"github.com/hashicorp/go-secure-stdlib/gatedwriter"
"github.com/hashicorp/go-secure-stdlib/listenerutil"
@@ -722,13 +721,13 @@ func (b *Server) SetupKMSes(ctx context.Context, ui cli.Ui, config *config.Confi
}
func (b *Server) RunShutdownFuncs() error {
var mErr *multierror.Error
var mErr error
for _, f := range b.ShutdownFuncs {
if err := f(); err != nil {
mErr = multierror.Append(mErr, err)
mErr = errors.Join(mErr, err)
}
}
return mErr.ErrorOrNil()
return mErr
}
// OpenAndSetServerDatabase calls OpenDatabase and sets its result *db.DB to the Server's
+5 -6
View File
@@ -27,7 +27,6 @@ import (
"github.com/hashicorp/boundary/internal/event"
"github.com/hashicorp/boundary/internal/kms"
"github.com/hashicorp/go-hclog"
"github.com/hashicorp/go-multierror"
"github.com/hashicorp/go-secure-stdlib/mlock"
"github.com/hashicorp/go-secure-stdlib/parseutil"
"github.com/hashicorp/go-uuid"
@@ -807,19 +806,19 @@ func (c *Command) Reload(newConf *config.Config) error {
c.ReloadFuncsLock.RLock()
defer c.ReloadFuncsLock.RUnlock()
var reloadErrors *multierror.Error
var reloadErrors error
for _, relFunc := range c.ReloadFuncs["listeners"] {
if relFunc != nil {
if err := relFunc(); err != nil {
reloadErrors = multierror.Append(reloadErrors, fmt.Errorf("error encountered reloading listener: %w", err))
reloadErrors = stderrors.Join(reloadErrors, fmt.Errorf("error encountered reloading listener: %w", err))
}
}
}
err := c.reloadControllerDatabase(newConf)
if err != nil {
reloadErrors = multierror.Append(reloadErrors, fmt.Errorf("failed to reload controller database: %w", err))
reloadErrors = stderrors.Join(reloadErrors, fmt.Errorf("failed to reload controller database: %w", err))
}
if newConf != nil && c.worker != nil {
@@ -837,7 +836,7 @@ func (c *Command) Reload(newConf *config.Config) error {
return nil
}()
if workerReloadErr != nil {
reloadErrors = multierror.Append(reloadErrors, fmt.Errorf("error encountered reloading worker initial upstreams: %w", workerReloadErr))
reloadErrors = stderrors.Join(reloadErrors, fmt.Errorf("error encountered reloading worker initial upstreams: %w", workerReloadErr))
}
}
@@ -850,7 +849,7 @@ func (c *Command) Reload(newConf *config.Config) error {
}
}
return reloadErrors.ErrorOrNil()
return reloadErrors
}
func verifyKmsSetup(dbase *db.DB) error {
+5 -6
View File
@@ -7,6 +7,7 @@ package ops
import (
"context"
"errors"
"fmt"
"net"
"net/http"
@@ -18,10 +19,8 @@ import (
"github.com/hashicorp/boundary/internal/daemon/worker"
"github.com/hashicorp/go-cleanhttp"
"github.com/hashicorp/go-hclog"
"github.com/hashicorp/go-multierror"
"github.com/hashicorp/go-secure-stdlib/listenerutil"
"github.com/mitchellh/cli"
"github.com/pkg/errors"
"github.com/prometheus/client_golang/prometheus/promhttp"
)
@@ -89,7 +88,7 @@ func (s *Server) Start() {
func (s *Server) Shutdown() error {
const op = "ops.(Server).Shutdown"
var closeErrors *multierror.Error
var closeErrors error
for _, b := range s.bundles {
if b == nil || b.ln == nil || b.ln.Config == nil || b.ln.OpsListener == nil || b.ln.HTTPServer == nil {
return fmt.Errorf("%s: missing bundle, listener or its fields", op)
@@ -100,17 +99,17 @@ func (s *Server) Shutdown() error {
err := b.ln.HTTPServer.Shutdown(ctx)
if err != nil {
multierror.Append(closeErrors, fmt.Errorf("%s: failed to shutdown http server: %w", op, err))
errors.Join(closeErrors, fmt.Errorf("%s: failed to shutdown http server: %w", op, err))
}
err = b.ln.OpsListener.Close()
err = listenerCloseErrorCheck(b.ln.Config.Type, err)
if err != nil {
multierror.Append(closeErrors, fmt.Errorf("%s: failed to close listener mux: %w", op, err))
errors.Join(closeErrors, fmt.Errorf("%s: failed to close listener mux: %w", op, err))
}
}
return closeErrors.ErrorOrNil()
return closeErrors
}
// WaitIfHealthExists waits for a configurable period of time `d` if the health endpoint has been