Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace use of multierror libraries with now standardised errors.Join #3744

Merged
merged 1 commit into from
Apr 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions cmd/cli/serve/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package serve

import (
"context"
"errors"
"fmt"
"path/filepath"
"time"
Expand All @@ -11,11 +12,10 @@ import (
"github.com/bacalhau-project/bacalhau/pkg/jobstore"
boltjobstore "github.com/bacalhau-project/bacalhau/pkg/jobstore/boltdb"
"github.com/bacalhau-project/bacalhau/pkg/util/idgen"
"github.com/pkg/errors"
pkgerrors "github.com/pkg/errors"
"github.com/rs/zerolog/log"
"github.com/samber/lo"
"github.com/spf13/viper"
"go.uber.org/multierr"

"github.com/bacalhau-project/bacalhau/cmd/util/flags/configflags"
"github.com/bacalhau-project/bacalhau/pkg/orchestrator/transformer"
Expand All @@ -38,7 +38,7 @@ func GetComputeConfig(ctx context.Context, createExecutionStore bool) (node.Comp
queueResources, queueErr := cfg.Capacity.QueueResourceLimits.ToResources()
jobResources, jobErr := cfg.Capacity.JobResourceLimits.ToResources()
defaultResources, defaultErr := cfg.Capacity.DefaultJobResourceLimits.ToResources()
if err := multierr.Combine(totalErr, queueErr, jobErr, defaultErr); err != nil {
if err := errors.Join(totalErr, queueErr, jobErr, defaultErr); err != nil {
return node.ComputeConfig{}, err
}

Expand All @@ -48,7 +48,7 @@ func GetComputeConfig(ctx context.Context, createExecutionStore bool) (node.Comp
if createExecutionStore {
executionStore, err = getExecutionStore(ctx, cfg.ExecutionStore)
if err != nil {
return node.ComputeConfig{}, errors.Wrapf(err, "failed to create execution store")
return node.ComputeConfig{}, pkgerrors.Wrapf(err, "failed to create execution store")
}
}

Expand Down Expand Up @@ -88,7 +88,7 @@ func GetRequesterConfig(ctx context.Context, createJobStore bool) (node.Requeste
if createJobStore {
jobStore, err = getJobStore(ctx, cfg.JobStore)
if err != nil {
return node.RequesterConfig{}, errors.Wrapf(err, "failed to create job store")
return node.RequesterConfig{}, pkgerrors.Wrapf(err, "failed to create job store")
}
}
return node.NewRequesterConfigWith(node.RequesterConfigParams{
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ require (
github.com/google/uuid v1.5.0
github.com/gorilla/websocket v1.5.1
github.com/hashicorp/go-hclog v1.6.2
github.com/hashicorp/go-multierror v1.1.1
github.com/hashicorp/go-plugin v1.6.0
github.com/hashicorp/go-retryablehttp v0.7.5
github.com/imdario/mergo v0.3.16
Expand Down Expand Up @@ -81,7 +80,6 @@ require (
go.opentelemetry.io/otel/trace v1.23.1
go.ptx.dk/multierrgroup v0.0.3
go.uber.org/mock v0.4.0
go.uber.org/multierr v1.11.0
go.uber.org/zap v1.27.0
golang.org/x/crypto v0.21.0
golang.org/x/exp v0.0.0-20240213143201-ec583247a57a
Expand Down Expand Up @@ -136,6 +134,7 @@ require (
github.com/google/flatbuffers v2.0.8+incompatible // indirect
github.com/gopherjs/gopherjs v0.0.0-20190812055157-5d271430af9f // indirect
github.com/gorilla/mux v1.8.1 // indirect
github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/hashicorp/yamux v0.1.1 // indirect
github.com/ianlancetaylor/demangle v0.0.0-20230524184225-eabc099b10ab // indirect
github.com/ipfs-shipyard/nopfs v0.0.12 // indirect
Expand Down Expand Up @@ -192,6 +191,7 @@ require (
github.com/wk8/go-ordered-map/v2 v2.1.8 // indirect
github.com/xanzy/ssh-agent v0.3.3 // indirect
github.com/yashtewari/glob-intersection v0.2.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/mod v0.15.0 // indirect
gonum.org/v1/gonum v0.14.0 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20240108191215-35c7eff3a6b1 // indirect
Expand Down
3 changes: 1 addition & 2 deletions pkg/authz/policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (
"github.com/bacalhau-project/bacalhau/pkg/lib/policy"
"github.com/lestrrat-go/jwx/jwk"
"github.com/samber/lo"
"go.uber.org/multierr"
)

// The name of the rule that must be `true` for the authorization provider to
Expand Down Expand Up @@ -126,7 +125,7 @@ func (authorizer *policyAuthorizer) Authorize(req *http.Request) (Authorization,

approved, aErr := authorizer.allowQuery(req.Context(), in)
tokenValid, tvErr := authorizer.tokenValidQuery(req.Context(), in)
return Authorization{Approved: approved, TokenValid: tokenValid}, multierr.Append(aErr, tvErr)
return Authorization{Approved: approved, TokenValid: tokenValid}, errors.Join(aErr, tvErr)
}

// AlwaysAllowPolicy is a policy that will always permit access, irrespective of
Expand Down
7 changes: 3 additions & 4 deletions pkg/compute/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"os"
"path/filepath"

"github.com/hashicorp/go-multierror"
"github.com/rs/zerolog/log"

"github.com/bacalhau-project/bacalhau/pkg/models"
Expand Down Expand Up @@ -193,14 +192,14 @@ func PrepareRunArguments(
},
}, func(ctx context.Context) error {
log.Ctx(ctx).Info().Str("execution", execution.ID).Msg("cleaning up execution")
cleanupErr := new(multierror.Error)
var cleanupErr error
for _, cleanupFunc := range cleanupFuncs {
if err := cleanupFunc(ctx); err != nil {
log.Ctx(ctx).Error().Err(err).Str("execution", execution.ID).Msg("cleaning up execution")
cleanupErr = multierror.Append(cleanupErr, err)
cleanupErr = errors.Join(cleanupErr, err)
}
}
return cleanupErr.ErrorOrNil()
return cleanupErr
}, nil
}

Expand Down
10 changes: 5 additions & 5 deletions pkg/compute/startup.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ package compute

import (
"context"
"errors"

"github.com/bacalhau-project/bacalhau/pkg/compute/store"
"github.com/bacalhau-project/bacalhau/pkg/model"
"github.com/bacalhau-project/bacalhau/pkg/models"
"github.com/hashicorp/go-multierror"
"github.com/rs/zerolog/log"
)

Expand Down Expand Up @@ -48,7 +48,7 @@ func (s *Startup) ensureLiveJobs(ctx context.Context) error {
return err
}

errs := new(multierror.Error)
var errs error

for idx := range localExecStates {
localExecution := localExecStates[idx]
Expand All @@ -59,7 +59,7 @@ func (s *Startup) ensureLiveJobs(ctx context.Context) error {
// Service and System jobs are long running jobs and so we need to make sure it is running
err = s.runExecution(ctx, localExecution)
if err != nil {
errs = multierror.Append(errs, err)
errs = errors.Join(errs, err)
}
}
case model.JobTypeBatch, models.JobTypeOps:
Expand All @@ -68,13 +68,13 @@ func (s *Startup) ensureLiveJobs(ctx context.Context) error {
// side-effects (particularly for ops jobs).
err = s.failExecution(ctx, localExecution)
if err != nil {
errs = multierror.Append(errs, err)
errs = errors.Join(errs, err)
}
}
}
}

return errs.ErrorOrNil()
return errs
}

func (s *Startup) failExecution(ctx context.Context, execution store.LocalExecutionState) error {
Expand Down
6 changes: 3 additions & 3 deletions pkg/config/types/storagetype.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package types

import (
"errors"
"fmt"
"strings"

"go.uber.org/multierr"
"gopkg.in/yaml.v3"
)

Expand All @@ -16,11 +16,11 @@ type JobStoreConfig struct {
func (cfg JobStoreConfig) Validate() error {
var err error
if cfg.Type <= UnknownStorage || cfg.Type > BoltDB {
err = multierr.Append(err, fmt.Errorf("unknown execution store type: %q", cfg.Type.String()))
err = errors.Join(err, fmt.Errorf("unknown execution store type: %q", cfg.Type.String()))
}

if cfg.Path == "" {
err = multierr.Append(err, fmt.Errorf("execution store path is missing"))
err = errors.Join(err, fmt.Errorf("execution store path is missing"))
}

return err
Expand Down
12 changes: 6 additions & 6 deletions pkg/devstack/option.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package devstack

import (
"errors"
"fmt"
"time"

"github.com/hashicorp/go-multierror"
"github.com/rs/zerolog"

"github.com/bacalhau-project/bacalhau/pkg/node"
Expand Down Expand Up @@ -97,28 +97,28 @@ func (o *DevStackConfig) MarshalZerologObject(e *zerolog.Event) {
}

func (o *DevStackConfig) Validate() error {
errs := new(multierror.Error)
var errs error
totalNodeCount := o.NumberOfHybridNodes + o.NumberOfRequesterOnlyNodes + o.NumberOfComputeOnlyNodes

if totalNodeCount == 0 {
errs = multierror.Append(errs, fmt.Errorf("you cannot create a devstack with zero nodes"))
errs = errors.Join(errs, fmt.Errorf("you cannot create a devstack with zero nodes"))
}

totalComputeNodes := o.NumberOfComputeOnlyNodes + o.NumberOfHybridNodes
if o.NumberOfBadComputeActors > totalComputeNodes {
errs = multierror.Append(errs,
errs = errors.Join(errs,
fmt.Errorf("you cannot have more bad compute actors (%d) than there are nodes (%d)",
o.NumberOfBadComputeActors, totalComputeNodes))
}

totalRequesterNodes := o.NumberOfRequesterOnlyNodes + o.NumberOfHybridNodes
if o.NumberOfBadRequesterActors > totalRequesterNodes {
errs = multierror.Append(errs,
errs = errors.Join(errs,
fmt.Errorf("you cannot have more bad requester actors (%d) than there are nodes (%d)",
o.NumberOfBadRequesterActors, totalRequesterNodes))
}

return errs.ErrorOrNil()
return errs
}

func WithNodeOverrides(overrides ...node.NodeConfig) ConfigOption {
Expand Down
22 changes: 11 additions & 11 deletions pkg/docker/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"context"
"encoding/base64"
"encoding/json"
"errors"
"fmt"
"io"
"net"
Expand All @@ -22,11 +23,10 @@ import (
"github.com/docker/docker/pkg/stdcopy"
"github.com/opencontainers/go-digest"
v1 "github.com/opencontainers/image-spec/specs-go/v1"
"github.com/pkg/errors"
pkgerrors "github.com/pkg/errors"
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
"go.ptx.dk/multierrgroup"
"go.uber.org/multierr"
"golang.org/x/exp/slices"

"github.com/bacalhau-project/bacalhau/pkg/config"
Expand Down Expand Up @@ -111,7 +111,7 @@ func (c *Client) RemoveObjectsWithLabel(ctx context.Context, labelName, labelVal

containerErr := c.removeContainers(ctx, filterz)
networkErr := c.removeNetworks(ctx, filterz)
return multierr.Combine(containerErr, networkErr)
return errors.Join(containerErr, networkErr)
}

func (c *Client) FindContainer(ctx context.Context, label string, value string) (string, error) {
Expand All @@ -132,7 +132,7 @@ func (c *Client) FindContainer(ctx context.Context, label string, value string)
func (c *Client) FollowLogs(ctx context.Context, id string) (stdout, stderr io.Reader, err error) {
cont, err := c.ContainerInspect(ctx, id)
if err != nil {
return nil, nil, errors.Wrap(err, "failed to get container")
return nil, nil, pkgerrors.Wrap(err, "failed to get container")
}

logOptions := container.LogsOptions{
Expand All @@ -144,7 +144,7 @@ func (c *Client) FollowLogs(ctx context.Context, id string) (stdout, stderr io.R
ctx = log.Ctx(ctx).With().Str("ContainerID", cont.ID).Str("Image", cont.Image).Logger().WithContext(ctx)
logsReader, err := c.ContainerLogs(ctx, cont.ID, logOptions)
if err != nil {
return nil, nil, errors.Wrap(err, "failed to get container logs")
return nil, nil, pkgerrors.Wrap(err, "failed to get container logs")
}

stdoutReader, stdoutWriter := io.Pipe()
Expand All @@ -170,11 +170,11 @@ func (c *Client) FollowLogs(ctx context.Context, id string) (stdout, stderr io.R
func (c *Client) GetOutputStream(ctx context.Context, id string, since string, follow bool) (io.ReadCloser, error) {
cont, err := c.ContainerInspect(ctx, id)
if err != nil {
return nil, errors.Wrap(err, "failed to get container")
return nil, pkgerrors.Wrap(err, "failed to get container")
}

if !cont.State.Running {
return nil, errors.Wrap(err, "cannot get logs when container is not running")
return nil, pkgerrors.Wrap(err, "cannot get logs when container is not running")
}

logOptions := container.LogsOptions{
Expand All @@ -189,7 +189,7 @@ func (c *Client) GetOutputStream(ctx context.Context, id string, since string, f
ctx = log.Ctx(ctx).With().Str("ContainerID", cont.ID).Str("Image", cont.Image).Logger().WithContext(ctx)
logsReader, err := c.ContainerLogs(ctx, cont.ID, logOptions)
if err != nil {
return nil, errors.Wrap(err, "failed to get container logs")
return nil, pkgerrors.Wrap(err, "failed to get container logs")
}

return logsReader, nil
Expand All @@ -203,7 +203,7 @@ func (c *Client) RemoveContainer(ctx context.Context, id string) error {
Force: true,
})
if err != nil {
return errors.WithStack(err)
return pkgerrors.WithStack(err)
}
return nil
}
Expand All @@ -228,7 +228,7 @@ func (c *Client) ImagePlatforms(ctx context.Context, image string, dockerCreds c

distribution, err := c.DistributionInspect(ctx, image, authToken)
if err != nil {
return nil, errors.Wrapf(err, DistributionInspectError, image)
return nil, pkgerrors.Wrapf(err, DistributionInspectError, image)
}

return distribution.Platforms, nil
Expand Down Expand Up @@ -342,7 +342,7 @@ func (c *Client) ImageDistribution(
authToken := getAuthToken(ctx, image, creds)
dist, err := c.DistributionInspect(ctx, image, authToken)
if err != nil {
return nil, errors.Wrapf(err, DistributionInspectError, image)
return nil, pkgerrors.Wrapf(err, DistributionInspectError, image)
}

obj := dist.Descriptor.Digest
Expand Down
5 changes: 2 additions & 3 deletions pkg/executor/docker/bidstrategy/semantic/image_platform.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@ package semantic

import (
"context"
"errors"
"sync"

"go.uber.org/multierr"

dockermodels "github.com/bacalhau-project/bacalhau/pkg/executor/docker/models"
"github.com/bacalhau-project/bacalhau/pkg/models"

Expand Down Expand Up @@ -95,7 +94,7 @@ func (s *ImagePlatformBidStrategy) ShouldBid(
log.Ctx(ctx).Debug().Str("Image", dockerEngine.Image).Msg("Image found in manifest cache")
}

errs := multierr.Combine(serr, ierr)
errs := errors.Join(serr, ierr)
if errs != nil {
return bidstrategy.BidStrategyResponse{
ShouldBid: false,
Expand Down
Loading
Loading