diff --git a/go.mod b/go.mod index d96f7076e9f..788cac7d025 100644 --- a/go.mod +++ b/go.mod @@ -176,7 +176,7 @@ require ( github.com/grpc-ecosystem/go-grpc-prometheus v1.2.1-0.20191002090509-6af20e3a5340 // indirect github.com/hashicorp/errwrap v1.1.0 // indirect github.com/hashicorp/go-msgpack v0.5.5 // indirect - github.com/hashicorp/go-multierror v1.1.1 + github.com/hashicorp/go-multierror v1.1.1 // indirect github.com/hashicorp/go-sockaddr v1.0.2 // indirect github.com/hashicorp/golang-lru v0.6.0 // indirect github.com/hashicorp/yamux v0.1.1 // indirect diff --git a/pkg/services/authn/authnimpl/service.go b/pkg/services/authn/authnimpl/service.go index 13ea36b4dc3..387a1a11991 100644 --- a/pkg/services/authn/authnimpl/service.go +++ b/pkg/services/authn/authnimpl/service.go @@ -6,7 +6,6 @@ import ( "net/http" "strconv" - "github.com/hashicorp/go-multierror" "github.com/prometheus/client_golang/prometheus" "go.opentelemetry.io/otel/attribute" @@ -143,7 +142,7 @@ func ProvideService( connector, errConnector := socialService.GetConnector(name) httpClient, errHTTPClient := socialService.GetOAuthHttpClient(name) if errConnector != nil || errHTTPClient != nil { - s.log.Error("Failed to configure oauth client", "client", clientName, "err", multierror.Append(errConnector, errHTTPClient)) + s.log.Error("Failed to configure oauth client", "client", clientName, "err", errors.Join(errConnector, errHTTPClient)) } else { s.RegisterClient(clients.ProvideOAuth(clientName, cfg, oauthCfg, connector, httpClient)) } @@ -201,7 +200,7 @@ func (s *Service) Authenticate(ctx context.Context, r *authn.Request) (*authn.Id return nil, err } - authErr = multierror.Append(authErr, err) + authErr = errors.Join(authErr, err) // try next continue } diff --git a/pkg/services/authn/clients/password.go b/pkg/services/authn/clients/password.go index d5c90b80ffa..03e0ccaee88 100644 --- a/pkg/services/authn/clients/password.go +++ b/pkg/services/authn/clients/password.go @@ -4,8 +4,6 @@ import ( "context" "errors" - "github.com/hashicorp/go-multierror" - "github.com/grafana/grafana/pkg/infra/log" "github.com/grafana/grafana/pkg/services/authn" "github.com/grafana/grafana/pkg/services/loginattempt" @@ -50,7 +48,7 @@ func (c *Password) AuthenticatePassword(ctx context.Context, r *authn.Request, u var clientErrs error for _, pwClient := range c.clients { identity, clientErr := pwClient.AuthenticatePassword(ctx, r, username, password) - clientErrs = multierror.Append(clientErrs, clientErr) + clientErrs = errors.Join(clientErrs, clientErr) // we always try next client on any error if clientErr != nil { c.log.FromContext(ctx).Debug("Failed to authenticate password identity", "client", pwClient, "error", clientErr) diff --git a/pkg/services/ngalert/backtesting/engine.go b/pkg/services/ngalert/backtesting/engine.go index af2a9012bf0..e91c9845f60 100644 --- a/pkg/services/ngalert/backtesting/engine.go +++ b/pkg/services/ngalert/backtesting/engine.go @@ -10,7 +10,6 @@ import ( "github.com/benbjohnson/clock" "github.com/grafana/grafana-plugin-sdk-go/data" - "github.com/hashicorp/go-multierror" "github.com/grafana/grafana/pkg/infra/log" "github.com/grafana/grafana/pkg/services/ngalert/eval" @@ -72,7 +71,7 @@ func (e *Engine) Test(ctx context.Context, user *user.SignedInUser, rule *models evaluator, err := backtestingEvaluatorFactory(ruleCtx, e.evalFactory, user, rule.GetEvalCondition()) if err != nil { - return nil, multierror.Append(ErrInvalidInputData, err) + return nil, errors.Join(ErrInvalidInputData, err) } stateManager := e.createStateManager() diff --git a/pkg/services/ngalert/schedule/schedule.go b/pkg/services/ngalert/schedule/schedule.go index 69cbbd97128..6384261f0ac 100644 --- a/pkg/services/ngalert/schedule/schedule.go +++ b/pkg/services/ngalert/schedule/schedule.go @@ -8,7 +8,6 @@ import ( "time" "github.com/benbjohnson/clock" - "github.com/hashicorp/go-multierror" "go.opentelemetry.io/otel/attribute" "golang.org/x/sync/errgroup" @@ -399,7 +398,7 @@ func (sch *schedule) ruleRoutine(grafanaCtx context.Context, key ngmodels.AlertR if err == nil { for _, result := range results { if result.Error != nil { - err = multierror.Append(err, result.Error) + err = errors.Join(err, result.Error) } } } diff --git a/pkg/services/ngalert/state/cache.go b/pkg/services/ngalert/state/cache.go index e0b7a399551..bb4147b2ea3 100644 --- a/pkg/services/ngalert/state/cache.go +++ b/pkg/services/ngalert/state/cache.go @@ -2,6 +2,7 @@ package state import ( "context" + "errors" "math" "net/url" "strings" @@ -9,7 +10,6 @@ import ( "time" "github.com/grafana/grafana-plugin-sdk-go/data" - "github.com/hashicorp/go-multierror" "github.com/grafana/grafana/pkg/infra/log" "github.com/grafana/grafana/pkg/services/ngalert/eval" @@ -161,21 +161,21 @@ func calculateState(ctx context.Context, log log.Logger, alertRule *ngModels.Ale // template.ExpandError errors. func expand(ctx context.Context, log log.Logger, name string, original map[string]string, data template.Data, externalURL *url.URL, evaluatedAt time.Time) (map[string]string, error) { var ( - errs *multierror.Error + errs error expanded = make(map[string]string, len(original)) ) for k, v := range original { result, err := template.Expand(ctx, name, v, data, externalURL, evaluatedAt) if err != nil { log.Error("Error in expanding template", "error", err) - errs = multierror.Append(errs, err) + errs = errors.Join(errs, err) // keep the original template on error expanded[k] = v } else { expanded[k] = result } } - return expanded, errs.ErrorOrNil() + return expanded, errs } func (rs *ruleStates) deleteStates(predicate func(s *State) bool) []*State { diff --git a/pkg/services/ngalert/state/cache_test.go b/pkg/services/ngalert/state/cache_test.go index aa9384af36d..95e81513b38 100644 --- a/pkg/services/ngalert/state/cache_test.go +++ b/pkg/services/ngalert/state/cache_test.go @@ -9,7 +9,6 @@ import ( "time" "github.com/grafana/grafana-plugin-sdk-go/data" - "github.com/hashicorp/go-multierror" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -67,14 +66,15 @@ func Test_expand(t *testing.T) { require.NotNil(t, err) require.Equal(t, original, results) - // TODO: Please update this test in issue https://github.com/grafana/grafana/issues/63686 - var multierr *multierror.Error - require.True(t, errors.As(err, &multierr)) - require.Equal(t, multierr.Len(), 2) + //nolint:errorlint + multierr, is := err.(interface{ Unwrap() []error }) + require.True(t, is) + unwrappedErrors := multierr.Unwrap() + require.Equal(t, len(unwrappedErrors), 2) errsStr := []string{ - multierr.Errors[0].Error(), - multierr.Errors[1].Error(), + unwrappedErrors[0].Error(), + unwrappedErrors[1].Error(), } firstErrStr := "failed to expand template '{{- $labels := .Labels -}}{{- $values := .Values -}}{{- $value := .Value -}}Instance {{ $labels. }} has been down for more than 5 minutes': error parsing template __alert_test: template: __alert_test:1: unexpected <.> in operand" @@ -83,7 +83,7 @@ func Test_expand(t *testing.T) { require.Contains(t, errsStr, firstErrStr) require.Contains(t, errsStr, secondErrStr) - for _, err := range multierr.Errors { + for _, err := range unwrappedErrors { var expandErr template.ExpandError require.True(t, errors.As(err, &expandErr)) } @@ -103,10 +103,11 @@ func Test_expand(t *testing.T) { require.NotNil(t, err) require.Equal(t, expected, results) - // TODO: Please update this test in issue https://github.com/grafana/grafana/issues/63686 - var multierr *multierror.Error - require.True(t, errors.As(err, &multierr)) - require.Equal(t, multierr.Len(), 1) + //nolint:errorlint + multierr, is := err.(interface{ Unwrap() []error }) + require.True(t, is) + unwrappedErrors := multierr.Unwrap() + require.Equal(t, len(unwrappedErrors), 1) // assert each error matches the expected error var expandErr template.ExpandError diff --git a/pkg/util/contextutil.go b/pkg/util/contextutil.go index 16e3a01dd06..600a2b1c024 100644 --- a/pkg/util/contextutil.go +++ b/pkg/util/contextutil.go @@ -2,9 +2,8 @@ package util import ( "context" + "errors" "sync" - - "github.com/hashicorp/go-multierror" ) // this is a decorator for a regular context that contains a custom error and returns the @@ -18,7 +17,7 @@ func (c *contextWithCancellableReason) Err() error { c.mtx.Lock() defer c.mtx.Unlock() if c.err != nil { - return multierror.Append(c.Context.Err(), c.err) + return errors.Join(c.Context.Err(), c.err) } return c.Context.Err() }