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

@@ -42,7 +42,6 @@ import (
pb "github.com/hashicorp/boundary/sdk/pbs/controller/api/resources/targets"
fm "github.com/hashicorp/boundary/version"
"github.com/hashicorp/go-bexpr"
"github.com/hashicorp/go-multierror"
"github.com/hashicorp/go-secure-stdlib/strutil"
"github.com/mr-tron/base58"
"google.golang.org/grpc/codes"
@@ -965,7 +964,7 @@ func (s Service) AuthorizeSession(ctx context.Context, req *pbs.AuthorizeSession
deleteCtx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
_, err := sessionRepo.DeleteSession(deleteCtx, sess.PublicId)
retErr = multierror.Append(retErr, err)
retErr = stderrors.Join(retErr, err)
}
}()
@@ -996,7 +995,7 @@ func (s Service) AuthorizeSession(ctx context.Context, req *pbs.AuthorizeSession
deleteCtx, cancel := context.WithTimeout(context.Background(), time.Minute)
defer cancel()
err := credRepo.Revoke(deleteCtx, sess.PublicId)
retErr = multierror.Append(retErr, err)
retErr = stderrors.Join(retErr, err)
// This leaves the credential in a state which will allow it to be cleaned up
// by the periodic credential cleanup job.
}
+10 -8
View File
@@ -6,6 +6,7 @@ package controller
import (
"context"
"crypto/tls"
stderrors "errors"
"fmt"
"math"
"net"
@@ -295,13 +296,14 @@ func (c *Controller) stopServersAndListeners() error {
mg.Go(c.stopApiGrpcServerAndListener)
stopErrors := mg.Wait()
convertedStopErrors := stopErrors.ErrorOrNil()
err := c.stopAnyListeners()
if err != nil {
stopErrors = multierror.Append(stopErrors, err)
convertedStopErrors = stderrors.Join(convertedStopErrors, err)
}
return stopErrors.ErrorOrNil()
return convertedStopErrors
}
func (c *Controller) stopClusterGrpcServerAndListener() error {
@@ -321,7 +323,7 @@ func (c *Controller) stopClusterGrpcServerAndListener() error {
}
func (c *Controller) stopHttpServersAndListeners() error {
var closeErrors *multierror.Error
var closeErrors error
for i := range c.apiListeners {
ln := c.apiListeners[i]
if ln.HTTPServer == nil {
@@ -335,11 +337,11 @@ func (c *Controller) stopHttpServersAndListeners() error {
err := ln.ApiListener.Close() // The HTTP Shutdown call should close this, but just in case.
err = listenerCloseErrorCheck(ln.Config.Type, err)
if err != nil {
multierror.Append(closeErrors, err)
closeErrors = stderrors.Join(closeErrors, err)
}
}
return closeErrors.ErrorOrNil()
return closeErrors
}
func (c *Controller) stopApiGrpcServerAndListener() error {
@@ -357,7 +359,7 @@ func (c *Controller) stopApiGrpcServerAndListener() error {
// listeners to make sure we didn't miss any;
// expected to run at the end of stopServersAndListeners.
func (c *Controller) stopAnyListeners() error {
var closeErrors *multierror.Error
var closeErrors error
for i := range c.apiListeners {
ln := c.apiListeners[i]
if ln == nil || ln.ApiListener == nil {
@@ -367,11 +369,11 @@ func (c *Controller) stopAnyListeners() error {
err := ln.ApiListener.Close()
err = listenerCloseErrorCheck(ln.Config.Type, err)
if err != nil {
multierror.Append(closeErrors, err)
closeErrors = stderrors.Join(closeErrors, err)
}
}
return closeErrors.ErrorOrNil()
return closeErrors
}
// listenerCloseErrorCheck does some validation on an error returned