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

@@ -5,11 +5,11 @@ package session
import (
"context"
stderrors "errors"
"fmt"
"github.com/hashicorp/boundary/internal/errors"
"github.com/hashicorp/boundary/internal/event"
"github.com/hashicorp/go-multierror"
)
// StateReport is used to report on the state of a Session.
@@ -44,27 +44,27 @@ func WorkerStatusReport(ctx context.Context, repo *Repository, connRepo *Connect
}
}
merr := new(multierror.Error)
var merr error
err := connRepo.updateBytesUpBytesDown(ctx, reportedConnections...)
if err != nil {
merr = multierror.Append(merr, errors.New(ctx, errors.Internal, op, fmt.Sprintf("failed to update bytes up and down for worker reported connections: %v", err)))
merr = stderrors.Join(merr, errors.New(ctx, errors.Internal, op, fmt.Sprintf("failed to update bytes up and down for worker reported connections: %v", err)))
}
notActive, err := repo.CheckIfNotActive(ctx, reportedSessions)
if err != nil {
merr = multierror.Append(merr, errors.New(ctx, errors.Internal, op, fmt.Sprintf("Error checking session state for worker %s: %v", workerId, err)))
merr = stderrors.Join(merr, errors.New(ctx, errors.Internal, op, fmt.Sprintf("Error checking session state for worker %s: %v", workerId, err)))
}
closed, err := connRepo.closeOrphanedConnections(ctx, workerId, reportedConnectionIds)
if err != nil {
merr = multierror.Append(merr, errors.New(ctx, errors.Internal, op, fmt.Sprintf("Error closing orphaned connections for worker %s: %v", workerId, err)))
merr = stderrors.Join(merr, errors.New(ctx, errors.Internal, op, fmt.Sprintf("Error closing orphaned connections for worker %s: %v", workerId, err)))
}
if len(closed) > 0 {
event.WriteSysEvent(ctx, op, "marked unclaimed connections as closed", "controller_id", workerId, "count", len(closed))
}
if merr.ErrorOrNil() != nil {
return nil, merr.ErrorOrNil()
if merr != nil {
return nil, merr
}
return notActive, nil
}