diff --git a/cmd/neofs-cli/modules/container.go b/cmd/neofs-cli/modules/container.go index 7e5d36861..8b2f50d7f 100644 --- a/cmd/neofs-cli/modules/container.go +++ b/cmd/neofs-cli/modules/container.go @@ -4,6 +4,7 @@ import ( "bytes" "context" "encoding/json" + "errors" "fmt" "io/ioutil" "math" @@ -22,7 +23,6 @@ import ( "github.com/nspcc-dev/neofs-api-go/pkg/object" "github.com/nspcc-dev/neofs-api-go/pkg/owner" "github.com/nspcc-dev/neofs-node/pkg/policy" - "github.com/pkg/errors" "github.com/spf13/cobra" ) @@ -307,7 +307,7 @@ var getContainerInfoCmd = &cobra.Command{ cnr = container.New() if err := cnr.Unmarshal(data); err != nil { - return errors.Wrap(err, "can't unmarshal container") + return fmt.Errorf("can't unmarshal container: %w", err) } } else { key, err := getKey() diff --git a/cmd/neofs-cli/modules/control.go b/cmd/neofs-cli/modules/control.go index 3cf204cf7..53907c547 100644 --- a/cmd/neofs-cli/modules/control.go +++ b/cmd/neofs-cli/modules/control.go @@ -7,7 +7,6 @@ import ( "github.com/nspcc-dev/neofs-api-go/util/signature" "github.com/nspcc-dev/neofs-node/pkg/services/control" controlSvc "github.com/nspcc-dev/neofs-node/pkg/services/control/server" - "github.com/pkg/errors" "github.com/spf13/cobra" ) @@ -112,7 +111,7 @@ func setNetmapStatus(cmd *cobra.Command, _ []string) error { switch netmapStatus { default: - return errors.Errorf("unsupported status %s", netmapStatus) + return fmt.Errorf("unsupported status %s", netmapStatus) case netmapStatusOnline: status = control.NetmapStatus_ONLINE case netmapStatusOffline: @@ -174,12 +173,12 @@ var dropObjectsCmd = &cobra.Command{ err := a.Parse(dropObjectsList[i]) if err != nil { - return errors.Wrapf(err, "could not parse address #%d", i) + return fmt.Errorf("could not parse address #%d: %w", i, err) } binAddr, err := a.Marshal() if err != nil { - return errors.Wrap(err, "could not marshal the address") + return fmt.Errorf("could not marshal the address: %w", err) } binAddrList = append(binAddrList, binAddr) diff --git a/cmd/neofs-cli/modules/storagegroup.go b/cmd/neofs-cli/modules/storagegroup.go index f0820d292..676611aa3 100644 --- a/cmd/neofs-cli/modules/storagegroup.go +++ b/cmd/neofs-cli/modules/storagegroup.go @@ -2,6 +2,7 @@ package cmd import ( "context" + "errors" "fmt" "github.com/nspcc-dev/neofs-api-go/pkg/client" @@ -10,7 +11,6 @@ import ( "github.com/nspcc-dev/neofs-api-go/pkg/token" "github.com/nspcc-dev/neofs-node/pkg/core/object" "github.com/nspcc-dev/neofs-node/pkg/services/object_manager/storagegroup" - "github.com/pkg/errors" "github.com/spf13/cobra" ) diff --git a/cmd/neofs-node/attributes.go b/cmd/neofs-node/attributes.go index dcecea7ca..4b87a93fa 100644 --- a/cmd/neofs-node/attributes.go +++ b/cmd/neofs-node/attributes.go @@ -1,11 +1,11 @@ package main import ( + "fmt" "strconv" "github.com/nspcc-dev/neofs-api-go/pkg/netmap" "github.com/nspcc-dev/neofs-node/pkg/util/attributes" - "github.com/pkg/errors" "github.com/spf13/viper" ) @@ -65,7 +65,7 @@ func addWellKnownAttributes(attrs []*netmap.NodeAttribute) []*netmap.NodeAttribu for key, desc := range mWellKnown { // check if required attribute is set if desc.explicit { - fatalOnErr(errors.Errorf("missing explicit value of required node attribute %s", key)) + fatalOnErr(fmt.Errorf("missing explicit value of required node attribute %s", key)) } // set default value of the attribute diff --git a/cmd/neofs-node/config.go b/cmd/neofs-node/config.go index 6aa47df7a..6ceb5ff12 100644 --- a/cmd/neofs-node/config.go +++ b/cmd/neofs-node/config.go @@ -3,6 +3,7 @@ package main import ( "context" "crypto/ecdsa" + "errors" "net" "os" "path" @@ -40,7 +41,6 @@ import ( util2 "github.com/nspcc-dev/neofs-node/pkg/util" "github.com/nspcc-dev/neofs-node/pkg/util/logger" "github.com/panjf2000/ants/v2" - "github.com/pkg/errors" "github.com/spf13/viper" "go.etcd.io/bbolt" "go.uber.org/atomic" diff --git a/cmd/neofs-node/container.go b/cmd/neofs-node/container.go index fb0578a03..564ff9452 100644 --- a/cmd/neofs-node/container.go +++ b/cmd/neofs-node/container.go @@ -4,6 +4,8 @@ import ( "bytes" "context" "crypto/ecdsa" + "errors" + "fmt" "strconv" apiClient "github.com/nspcc-dev/neofs-api-go/pkg/client" @@ -30,7 +32,6 @@ import ( loadstorage "github.com/nspcc-dev/neofs-node/pkg/services/container/announcement/load/storage" containerMorph "github.com/nspcc-dev/neofs-node/pkg/services/container/morph" "github.com/nspcc-dev/neofs-node/pkg/util/logger" - "github.com/pkg/errors" "go.uber.org/zap" ) @@ -230,12 +231,12 @@ func (r *remoteLoadAnnounceProvider) InitRemote(srv loadroute.ServerInfo) (loadc hostAddr, err := network.HostAddrFromMultiaddr(addr) if err != nil { - return nil, errors.Wrap(err, "could not convert address to IP format") + return nil, fmt.Errorf("could not convert address to IP format: %w", err) } c, err := r.clientCache.Get(hostAddr) if err != nil { - return nil, errors.Wrap(err, "could not initialize API client") + return nil, fmt.Errorf("could not initialize API client: %w", err) } return &remoteLoadAnnounceWriterProvider{ @@ -298,7 +299,7 @@ func (l *loadPlacementBuilder) BuildPlacement(epoch uint64, cid *containerSDK.ID placement, err := nm.GetPlacementVectors(cnrNodes, pivot) if err != nil { - return nil, errors.Wrap(err, "could not build placement vectors") + return nil, fmt.Errorf("could not build placement vectors: %w", err) } return placement, nil @@ -312,12 +313,12 @@ func (l *loadPlacementBuilder) buildPlacement(epoch uint64, cid *containerSDK.ID nm, err := l.nmSrc.GetNetMapByEpoch(epoch) if err != nil { - return nil, nil, errors.Wrap(err, "could not get network map") + return nil, nil, fmt.Errorf("could not get network map: %w", err) } cnrNodes, err := nm.GetContainerNodes(cnr.PlacementPolicy(), cid.ToV2().GetValue()) if err != nil { - return nil, nil, errors.Wrap(err, "could not build container nodes") + return nil, nil, fmt.Errorf("could not build container nodes: %w", err) } return cnrNodes, nm, nil @@ -407,7 +408,7 @@ func (c *usedSpaceService) AnnounceUsedSpace(ctx context.Context, req *container w, err := c.loadWriterProvider.InitWriter(loadroute.NewRouteContext(ctx, passedRoute)) if err != nil { - return nil, errors.Wrap(err, "could not initialize container's used space writer") + return nil, fmt.Errorf("could not initialize container's used space writer: %w", err) } for _, aV2 := range req.GetBody().GetAnnouncements() { @@ -459,19 +460,19 @@ func (c *usedSpaceService) processLoadValue(ctx context.Context, a containerSDK. route []loadroute.ServerInfo, w loadcontroller.Writer) error { fromCnr, err := c.loadPlacementBuilder.isNodeFromContainerKey(a.Epoch(), a.ContainerID(), route[0].PublicKey()) if err != nil { - return errors.Wrap(err, "could not verify that the sender belongs to the container") + return fmt.Errorf("could not verify that the sender belongs to the container: %w", err) } else if !fromCnr { return errNodeOutsideContainer } err = loadroute.CheckRoute(c.routeBuilder, a, route) if err != nil { - return errors.Wrap(err, "wrong route of container's used space value") + return fmt.Errorf("wrong route of container's used space value: %w", err) } err = w.Put(a) if err != nil { - return errors.Wrap(err, "could not write container's used space value") + return fmt.Errorf("could not write container's used space value: %w", err) } return nil diff --git a/cmd/neofs-node/control.go b/cmd/neofs-node/control.go index 915c09f32..194418aaf 100644 --- a/cmd/neofs-node/control.go +++ b/cmd/neofs-node/control.go @@ -3,6 +3,7 @@ package main import ( "context" "encoding/hex" + "fmt" "net" "github.com/nspcc-dev/neofs-api-go/pkg/object" @@ -10,7 +11,6 @@ import ( "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/engine" "github.com/nspcc-dev/neofs-node/pkg/services/control" controlSvc "github.com/nspcc-dev/neofs-node/pkg/services/control/server" - "github.com/pkg/errors" "google.golang.org/grpc" ) @@ -34,7 +34,7 @@ func initControlService(c *cfg) { fatalOnErr(err) if crypto.UnmarshalPublicKey(key) == nil { - fatalOnErr(errors.Errorf("invalid permitted key for Control service %s", strKeys[i])) + fatalOnErr(fmt.Errorf("invalid permitted key for Control service %s", strKeys[i])) } keys = append(keys, key) diff --git a/cmd/neofs-node/netmap.go b/cmd/neofs-node/netmap.go index ba8a98d76..0efbfb817 100644 --- a/cmd/neofs-node/netmap.go +++ b/cmd/neofs-node/netmap.go @@ -2,6 +2,7 @@ package main import ( "bytes" + "fmt" netmapSDK "github.com/nspcc-dev/neofs-api-go/pkg/netmap" netmapV2 "github.com/nspcc-dev/neofs-api-go/v2/netmap" @@ -13,7 +14,6 @@ import ( netmapTransportGRPC "github.com/nspcc-dev/neofs-node/pkg/network/transport/netmap/grpc" "github.com/nspcc-dev/neofs-node/pkg/services/control" netmapService "github.com/nspcc-dev/neofs-node/pkg/services/netmap" - "github.com/pkg/errors" "go.uber.org/atomic" "go.uber.org/zap" ) @@ -111,7 +111,7 @@ func bootstrapNode(c *cfg) { initState(c) err := c.cfgNetmap.wrapper.AddPeer(c.toOnlineLocalNodeInfo()) - fatalOnErr(errors.Wrap(err, "bootstrap error")) + fatalOnErr(fmt.Errorf("bootstrap error: %w", err)) } func addNetmapNotificationHandler(c *cfg, sTyp string, h event.Handler) { @@ -136,10 +136,10 @@ func setNetmapNotificationParser(c *cfg, sTyp string, p event.Parser) { func initState(c *cfg) { epoch, err := c.cfgNetmap.wrapper.Epoch() - fatalOnErr(errors.Wrap(err, "could not initialize current epoch number")) + fatalOnErr(fmt.Errorf("could not initialize current epoch number: %w", err)) ni, err := c.netmapLocalNodeState(epoch) - fatalOnErr(errors.Wrap(err, "could not init network state")) + fatalOnErr(fmt.Errorf("could not init network state: %w", err)) c.handleNodeInfoStatus(ni) diff --git a/cmd/neofs-node/object.go b/cmd/neofs-node/object.go index 26c425d19..449c41b8a 100644 --- a/cmd/neofs-node/object.go +++ b/cmd/neofs-node/object.go @@ -3,6 +3,7 @@ package main import ( "context" "crypto/sha256" + "fmt" eaclSDK "github.com/nspcc-dev/neofs-api-go/pkg/acl/eacl" "github.com/nspcc-dev/neofs-api-go/pkg/client" @@ -40,7 +41,6 @@ import ( "github.com/nspcc-dev/neofs-node/pkg/services/reputation" truststorage "github.com/nspcc-dev/neofs-node/pkg/services/reputation/local/storage" "github.com/nspcc-dev/neofs-node/pkg/util/logger" - "github.com/pkg/errors" "go.uber.org/zap" ) @@ -131,7 +131,7 @@ type innerRingFetcher struct { func (n *innerRingFetcher) InnerRingKeys() ([][]byte, error) { keys, err := n.sidechain.NeoFSAlphabetList() if err != nil { - return nil, errors.Wrap(err, "can't get inner ring keys") + return nil, fmt.Errorf("can't get inner ring keys: %w", err) } result := make([][]byte, 0, len(keys)) @@ -383,7 +383,7 @@ func (s *morphEACLStorage) GetEACL(cid *container.ID) (*eaclSDK.Table, error) { }, signature.SignWithRFC6979(), ); err != nil { - return nil, errors.Wrap(err, "incorrect signature") + return nil, fmt.Errorf("incorrect signature: %w", err) } return table, nil diff --git a/cmd/neofs-node/reputation.go b/cmd/neofs-node/reputation.go index 4119802c5..a8f80bc3e 100644 --- a/cmd/neofs-node/reputation.go +++ b/cmd/neofs-node/reputation.go @@ -2,6 +2,7 @@ package main import ( "context" + "fmt" "github.com/nspcc-dev/neo-go/pkg/encoding/fixedn" v2reputation "github.com/nspcc-dev/neofs-api-go/v2/reputation" @@ -33,7 +34,6 @@ import ( truststorage "github.com/nspcc-dev/neofs-node/pkg/services/reputation/local/storage" reputationrpc "github.com/nspcc-dev/neofs-node/pkg/services/reputation/rpc" "github.com/nspcc-dev/neofs-node/pkg/util/logger" - "github.com/pkg/errors" "go.uber.org/zap" ) @@ -272,13 +272,13 @@ func (s *reputationServer) AnnounceLocalTrust(ctx context.Context, req *v2reputa w, err := s.localRouter.InitWriter(reputationrouter.NewRouteContext(eCtx, passedRoute)) if err != nil { - return nil, errors.Wrap(err, "could not initialize local trust writer") + return nil, fmt.Errorf("could not initialize local trust writer: %w", err) } for _, trust := range body.GetTrusts() { err = s.processLocalTrust(body.GetEpoch(), apiToLocalTrust(trust, passedRoute[0].PublicKey()), passedRoute, w) if err != nil { - return nil, errors.Wrap(err, "could not write one of local trusts") + return nil, fmt.Errorf("could not write one of local trusts: %w", err) } } @@ -298,7 +298,7 @@ func (s *reputationServer) AnnounceIntermediateResult(ctx context.Context, req * w, err := s.intermediateRouter.InitWriter(reputationrouter.NewRouteContext(eiCtx, passedRoute)) if err != nil { - return nil, errors.Wrap(err, "could not initialize intermediate trust writer") + return nil, fmt.Errorf("could not initialize intermediate trust writer: %w", err) } v2Trust := body.GetTrust() @@ -307,7 +307,7 @@ func (s *reputationServer) AnnounceIntermediateResult(ctx context.Context, req * err = w.Write(trust) if err != nil { - return nil, errors.Wrap(err, "could not write intermediate trust") + return nil, fmt.Errorf("could not write intermediate trust: %w", err) } resp := new(v2reputation.AnnounceIntermediateResultResponse) @@ -320,7 +320,7 @@ func (s *reputationServer) processLocalTrust(epoch uint64, t reputation.Trust, passedRoute []reputationcommon.ServerInfo, w reputationcommon.Writer) error { err := reputationrouter.CheckRoute(s.routeBuilder, epoch, t, passedRoute) if err != nil { - return errors.Wrap(err, "wrong route of reputation trust value") + return fmt.Errorf("wrong route of reputation trust value: %w", err) } return w.Write(t) diff --git a/cmd/neofs-node/reputation/common/remote.go b/cmd/neofs-node/reputation/common/remote.go index fd2c43ed2..9ffb69535 100644 --- a/cmd/neofs-node/reputation/common/remote.go +++ b/cmd/neofs-node/reputation/common/remote.go @@ -1,12 +1,13 @@ package common import ( + "fmt" + apiClient "github.com/nspcc-dev/neofs-api-go/pkg/client" "github.com/nspcc-dev/neofs-node/pkg/network" reputationcommon "github.com/nspcc-dev/neofs-node/pkg/services/reputation/common" reputationrouter "github.com/nspcc-dev/neofs-node/pkg/services/reputation/common/router" trustcontroller "github.com/nspcc-dev/neofs-node/pkg/services/reputation/local/controller" - "github.com/pkg/errors" ) type clientCache interface { @@ -78,12 +79,12 @@ func (rtp *remoteTrustProvider) InitRemote(srv reputationcommon.ServerInfo) (rep hostAddr, err := network.HostAddrFromMultiaddr(addr) if err != nil { - return nil, errors.Wrap(err, "could not convert address to IP format") + return nil, fmt.Errorf("could not convert address to IP format: %w", err) } c, err := rtp.clientCache.Get(hostAddr) if err != nil { - return nil, errors.Wrap(err, "could not initialize API client") + return nil, fmt.Errorf("could not initialize API client: %w", err) } return rtp.remoteProvider.WithClient(c), nil diff --git a/cmd/neofs-node/reputation/local/storage.go b/cmd/neofs-node/reputation/local/storage.go index f3a3a39dc..840032627 100644 --- a/cmd/neofs-node/reputation/local/storage.go +++ b/cmd/neofs-node/reputation/local/storage.go @@ -2,6 +2,7 @@ package local import ( "bytes" + "errors" netmapcore "github.com/nspcc-dev/neofs-node/pkg/core/netmap" "github.com/nspcc-dev/neofs-node/pkg/services/reputation" @@ -9,7 +10,6 @@ import ( trustcontroller "github.com/nspcc-dev/neofs-node/pkg/services/reputation/local/controller" truststorage "github.com/nspcc-dev/neofs-node/pkg/services/reputation/local/storage" "github.com/nspcc-dev/neofs-node/pkg/util/logger" - "github.com/pkg/errors" ) type TrustStorage struct { diff --git a/go.mod b/go.mod index 729d2689a..8d9481a39 100644 --- a/go.mod +++ b/go.mod @@ -19,7 +19,6 @@ require ( github.com/nspcc-dev/tzhash v1.4.0 github.com/panjf2000/ants/v2 v2.3.0 github.com/paulmach/orb v0.2.1 - github.com/pkg/errors v0.9.1 github.com/prometheus/client_golang v1.6.0 github.com/spf13/cobra v1.0.0 github.com/spf13/pflag v1.0.5 // indirect diff --git a/pkg/core/container/fmt.go b/pkg/core/container/fmt.go index 03de5e43a..69275f38f 100644 --- a/pkg/core/container/fmt.go +++ b/pkg/core/container/fmt.go @@ -1,10 +1,12 @@ package container import ( + "errors" + "fmt" + "github.com/nspcc-dev/neofs-api-go/pkg" "github.com/nspcc-dev/neofs-api-go/pkg/container" "github.com/nspcc-dev/neofs-api-go/pkg/owner" - "github.com/pkg/errors" ) var errNilPolicy = errors.New("placement policy is nil") @@ -19,15 +21,15 @@ func CheckFormat(c *container.Container) error { } if err := pkg.IsSupportedVersion(c.Version()); err != nil { - return errors.Wrap(err, "incorrect version") + return fmt.Errorf("incorrect version: %w", err) } if ln := len(c.OwnerID().ToV2().GetValue()); ln != owner.NEO3WalletSize { - return errors.Errorf("incorrect owner identifier: expected length %d != %d", owner.NEO3WalletSize, ln) + return fmt.Errorf("incorrect owner identifier: expected length %d != %d", owner.NEO3WalletSize, ln) } if _, err := c.NonceUUID(); err != nil { - return errors.Wrap(err, "incorrect nonce") + return fmt.Errorf("incorrect nonce: %w", err) } return nil diff --git a/pkg/core/object/errors.go b/pkg/core/object/errors.go index b09c1c35f..b1ba11e1e 100644 --- a/pkg/core/object/errors.go +++ b/pkg/core/object/errors.go @@ -1,6 +1,6 @@ package object -import "github.com/pkg/errors" +import "errors" // ErrNotFound is a basic "not found" error returned by // object read functions. diff --git a/pkg/core/object/fmt.go b/pkg/core/object/fmt.go index e4392ee92..9051944d6 100644 --- a/pkg/core/object/fmt.go +++ b/pkg/core/object/fmt.go @@ -2,6 +2,8 @@ package object import ( "bytes" + "errors" + "fmt" "strconv" "github.com/nspcc-dev/neofs-api-go/pkg/object" @@ -10,7 +12,6 @@ import ( objectV2 "github.com/nspcc-dev/neofs-api-go/v2/object" crypto "github.com/nspcc-dev/neofs-crypto" "github.com/nspcc-dev/neofs-node/pkg/core/netmap" - "github.com/pkg/errors" ) // FormatValidator represents object format validator. @@ -75,16 +76,16 @@ func (v *FormatValidator) Validate(obj *Object) error { for ; obj != nil; obj = obj.GetParent() { if err := v.validateSignatureKey(obj); err != nil { - return errors.Wrapf(err, "(%T) could not validate signature key", v) + return fmt.Errorf("(%T) could not validate signature key: %w", v, err) } // TODO: combine small checks if err := v.checkExpiration(obj); err != nil { - return errors.Wrapf(err, "object did not pass expiration check") + return fmt.Errorf("object did not pass expiration ch: %weck", err) } if err := object.CheckHeaderVerificationFields(obj.SDK()); err != nil { - return errors.Wrapf(err, "(%T) could not validate header fields", v) + return fmt.Errorf("(%T) could not validate header fields: %w", v, err) } } @@ -116,7 +117,7 @@ func (v *FormatValidator) checkOwnerKey(id *owner.ID, key []byte) error { // FIXME: implement Equal method if s1, s2 := id.String(), id2.String(); s1 != s2 { - return errors.Errorf("(%T) different owner identifiers %s/%s", v, s1, s2) + return fmt.Errorf("(%T) different owner identifiers %s/%s", v, s1, s2) } return nil @@ -127,13 +128,13 @@ func (v *FormatValidator) ValidateContent(o *Object) error { switch o.Type() { case object.TypeTombstone: if len(o.Payload()) == 0 { - return errors.Errorf("(%T) empty payload in tombstone", v) + return fmt.Errorf("(%T) empty payload in tombstone", v) } tombstone := object.NewTombstone() if err := tombstone.Unmarshal(o.Payload()); err != nil { - return errors.Wrapf(err, "(%T) could not unmarshal tombstone content", v) + return fmt.Errorf("(%T) could not unmarshal tombstone content: %w", v, err) } // check if tombstone has the same expiration in body and header @@ -153,7 +154,7 @@ func (v *FormatValidator) ValidateContent(o *Object) error { for _, id := range idList { if id == nil { - return errors.Errorf("(%T) empty member in tombstone", v) + return fmt.Errorf("(%T) empty member in tombstone", v) } a := object.NewAddress() @@ -168,18 +169,18 @@ func (v *FormatValidator) ValidateContent(o *Object) error { } case object.TypeStorageGroup: if len(o.Payload()) == 0 { - return errors.Errorf("(%T) empty payload in SG", v) + return fmt.Errorf("(%T) empty payload in SG", v) } sg := storagegroup.New() if err := sg.Unmarshal(o.Payload()); err != nil { - return errors.Wrapf(err, "(%T) could not unmarshal SG content", v) + return fmt.Errorf("(%T) could not unmarshal SG content: %w", v, err) } for _, id := range sg.Members() { if id == nil { - return errors.Errorf("(%T) empty member in SG", v) + return fmt.Errorf("(%T) empty member in SG", v) } } default: diff --git a/pkg/core/object/fmt_test.go b/pkg/core/object/fmt_test.go index b93c8c41a..bc1de24f6 100644 --- a/pkg/core/object/fmt_test.go +++ b/pkg/core/object/fmt_test.go @@ -4,6 +4,7 @@ import ( "crypto/ecdsa" "crypto/rand" "crypto/sha256" + "errors" "strconv" "testing" @@ -15,7 +16,6 @@ import ( objectV2 "github.com/nspcc-dev/neofs-api-go/v2/object" crypto "github.com/nspcc-dev/neofs-crypto" "github.com/nspcc-dev/neofs-node/pkg/util/test" - "github.com/pkg/errors" "github.com/stretchr/testify/require" ) diff --git a/pkg/innerring/indexer.go b/pkg/innerring/indexer.go index d252dd4ad..fd309dc9a 100644 --- a/pkg/innerring/indexer.go +++ b/pkg/innerring/indexer.go @@ -2,12 +2,12 @@ package innerring import ( "crypto/ecdsa" + "fmt" "sync" "time" "github.com/nspcc-dev/neofs-node/pkg/innerring/invoke" "github.com/nspcc-dev/neofs-node/pkg/morph/client" - "github.com/pkg/errors" ) type ( @@ -72,7 +72,7 @@ func (s *innerRingIndexer) update() (ind indexes, err error) { func (s *innerRingIndexer) InnerRingIndex() (int32, error) { ind, err := s.update() if err != nil { - return 0, errors.Wrap(err, "can't update index state") + return 0, fmt.Errorf("can't update index state: %w", err) } return ind.innerRingIndex, nil @@ -81,7 +81,7 @@ func (s *innerRingIndexer) InnerRingIndex() (int32, error) { func (s *innerRingIndexer) InnerRingSize() (int32, error) { ind, err := s.update() if err != nil { - return 0, errors.Wrap(err, "can't update index state") + return 0, fmt.Errorf("can't update index state: %w", err) } return ind.innerRingSize, nil @@ -90,7 +90,7 @@ func (s *innerRingIndexer) InnerRingSize() (int32, error) { func (s *innerRingIndexer) AlphabetIndex() (int32, error) { ind, err := s.update() if err != nil { - return 0, errors.Wrap(err, "can't update index state") + return 0, fmt.Errorf("can't update index state: %w", err) } return ind.alphabetIndex, nil diff --git a/pkg/innerring/innerring.go b/pkg/innerring/innerring.go index 6da977229..0f789db97 100644 --- a/pkg/innerring/innerring.go +++ b/pkg/innerring/innerring.go @@ -3,6 +3,8 @@ package innerring import ( "context" "crypto/ecdsa" + "errors" + "fmt" "io" "github.com/nspcc-dev/neo-go/pkg/core/block" @@ -31,7 +33,6 @@ import ( util2 "github.com/nspcc-dev/neofs-node/pkg/util" "github.com/nspcc-dev/neofs-node/pkg/util/precision" "github.com/panjf2000/ants/v2" - "github.com/pkg/errors" "github.com/spf13/viper" "go.uber.org/atomic" "go.uber.org/zap" @@ -179,9 +180,9 @@ func (s *Server) Start(ctx context.Context, intError chan<- error) error { case <-ctx.Done(): return case err := <-morphErr: - intError <- errors.Wrap(err, "sidechain") + intError <- fmt.Errorf("sidechain: %w", err) case err := <-mainnnetErr: - intError <- errors.Wrap(err, "mainnet") + intError <- fmt.Errorf("mainnet: %w", err) } }() @@ -197,7 +198,7 @@ func (s *Server) Start(ctx context.Context, intError chan<- error) error { go s.mainnetListener.ListenWithError(ctx, mainnnetErr) // listen for neo:mainnet events if err := s.startBlockTimers(); err != nil { - return errors.Wrap(err, "could not start block timers") + return fmt.Errorf("could not start block timers: %w", err) } s.startWorkers(ctx) @@ -249,7 +250,7 @@ func New(ctx context.Context, log *zap.Logger, cfg *viper.Viper) (*Server, error // prepare inner ring node private key server.key, err = crypto.LoadPrivateKey(cfg.GetString("key")) if err != nil { - return nil, errors.Wrap(err, "ir: can't create private key") + return nil, fmt.Errorf("ir: can't create private key: %w", err) } // get all script hashes of contracts @@ -261,7 +262,7 @@ func New(ctx context.Context, log *zap.Logger, cfg *viper.Viper) (*Server, error // parse default validators server.predefinedValidators, err = parsePredefinedValidators(cfg) if err != nil { - return nil, errors.Wrap(err, "ir: can't parse predefined validators list") + return nil, fmt.Errorf("ir: can't parse predefined validators list: %w", err) } morphChain := &chainParams{ @@ -733,42 +734,42 @@ func parseContracts(cfg *viper.Viper) (*contracts, error) { result.netmap, err = util.Uint160DecodeStringLE(netmapContractStr) if err != nil { - return nil, errors.Wrap(err, "ir: can't read netmap script-hash") + return nil, fmt.Errorf("ir: can't read netmap script-hash: %w", err) } result.neofs, err = util.Uint160DecodeStringLE(neofsContractStr) if err != nil { - return nil, errors.Wrap(err, "ir: can't read neofs script-hash") + return nil, fmt.Errorf("ir: can't read neofs script-hash: %w", err) } result.balance, err = util.Uint160DecodeStringLE(balanceContractStr) if err != nil { - return nil, errors.Wrap(err, "ir: can't read balance script-hash") + return nil, fmt.Errorf("ir: can't read balance script-hash: %w", err) } result.container, err = util.Uint160DecodeStringLE(containerContractStr) if err != nil { - return nil, errors.Wrap(err, "ir: can't read container script-hash") + return nil, fmt.Errorf("ir: can't read container script-hash: %w", err) } result.audit, err = util.Uint160DecodeStringLE(auditContractStr) if err != nil { - return nil, errors.Wrap(err, "ir: can't read audit script-hash") + return nil, fmt.Errorf("ir: can't read audit script-hash: %w", err) } result.proxy, err = util.Uint160DecodeStringLE(proxyContractStr) if err != nil { - return nil, errors.Wrap(err, "ir: can't read proxy script-hash") + return nil, fmt.Errorf("ir: can't read proxy script-hash: %w", err) } result.processing, err = util.Uint160DecodeStringLE(processingContractStr) if err != nil { - return nil, errors.Wrap(err, "ir: can't read processing script-hash") + return nil, fmt.Errorf("ir: can't read processing script-hash: %w", err) } result.reputation, err = util.Uint160DecodeStringLE(reputationContractStr) if err != nil { - return nil, errors.Wrap(err, "ir: can't read reputation script-hash") + return nil, fmt.Errorf("ir: can't read reputation script-hash: %w", err) } result.alphabet, err = parseAlphabetContracts(cfg) @@ -793,7 +794,7 @@ func ParsePublicKeysFromStrings(pubKeys []string) (keys.PublicKeys, error) { for i := range pubKeys { key, err := keys.NewPublicKeyFromString(pubKeys[i]) if err != nil { - return nil, errors.Wrap(err, "can't decode public key") + return nil, fmt.Errorf("can't decode public key: %w", err) } publicKeys = append(publicKeys, key) @@ -807,7 +808,7 @@ func parseAlphabetContracts(cfg *viper.Viper) (alphabetContracts, error) { alpha := newAlphabetContracts() if num > lastLetterNum { - return nil, errors.Errorf("amount of alphabet contracts overflows glagolitsa %d > %d", num, lastLetterNum) + return nil, fmt.Errorf("amount of alphabet contracts overflows glagolitsa %d > %d", num, lastLetterNum) } for letter := az; letter < num; letter++ { @@ -815,7 +816,7 @@ func parseAlphabetContracts(cfg *viper.Viper) (alphabetContracts, error) { contractHash, err := util.Uint160DecodeStringLE(contractStr) if err != nil { - return nil, errors.Wrapf(err, "invalid alphabet %s contract: %s", letter.configString(), contractStr) + return nil, fmt.Errorf("invalid alphabet %s contract: %s: %w", letter.configString(), contractStr, err) } alpha.set(letter, contractHash) @@ -828,13 +829,13 @@ func (s *Server) initConfigFromBlockchain() error { // get current epoch epoch, err := invoke.Epoch(s.morphClient, s.contracts.netmap) if err != nil { - return errors.Wrap(err, "can't read epoch") + return fmt.Errorf("can't read epoch: %w", err) } // get balance precision balancePrecision, err := invoke.BalancePrecision(s.morphClient, s.contracts.balance) if err != nil { - return errors.Wrap(err, "can't read balance contract precision") + return fmt.Errorf("can't read balance contract precision: %w", err) } s.epochCounter.Store(uint64(epoch)) diff --git a/pkg/innerring/invoke/enhanced.go b/pkg/innerring/invoke/enhanced.go index 11d14f301..29d631cf8 100644 --- a/pkg/innerring/invoke/enhanced.go +++ b/pkg/innerring/invoke/enhanced.go @@ -15,7 +15,6 @@ import ( wrapNetmap "github.com/nspcc-dev/neofs-node/pkg/morph/client/netmap/wrapper" "github.com/nspcc-dev/neofs-node/pkg/morph/client/reputation" reputationWrapper "github.com/nspcc-dev/neofs-node/pkg/morph/client/reputation/wrapper" - "github.com/pkg/errors" ) // NewContainerClient creates wrapper to access data from container contract. @@ -62,12 +61,12 @@ func NewAuditClient(cli *client.Client, contract util.Uint160, fee SideFeeProvid func NewBalanceClient(cli *client.Client, contract util.Uint160, fee SideFeeProvider) (*balanceWrapper.Wrapper, error) { staticClient, err := client.NewStatic(cli, contract, fee.SideChainFee()) if err != nil { - return nil, errors.Wrap(err, "could not create static client of Balance contract") + return nil, fmt.Errorf("could not create static client of Balance contract: %w", err) } enhancedBalanceClient, err := balance.New(staticClient) if err != nil { - return nil, errors.Wrap(err, "could not create Balance contract client") + return nil, fmt.Errorf("could not create Balance contract client: %w", err) } return balanceWrapper.New(enhancedBalanceClient) @@ -77,12 +76,12 @@ func NewBalanceClient(cli *client.Client, contract util.Uint160, fee SideFeeProv func NewReputationClient(cli *client.Client, contract util.Uint160, fee SideFeeProvider) (*reputationWrapper.ClientWrapper, error) { staticClient, err := client.NewStatic(cli, contract, fee.SideChainFee()) if err != nil { - return nil, errors.Wrap(err, "could not create static client of reputation contract") + return nil, fmt.Errorf("could not create static client of reputation contract: %w", err) } enhancedRepurationClient, err := reputation.New(staticClient) if err != nil { - return nil, errors.Wrap(err, "could not create reputation contract client") + return nil, fmt.Errorf("could not create reputation contract client: %w", err) } return reputationWrapper.WrapClient(enhancedRepurationClient), nil diff --git a/pkg/innerring/invoke/netmap.go b/pkg/innerring/invoke/netmap.go index ac3e29442..71d7a55c5 100644 --- a/pkg/innerring/invoke/netmap.go +++ b/pkg/innerring/invoke/netmap.go @@ -1,12 +1,14 @@ package invoke import ( + "errors" + "fmt" + "github.com/nspcc-dev/neo-go/pkg/crypto/keys" "github.com/nspcc-dev/neo-go/pkg/util" "github.com/nspcc-dev/neo-go/pkg/vm/stackitem" "github.com/nspcc-dev/neofs-api-go/pkg/netmap" "github.com/nspcc-dev/neofs-node/pkg/morph/client" - "github.com/pkg/errors" ) type ( @@ -157,7 +159,7 @@ func NetmapSnapshot(cli *client.Client, con util.Uint160) (*netmap.Netmap, error for i := range rawNodeInfos { nodeInfo, err := peerInfoFromStackItem(rawNodeInfos[i]) if err != nil { - return nil, errors.Wrap(err, "invalid RPC response") + return nil, fmt.Errorf("invalid RPC response: %w", err) } result = append(result, *nodeInfo) diff --git a/pkg/innerring/processors/alphabet/processor.go b/pkg/innerring/processors/alphabet/processor.go index 51a53199b..d41d1a51d 100644 --- a/pkg/innerring/processors/alphabet/processor.go +++ b/pkg/innerring/processors/alphabet/processor.go @@ -1,11 +1,13 @@ package alphabet import ( + "errors" + "fmt" + "github.com/nspcc-dev/neo-go/pkg/util" "github.com/nspcc-dev/neofs-node/pkg/morph/client" "github.com/nspcc-dev/neofs-node/pkg/morph/event" "github.com/panjf2000/ants/v2" - "github.com/pkg/errors" "go.uber.org/zap" ) @@ -65,7 +67,7 @@ func New(p *Params) (*Processor, error) { pool, err := ants.NewPool(p.PoolSize, ants.WithNonblocking(true)) if err != nil { - return nil, errors.Wrap(err, "ir/neofs: can't create worker pool") + return nil, fmt.Errorf("ir/neofs: can't create worker pool: %w", err) } return &Processor{ diff --git a/pkg/innerring/processors/audit/processor.go b/pkg/innerring/processors/audit/processor.go index 37240e257..1bdde8d96 100644 --- a/pkg/innerring/processors/audit/processor.go +++ b/pkg/innerring/processors/audit/processor.go @@ -3,6 +3,8 @@ package audit import ( "context" "crypto/ecdsa" + "errors" + "fmt" "time" "github.com/nspcc-dev/neo-go/pkg/util" @@ -15,7 +17,6 @@ import ( "github.com/nspcc-dev/neofs-node/pkg/morph/event" "github.com/nspcc-dev/neofs-node/pkg/services/audit" "github.com/panjf2000/ants/v2" - "github.com/pkg/errors" "go.uber.org/zap" ) @@ -110,7 +111,7 @@ func New(p *Params) (*Processor, error) { pool, err := ants.NewPool(ProcessorPoolSize, ants.WithNonblocking(true)) if err != nil { - return nil, errors.Wrap(err, "ir/audit: can't create worker pool") + return nil, fmt.Errorf("ir/audit: can't create worker pool: %w", err) } // creating enhanced client for getting network map diff --git a/pkg/innerring/processors/audit/scheduler.go b/pkg/innerring/processors/audit/scheduler.go index 03607cf2c..e12608efd 100644 --- a/pkg/innerring/processors/audit/scheduler.go +++ b/pkg/innerring/processors/audit/scheduler.go @@ -1,11 +1,12 @@ package audit import ( + "errors" + "fmt" "sort" "strings" "github.com/nspcc-dev/neofs-api-go/pkg/container" - "github.com/pkg/errors" "go.uber.org/zap" ) @@ -14,7 +15,7 @@ var ErrInvalidIRNode = errors.New("node is not in the inner ring list") func (ap *Processor) selectContainersToAudit(epoch uint64) ([]*container.ID, error) { containers, err := ap.containerClient.List(nil) if err != nil { - return nil, errors.Wrap(err, "can't get list of containers to start audit") + return nil, fmt.Errorf("can't get list of containers to start audit: %w", err) } // consider getting extra information about container complexity from diff --git a/pkg/innerring/processors/balance/processor.go b/pkg/innerring/processors/balance/processor.go index a98df4ff6..ca6b6d74d 100644 --- a/pkg/innerring/processors/balance/processor.go +++ b/pkg/innerring/processors/balance/processor.go @@ -1,13 +1,15 @@ package balance import ( + "errors" + "fmt" + "github.com/nspcc-dev/neo-go/pkg/util" "github.com/nspcc-dev/neofs-node/pkg/innerring/config" "github.com/nspcc-dev/neofs-node/pkg/morph/client" "github.com/nspcc-dev/neofs-node/pkg/morph/event" balanceEvent "github.com/nspcc-dev/neofs-node/pkg/morph/event/balance" "github.com/panjf2000/ants/v2" - "github.com/pkg/errors" "go.uber.org/zap" ) @@ -70,7 +72,7 @@ func New(p *Params) (*Processor, error) { pool, err := ants.NewPool(p.PoolSize, ants.WithNonblocking(true)) if err != nil { - return nil, errors.Wrap(err, "ir/balance: can't create worker pool") + return nil, fmt.Errorf("ir/balance: can't create worker pool: %w", err) } return &Processor{ diff --git a/pkg/innerring/processors/container/processor.go b/pkg/innerring/processors/container/processor.go index 84c242a34..c37c50e93 100644 --- a/pkg/innerring/processors/container/processor.go +++ b/pkg/innerring/processors/container/processor.go @@ -1,13 +1,15 @@ package container import ( + "errors" + "fmt" + "github.com/nspcc-dev/neo-go/pkg/util" "github.com/nspcc-dev/neofs-node/pkg/innerring/config" "github.com/nspcc-dev/neofs-node/pkg/morph/client" "github.com/nspcc-dev/neofs-node/pkg/morph/event" containerEvent "github.com/nspcc-dev/neofs-node/pkg/morph/event/container" "github.com/panjf2000/ants/v2" - "github.com/pkg/errors" "go.uber.org/zap" ) @@ -60,7 +62,7 @@ func New(p *Params) (*Processor, error) { pool, err := ants.NewPool(p.PoolSize, ants.WithNonblocking(true)) if err != nil { - return nil, errors.Wrap(err, "ir/container: can't create worker pool") + return nil, fmt.Errorf("ir/container: can't create worker pool: %w", err) } return &Processor{ diff --git a/pkg/innerring/processors/governance/list.go b/pkg/innerring/processors/governance/list.go index a181c5969..b5d10ead9 100644 --- a/pkg/innerring/processors/governance/list.go +++ b/pkg/innerring/processors/governance/list.go @@ -1,10 +1,11 @@ package governance import ( + "errors" + "fmt" "sort" "github.com/nspcc-dev/neo-go/pkg/crypto/keys" - "github.com/pkg/errors" ) var ( @@ -25,7 +26,7 @@ func newAlphabetList(sidechain, mainnet keys.PublicKeys) (keys.PublicKeys, error } if len(mainnet) < ln { - return nil, errors.Wrapf(errNotEnoughKeys, "expecting %d keys", ln) + return nil, fmt.Errorf("%w: expecting %d keys", errNotEnoughKeys, ln) } hmap := make(map[string]bool, ln) diff --git a/pkg/innerring/processors/governance/processor.go b/pkg/innerring/processors/governance/processor.go index 7c811a055..3e98150fc 100644 --- a/pkg/innerring/processors/governance/processor.go +++ b/pkg/innerring/processors/governance/processor.go @@ -1,13 +1,15 @@ package governance import ( + "errors" + "fmt" + "github.com/nspcc-dev/neo-go/pkg/crypto/keys" "github.com/nspcc-dev/neo-go/pkg/util" "github.com/nspcc-dev/neofs-node/pkg/innerring/config" "github.com/nspcc-dev/neofs-node/pkg/morph/client" "github.com/nspcc-dev/neofs-node/pkg/morph/event" "github.com/panjf2000/ants/v2" - "github.com/pkg/errors" "go.uber.org/zap" ) @@ -89,7 +91,7 @@ func New(p *Params) (*Processor, error) { pool, err := ants.NewPool(ProcessorPoolSize, ants.WithNonblocking(true)) if err != nil { - return nil, errors.Wrap(err, "ir/governance: can't create worker pool") + return nil, fmt.Errorf("ir/governance: can't create worker pool: %w", err) } return &Processor{ diff --git a/pkg/innerring/processors/neofs/processor.go b/pkg/innerring/processors/neofs/processor.go index c0d7500a2..58047912f 100644 --- a/pkg/innerring/processors/neofs/processor.go +++ b/pkg/innerring/processors/neofs/processor.go @@ -1,6 +1,8 @@ package neofs import ( + "errors" + "fmt" "sync" lru "github.com/hashicorp/golang-lru" @@ -11,7 +13,6 @@ import ( "github.com/nspcc-dev/neofs-node/pkg/morph/event" neofsEvent "github.com/nspcc-dev/neofs-node/pkg/morph/event/neofs" "github.com/panjf2000/ants/v2" - "github.com/pkg/errors" "go.uber.org/zap" ) @@ -97,12 +98,12 @@ func New(p *Params) (*Processor, error) { pool, err := ants.NewPool(p.PoolSize, ants.WithNonblocking(true)) if err != nil { - return nil, errors.Wrap(err, "ir/neofs: can't create worker pool") + return nil, fmt.Errorf("ir/neofs: can't create worker pool: %w", err) } lruCache, err := lru.New(p.MintEmitCacheSize) if err != nil { - return nil, errors.Wrap(err, "ir/neofs: can't create LRU cache for gas emission") + return nil, fmt.Errorf("ir/neofs: can't create LRU cache for gas emission: %w", err) } return &Processor{ diff --git a/pkg/innerring/processors/netmap/nodevalidation/locode/calls.go b/pkg/innerring/processors/netmap/nodevalidation/locode/calls.go index fa38394b8..ade2e80fe 100644 --- a/pkg/innerring/processors/netmap/nodevalidation/locode/calls.go +++ b/pkg/innerring/processors/netmap/nodevalidation/locode/calls.go @@ -1,9 +1,11 @@ package locode import ( + "errors" + "fmt" + "github.com/nspcc-dev/neofs-api-go/pkg/netmap" "github.com/nspcc-dev/neofs-node/pkg/util/locode" - "github.com/pkg/errors" ) var errMissingRequiredAttr = errors.New("missing required attribute in DB record") @@ -36,12 +38,12 @@ func (v *Validator) VerifyAndUpdate(n *netmap.NodeInfo) error { lc, err := locode.FromString(attrLocode.Value()) if err != nil { - return errors.Wrap(err, "invalid locode value") + return fmt.Errorf("invalid locode value: %w", err) } record, err := v.db.Get(lc) if err != nil { - return errors.Wrap(err, "could not get locode record from DB") + return fmt.Errorf("could not get locode record from DB: %w", err) } for attrKey, attrDesc := range v.mAttr { diff --git a/pkg/innerring/processors/netmap/processor.go b/pkg/innerring/processors/netmap/processor.go index 88a37f86b..1257e047f 100644 --- a/pkg/innerring/processors/netmap/processor.go +++ b/pkg/innerring/processors/netmap/processor.go @@ -1,6 +1,9 @@ package netmap import ( + "errors" + "fmt" + "github.com/nspcc-dev/neo-go/pkg/util" "github.com/nspcc-dev/neofs-api-go/pkg/netmap" "github.com/nspcc-dev/neofs-node/pkg/innerring/config" @@ -9,7 +12,6 @@ import ( "github.com/nspcc-dev/neofs-node/pkg/morph/event" netmapEvent "github.com/nspcc-dev/neofs-node/pkg/morph/event/netmap" "github.com/panjf2000/ants/v2" - "github.com/pkg/errors" "go.uber.org/zap" ) @@ -131,7 +133,7 @@ func New(p *Params) (*Processor, error) { pool, err := ants.NewPool(p.PoolSize, ants.WithNonblocking(true)) if err != nil { - return nil, errors.Wrap(err, "ir/netmap: can't create worker pool") + return nil, fmt.Errorf("ir/netmap: can't create worker pool: %w", err) } return &Processor{ diff --git a/pkg/innerring/processors/reputation/processor.go b/pkg/innerring/processors/reputation/processor.go index e5dca8f5a..de42c29f5 100644 --- a/pkg/innerring/processors/reputation/processor.go +++ b/pkg/innerring/processors/reputation/processor.go @@ -1,12 +1,14 @@ package reputation import ( + "errors" + "fmt" + "github.com/nspcc-dev/neo-go/pkg/util" reputationWrapper "github.com/nspcc-dev/neofs-node/pkg/morph/client/reputation/wrapper" "github.com/nspcc-dev/neofs-node/pkg/morph/event" reputationEvent "github.com/nspcc-dev/neofs-node/pkg/morph/event/reputation" "github.com/panjf2000/ants/v2" - "github.com/pkg/errors" "go.uber.org/zap" ) @@ -69,7 +71,7 @@ func New(p *Params) (*Processor, error) { pool, err := ants.NewPool(p.PoolSize, ants.WithNonblocking(true)) if err != nil { - return nil, errors.Wrap(err, "ir/reputation: can't create worker pool") + return nil, fmt.Errorf("ir/reputation: can't create worker pool: %w", err) } return &Processor{ diff --git a/pkg/innerring/processors/settlement/processor.go b/pkg/innerring/processors/settlement/processor.go index efdf87106..7fb2da633 100644 --- a/pkg/innerring/processors/settlement/processor.go +++ b/pkg/innerring/processors/settlement/processor.go @@ -8,7 +8,6 @@ import ( nodeutil "github.com/nspcc-dev/neofs-node/pkg/util" "github.com/nspcc-dev/neofs-node/pkg/util/logger" "github.com/panjf2000/ants/v2" - "github.com/pkg/errors" "go.uber.org/zap" ) @@ -61,7 +60,7 @@ func New(prm Prm, opts ...Option) *Processor { pool, err := ants.NewPool(o.poolSize, ants.WithNonblocking(true)) if err != nil { - panic(errors.Wrap(err, "could not create worker pool")) + panic(fmt.Errorf("could not create worker pool: %w", err)) } o.log.Debug("worker pool for settlement processor successfully initialized", diff --git a/pkg/innerring/settlement.go b/pkg/innerring/settlement.go index beb33fe3f..f9d841f27 100644 --- a/pkg/innerring/settlement.go +++ b/pkg/innerring/settlement.go @@ -3,6 +3,7 @@ package innerring import ( "context" "encoding/hex" + "fmt" "math/big" auditAPI "github.com/nspcc-dev/neofs-api-go/pkg/audit" @@ -22,7 +23,6 @@ import ( "github.com/nspcc-dev/neofs-node/pkg/morph/client/container/wrapper" containerClient "github.com/nspcc-dev/neofs-node/pkg/morph/client/container/wrapper" "github.com/nspcc-dev/neofs-node/pkg/util/logger" - "github.com/pkg/errors" "go.uber.org/zap" ) @@ -91,7 +91,7 @@ func (c *containerWrapper) Owner() *owner.ID { func (s settlementDeps) AuditResultsForEpoch(epoch uint64) ([]*auditAPI.Result, error) { idList, err := s.auditClient.ListAuditResultIDByEpoch(epoch) if err != nil { - return nil, errors.Wrap(err, "could not list audit results in sidechain") + return nil, fmt.Errorf("could not list audit results in sidechain: %w", err) } res := make([]*auditAPI.Result, 0, len(idList)) @@ -99,7 +99,7 @@ func (s settlementDeps) AuditResultsForEpoch(epoch uint64) ([]*auditAPI.Result, for i := range idList { r, err := s.auditClient.GetAuditResult(idList[i]) if err != nil { - return nil, errors.Wrap(err, "could not get audit result") + return nil, fmt.Errorf("could not get audit result: %w", err) } res = append(res, r) @@ -111,7 +111,7 @@ func (s settlementDeps) AuditResultsForEpoch(epoch uint64) ([]*auditAPI.Result, func (s settlementDeps) ContainerInfo(cid *containerAPI.ID) (common.ContainerInfo, error) { cnr, err := s.cnrSrc.Get(cid) if err != nil { - return nil, errors.Wrap(err, "could not get container from storage") + return nil, fmt.Errorf("could not get container from storage: %w", err) } return (*containerWrapper)(cnr), nil @@ -130,12 +130,12 @@ func (s settlementDeps) buildContainer(e uint64, cid *containerAPI.ID) (netmapAP } if err != nil { - return nil, nil, errors.Wrap(err, "could not get network map from storage") + return nil, nil, fmt.Errorf("could not get network map from storage: %w", err) } cnr, err := s.cnrSrc.Get(cid) if err != nil { - return nil, nil, errors.Wrap(err, "could not get container from sidechain") + return nil, nil, fmt.Errorf("could not get container from sidechain: %w", err) } cn, err := nm.GetContainerNodes( @@ -143,7 +143,7 @@ func (s settlementDeps) buildContainer(e uint64, cid *containerAPI.ID) (netmapAP cid.ToV2().GetValue(), // may be replace pivot calculation to neofs-api-go ) if err != nil { - return nil, nil, errors.Wrap(err, "could not calculate container nodes") + return nil, nil, fmt.Errorf("could not calculate container nodes: %w", err) } return cn, nm, nil diff --git a/pkg/local_object_storage/blobovnicza/blobovnicza_test.go b/pkg/local_object_storage/blobovnicza/blobovnicza_test.go index 923933d53..d5a0c9b52 100644 --- a/pkg/local_object_storage/blobovnicza/blobovnicza_test.go +++ b/pkg/local_object_storage/blobovnicza/blobovnicza_test.go @@ -2,6 +2,7 @@ package blobovnicza import ( "crypto/sha256" + "errors" "math/rand" "os" "testing" @@ -10,7 +11,6 @@ import ( objectSDK "github.com/nspcc-dev/neofs-api-go/pkg/object" "github.com/nspcc-dev/neofs-node/pkg/core/object" "github.com/nspcc-dev/neofs-node/pkg/util/logger/test" - "github.com/pkg/errors" "github.com/stretchr/testify/require" ) diff --git a/pkg/local_object_storage/blobovnicza/control.go b/pkg/local_object_storage/blobovnicza/control.go index 408e624a2..3137907e3 100644 --- a/pkg/local_object_storage/blobovnicza/control.go +++ b/pkg/local_object_storage/blobovnicza/control.go @@ -1,10 +1,11 @@ package blobovnicza import ( + "errors" + "fmt" "os" "path" - "github.com/pkg/errors" "go.etcd.io/bbolt" "go.uber.org/zap" ) @@ -58,8 +59,11 @@ func (b *Blobovnicza) Init() error { return true, b.syncFullnessCounter() } - return false, errors.Wrapf(err, - "(%T) could not create bucket for bounds [%d:%d]", b, lower, upper) + if err != nil { + return false, fmt.Errorf("(%T) could not create bucket for bounds [%d:%d]: %w", + b, lower, upper, err) + } + return false, nil }) }) } diff --git a/pkg/local_object_storage/blobovnicza/get_range.go b/pkg/local_object_storage/blobovnicza/get_range.go index 43b2282d3..77895547f 100644 --- a/pkg/local_object_storage/blobovnicza/get_range.go +++ b/pkg/local_object_storage/blobovnicza/get_range.go @@ -1,9 +1,10 @@ package blobovnicza import ( + "fmt" + objectSDK "github.com/nspcc-dev/neofs-api-go/pkg/object" "github.com/nspcc-dev/neofs-node/pkg/core/object" - "github.com/pkg/errors" ) // GetRangePrm groups the parameters of GetRange operation. @@ -59,7 +60,7 @@ func (b *Blobovnicza) GetRange(prm *GetRangePrm) (*GetRangeRes, error) { payload := res.obj if from > to { - return nil, errors.Errorf("invalid range [%d:%d]", from, to) + return nil, fmt.Errorf("invalid range [%d:%d]", from, to) } else if uint64(len(payload)) < to { return nil, object.ErrRangeOutOfBounds } diff --git a/pkg/local_object_storage/blobovnicza/iterate.go b/pkg/local_object_storage/blobovnicza/iterate.go index e62c5bb94..715fcd929 100644 --- a/pkg/local_object_storage/blobovnicza/iterate.go +++ b/pkg/local_object_storage/blobovnicza/iterate.go @@ -1,7 +1,8 @@ package blobovnicza import ( - "github.com/pkg/errors" + "fmt" + "go.etcd.io/bbolt" ) @@ -12,7 +13,7 @@ func (b *Blobovnicza) iterateBuckets(tx *bbolt.Tx, f func(uint64, uint64, *bbolt // expected to happen: // - before initialization step (incorrect usage by design) // - if DB is corrupted (in future this case should be handled) - return false, errors.Errorf("(%T) could not get bucket %s", b, stringifyBounds(lower, upper)) + return false, fmt.Errorf("(%T) could not get bucket %s", b, stringifyBounds(lower, upper)) } return f(lower, upper, buck) diff --git a/pkg/local_object_storage/blobovnicza/put.go b/pkg/local_object_storage/blobovnicza/put.go index 5f145ff5d..f74ee13a3 100644 --- a/pkg/local_object_storage/blobovnicza/put.go +++ b/pkg/local_object_storage/blobovnicza/put.go @@ -1,8 +1,10 @@ package blobovnicza import ( + "errors" + "fmt" + objectSDK "github.com/nspcc-dev/neofs-api-go/pkg/object" - "github.com/pkg/errors" "go.etcd.io/bbolt" ) @@ -65,12 +67,12 @@ func (b *Blobovnicza) Put(prm *PutPrm) (*PutRes, error) { // expected to happen: // - before initialization step (incorrect usage by design) // - if DB is corrupted (in future this case should be handled) - return errors.Errorf("(%T) bucket for size %d not created", b, sz) + return fmt.Errorf("(%T) bucket for size %d not created", b, sz) } // save the object in bucket if err := buck.Put(addressKey(addr), prm.objData); err != nil { - return errors.Wrapf(err, "(%T) could not save object in bucket", b) + return fmt.Errorf("(%T) could not save object in bucket: %w", b, err) } // increase fullness counter diff --git a/pkg/local_object_storage/blobovnicza/sizes.go b/pkg/local_object_storage/blobovnicza/sizes.go index c304df56a..cecdb3f0e 100644 --- a/pkg/local_object_storage/blobovnicza/sizes.go +++ b/pkg/local_object_storage/blobovnicza/sizes.go @@ -5,7 +5,6 @@ import ( "fmt" "code.cloudfoundry.org/bytefmt" - "github.com/pkg/errors" "go.etcd.io/bbolt" ) @@ -54,13 +53,13 @@ func (b *Blobovnicza) full() bool { } func (b *Blobovnicza) syncFullnessCounter() error { - return errors.Wrap(b.boltDB.View(func(tx *bbolt.Tx) error { + err := b.boltDB.View(func(tx *bbolt.Tx) error { sz := uint64(0) if err := b.iterateBucketKeys(func(lower, upper uint64, key []byte) (bool, error) { buck := tx.Bucket(key) if buck == nil { - return false, errors.Errorf("bucket not found %s", stringifyBounds(lower, upper)) + return false, fmt.Errorf("bucket not found %s", stringifyBounds(lower, upper)) } sz += uint64(buck.Stats().KeyN) * (upper - lower) @@ -73,5 +72,9 @@ func (b *Blobovnicza) syncFullnessCounter() error { b.filled.Store(sz) return nil - }), "(%T) could not sync fullness counter") + }) + if err != nil { + return fmt.Errorf("could not sync fullness counter: %w", err) + } + return nil } diff --git a/pkg/local_object_storage/blobstor/blobovnicza.go b/pkg/local_object_storage/blobstor/blobovnicza.go index 3a6bbffa9..69b927693 100644 --- a/pkg/local_object_storage/blobstor/blobovnicza.go +++ b/pkg/local_object_storage/blobstor/blobovnicza.go @@ -1,6 +1,7 @@ package blobstor import ( + "errors" "fmt" "path" "strconv" @@ -11,7 +12,6 @@ import ( objectSDK "github.com/nspcc-dev/neofs-api-go/pkg/object" "github.com/nspcc-dev/neofs-node/pkg/core/object" "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobovnicza" - "github.com/pkg/errors" "go.uber.org/zap" ) @@ -101,7 +101,7 @@ func newBlobovniczaTree(c *cfg) (blz *blobovniczas) { }) if err != nil { // occurs only if the size is not positive - panic(errors.Wrapf(err, "could not create LRU cache of size %d", c.openedCacheSize)) + panic(fmt.Errorf("could not create LRU cache of size %d: %w", c.openedCacheSize, err)) } cp := uint64(1) @@ -563,13 +563,13 @@ func (b *blobovniczas) getObject(blz *blobovnicza.Blobovnicza, prm *blobovnicza. // decompress the data data, err := b.decompressor(res.Object()) if err != nil { - return nil, errors.Wrap(err, "could not decompress object data") + return nil, fmt.Errorf("could not decompress object data: %w", err) } // unmarshal the object obj := object.New() if err := obj.Unmarshal(data); err != nil { - return nil, errors.Wrap(err, "could not unmarshal the object") + return nil, fmt.Errorf("could not unmarshal the object: %w", err) } return &GetSmallRes{ @@ -596,13 +596,13 @@ func (b *blobovniczas) getObjectRange(blz *blobovnicza.Blobovnicza, prm *GetRang // decompress the data data, err := b.decompressor(res.Object()) if err != nil { - return nil, errors.Wrap(err, "could not decompress object data") + return nil, fmt.Errorf("could not decompress object data: %w", err) } // unmarshal the object obj := object.New() if err := obj.Unmarshal(data); err != nil { - return nil, errors.Wrap(err, "could not unmarshal the object") + return nil, fmt.Errorf("could not unmarshal the object: %w", err) } from := prm.rng.GetOffset() @@ -766,9 +766,9 @@ func (b *blobovniczas) init() error { return b.iterateLeaves(func(p string) (bool, error) { blz, err := b.openBlobovnicza(p) if err != nil { - return false, errors.Wrapf(err, "could not open blobovnicza %s", p) + return false, fmt.Errorf("could not open blobovnicza %s: %w", p, err) } else if err := blz.Init(); err != nil { - return false, errors.Wrapf(err, "could not initialize blobovnicza structure %s", p) + return false, fmt.Errorf("could not initialize blobovnicza structure %s: %w", p, err) } log := b.log.With(zap.String("id", p)) @@ -831,7 +831,7 @@ func (b *blobovniczas) openBlobovnicza(p string) (*blobovnicza.Blobovnicza, erro )...) if err := blz.Open(); err != nil { - return nil, errors.Wrapf(err, "could not open blobovnicza %s", p) + return nil, fmt.Errorf("could not open blobovnicza %s: %w", p, err) } b.activeMtx.Lock() diff --git a/pkg/local_object_storage/blobstor/delete_big.go b/pkg/local_object_storage/blobstor/delete_big.go index b1565a8d1..4f7873e47 100644 --- a/pkg/local_object_storage/blobstor/delete_big.go +++ b/pkg/local_object_storage/blobstor/delete_big.go @@ -1,9 +1,10 @@ package blobstor import ( + "errors" + "github.com/nspcc-dev/neofs-node/pkg/core/object" "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobstor/fstree" - "github.com/pkg/errors" ) // DeleteBigPrm groups the parameters of DeleteBig operation. diff --git a/pkg/local_object_storage/blobstor/exists.go b/pkg/local_object_storage/blobstor/exists.go index 5240accfd..43b89de7b 100644 --- a/pkg/local_object_storage/blobstor/exists.go +++ b/pkg/local_object_storage/blobstor/exists.go @@ -1,9 +1,10 @@ package blobstor import ( + "errors" + "github.com/nspcc-dev/neofs-api-go/pkg/object" "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobstor/fstree" - "github.com/pkg/errors" ) // ExistsPrm groups the parameters of Exists operation. diff --git a/pkg/local_object_storage/blobstor/get_big.go b/pkg/local_object_storage/blobstor/get_big.go index 418f0d9b3..228372d6a 100644 --- a/pkg/local_object_storage/blobstor/get_big.go +++ b/pkg/local_object_storage/blobstor/get_big.go @@ -1,9 +1,11 @@ package blobstor import ( + "errors" + "fmt" + "github.com/nspcc-dev/neofs-node/pkg/core/object" "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobstor/fstree" - "github.com/pkg/errors" ) // GetBigPrm groups the parameters of GetBig operation. @@ -31,18 +33,18 @@ func (b *BlobStor) GetBig(prm *GetBigPrm) (*GetBigRes, error) { return nil, object.ErrNotFound } - return nil, errors.Wrap(err, "could not read object from fs tree") + return nil, fmt.Errorf("could not read object from fs tree: %w", err) } data, err = b.decompressor(data) if err != nil { - return nil, errors.Wrap(err, "could not decompress object data") + return nil, fmt.Errorf("could not decompress object data: %w", err) } // unmarshal the object obj := object.New() if err := obj.Unmarshal(data); err != nil { - return nil, errors.Wrap(err, "could not unmarshal the object") + return nil, fmt.Errorf("could not unmarshal the object: %w", err) } return &GetBigRes{ diff --git a/pkg/local_object_storage/blobstor/get_range_big.go b/pkg/local_object_storage/blobstor/get_range_big.go index bcdfabd33..e2eeb7359 100644 --- a/pkg/local_object_storage/blobstor/get_range_big.go +++ b/pkg/local_object_storage/blobstor/get_range_big.go @@ -1,8 +1,9 @@ package blobstor import ( + "fmt" + "github.com/nspcc-dev/neofs-node/pkg/core/object" - "github.com/pkg/errors" ) // GetRangeBigPrm groups the parameters of GetRangeBig operation. @@ -26,18 +27,18 @@ func (b *BlobStor) GetRangeBig(prm *GetRangeBigPrm) (*GetRangeBigRes, error) { // get compressed object data data, err := b.fsTree.Get(prm.addr) if err != nil { - return nil, errors.Wrap(err, "could not read object from fs tree") + return nil, fmt.Errorf("could not read object from fs tree: %w", err) } data, err = b.decompressor(data) if err != nil { - return nil, errors.Wrap(err, "could not decompress object data") + return nil, fmt.Errorf("could not decompress object data: %w", err) } // unmarshal the object obj := object.New() if err := obj.Unmarshal(data); err != nil { - return nil, errors.Wrap(err, "could not unmarshal the object") + return nil, fmt.Errorf("could not unmarshal the object: %w", err) } payload := obj.Payload() diff --git a/pkg/local_object_storage/blobstor/put.go b/pkg/local_object_storage/blobstor/put.go index 9864d1c9f..8451a9f8a 100644 --- a/pkg/local_object_storage/blobstor/put.go +++ b/pkg/local_object_storage/blobstor/put.go @@ -1,8 +1,9 @@ package blobstor import ( + "fmt" + objectSDK "github.com/nspcc-dev/neofs-api-go/pkg/object" - "github.com/pkg/errors" ) // PutPrm groups the parameters of Put operation. @@ -27,7 +28,7 @@ func (b *BlobStor) Put(prm *PutPrm) (*PutRes, error) { // marshal object data, err := prm.obj.Marshal() if err != nil { - return nil, errors.Wrap(err, "could not marshal the object") + return nil, fmt.Errorf("could not marshal the object: %w", err) } return b.PutRaw(prm.obj.Address(), data) diff --git a/pkg/local_object_storage/engine/control.go b/pkg/local_object_storage/engine/control.go index 72ef84bd9..1b1383b69 100644 --- a/pkg/local_object_storage/engine/control.go +++ b/pkg/local_object_storage/engine/control.go @@ -1,7 +1,8 @@ package engine import ( - "github.com/pkg/errors" + "fmt" + "go.uber.org/zap" ) @@ -12,7 +13,7 @@ func (e *StorageEngine) Open() error { for id, sh := range e.shards { if err := sh.Open(); err != nil { - return errors.Wrapf(err, "could not open shard %s", id) + return fmt.Errorf("could not open shard %s: %w", id, err) } } @@ -26,7 +27,7 @@ func (e *StorageEngine) Init() error { for id, sh := range e.shards { if err := sh.Init(); err != nil { - return errors.Wrapf(err, "could not initialize shard %s", id) + return fmt.Errorf("could not initialize shard %s: %w", id, err) } } diff --git a/pkg/local_object_storage/engine/head.go b/pkg/local_object_storage/engine/head.go index 6c22ad2ab..d4abcf6bc 100644 --- a/pkg/local_object_storage/engine/head.go +++ b/pkg/local_object_storage/engine/head.go @@ -1,11 +1,12 @@ package engine import ( + "errors" + objectSDK "github.com/nspcc-dev/neofs-api-go/pkg/object" "github.com/nspcc-dev/neofs-node/pkg/core/object" "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/shard" "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/util" - "github.com/pkg/errors" "go.uber.org/zap" ) diff --git a/pkg/local_object_storage/engine/shards.go b/pkg/local_object_storage/engine/shards.go index 57cb07cac..41633b260 100644 --- a/pkg/local_object_storage/engine/shards.go +++ b/pkg/local_object_storage/engine/shards.go @@ -1,13 +1,13 @@ package engine import ( + "errors" "fmt" "github.com/google/uuid" "github.com/nspcc-dev/hrw" "github.com/nspcc-dev/neofs-api-go/pkg/object" "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/shard" - "github.com/pkg/errors" ) var errShardNotFound = errors.New("shard not found") @@ -26,7 +26,7 @@ func (e *StorageEngine) AddShard(opts ...shard.Option) (*shard.ID, error) { id, err := generateShardID() if err != nil { - return nil, errors.Wrap(err, "could not generate shard ID") + return nil, fmt.Errorf("could not generate shard ID: %w", err) } e.shards[id.String()] = shard.New(append(opts, diff --git a/pkg/local_object_storage/metabase/delete.go b/pkg/local_object_storage/metabase/delete.go index 3b9099365..c77ba04e9 100644 --- a/pkg/local_object_storage/metabase/delete.go +++ b/pkg/local_object_storage/metabase/delete.go @@ -2,11 +2,11 @@ package meta import ( "bytes" + "errors" "fmt" objectSDK "github.com/nspcc-dev/neofs-api-go/pkg/object" "github.com/nspcc-dev/neofs-node/pkg/core/object" - "github.com/pkg/errors" "go.etcd.io/bbolt" ) @@ -80,7 +80,7 @@ func (db *DB) delete(tx *bbolt.Tx, addr *objectSDK.Address, refCounter reference if graveyard != nil { err := graveyard.Delete(addressKey(addr)) if err != nil { - return errors.Wrap(err, "could not remove from graveyard") + return fmt.Errorf("could not remove from graveyard: %w", err) } } diff --git a/pkg/local_object_storage/metabase/delete_test.go b/pkg/local_object_storage/metabase/delete_test.go index 138b5bbf8..ccac6780c 100644 --- a/pkg/local_object_storage/metabase/delete_test.go +++ b/pkg/local_object_storage/metabase/delete_test.go @@ -1,11 +1,11 @@ package meta_test import ( + "errors" "testing" objectSDK "github.com/nspcc-dev/neofs-api-go/pkg/object" meta "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/metabase" - "github.com/pkg/errors" "github.com/stretchr/testify/require" ) diff --git a/pkg/local_object_storage/metabase/graveyard.go b/pkg/local_object_storage/metabase/graveyard.go index 7366f9ed5..0fbe92c99 100644 --- a/pkg/local_object_storage/metabase/graveyard.go +++ b/pkg/local_object_storage/metabase/graveyard.go @@ -2,9 +2,10 @@ package meta import ( "bytes" + "errors" + "fmt" "github.com/nspcc-dev/neofs-api-go/pkg/object" - "github.com/pkg/errors" "go.etcd.io/bbolt" ) @@ -50,7 +51,7 @@ func (db *DB) iterateOverGraveyard(tx *bbolt.Tx, h GraveHandler) error { // parse Grave g, err := graveFromKV(k, v) if err != nil { - return errors.Wrap(err, "could not parse Grave") + return fmt.Errorf("could not parse Grave: %w", err) } // handler Grave @@ -67,7 +68,7 @@ func (db *DB) iterateOverGraveyard(tx *bbolt.Tx, h GraveHandler) error { func graveFromKV(k, v []byte) (*Grave, error) { addr, err := addressFromKey(k) if err != nil { - return nil, errors.Wrap(err, "could not parse address") + return nil, fmt.Errorf("could not parse address: %w", err) } return &Grave{ diff --git a/pkg/local_object_storage/metabase/inhume.go b/pkg/local_object_storage/metabase/inhume.go index 9e496a1df..90810a333 100644 --- a/pkg/local_object_storage/metabase/inhume.go +++ b/pkg/local_object_storage/metabase/inhume.go @@ -2,9 +2,10 @@ package meta import ( "bytes" + "errors" + "fmt" objectSDK "github.com/nspcc-dev/neofs-api-go/pkg/object" - "github.com/pkg/errors" "go.etcd.io/bbolt" ) @@ -86,7 +87,7 @@ func (db *DB) Inhume(prm *InhumePrm) (res *InhumeRes, err error) { if data != nil && !bytes.Equal(data, []byte(inhumeGCMarkValue)) { err := graveyard.Delete(tombKey) if err != nil { - return errors.Wrap(err, "could not remove grave with tombstone key") + return fmt.Errorf("could not remove grave with tombstone key: %w", err) } } } else { diff --git a/pkg/local_object_storage/metabase/inhume_test.go b/pkg/local_object_storage/metabase/inhume_test.go index 0e5818875..55cecfb67 100644 --- a/pkg/local_object_storage/metabase/inhume_test.go +++ b/pkg/local_object_storage/metabase/inhume_test.go @@ -1,11 +1,11 @@ package meta_test import ( + "errors" "testing" "github.com/nspcc-dev/neofs-node/pkg/core/object" meta "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/metabase" - "github.com/pkg/errors" "github.com/stretchr/testify/require" ) diff --git a/pkg/local_object_storage/metabase/iterators.go b/pkg/local_object_storage/metabase/iterators.go index 57f6faee2..a1df7b2e2 100644 --- a/pkg/local_object_storage/metabase/iterators.go +++ b/pkg/local_object_storage/metabase/iterators.go @@ -1,12 +1,13 @@ package meta import ( + "errors" + "fmt" "strconv" "github.com/nspcc-dev/neofs-api-go/pkg/container" "github.com/nspcc-dev/neofs-api-go/pkg/object" objectV2 "github.com/nspcc-dev/neofs-api-go/v2/object" - "github.com/pkg/errors" "go.etcd.io/bbolt" ) @@ -60,7 +61,7 @@ func (db *DB) iterateExpired(tx *bbolt.Tx, epoch uint64, h ExpiredObjectHandler) expiresAt, err := strconv.ParseUint(string(expKey), 10, 64) if err != nil { - return errors.Wrap(err, "could not parse expiration epoch") + return fmt.Errorf("could not parse expiration epoch: %w", err) } else if expiresAt >= epoch { return nil } @@ -70,14 +71,14 @@ func (db *DB) iterateExpired(tx *bbolt.Tx, epoch uint64, h ExpiredObjectHandler) err = id.Parse(string(idKey)) if err != nil { - return errors.Wrap(err, "could not parse ID of expired object") + return fmt.Errorf("could not parse ID of expired object: %w", err) } cid := container.NewID() err = cid.Parse(string(cidBytes)) if err != nil { - return errors.Wrap(err, "could not parse container ID of expired bucket") + return fmt.Errorf("could not parse container ID of expired bucket: %w", err) } addr := object.NewAddress() @@ -133,7 +134,7 @@ func (db *DB) iterateCoveredByTombstones(tx *bbolt.Tx, tss map[string]struct{}, if _, ok := tss[string(v)]; ok { addr, err := addressFromKey(k) if err != nil { - return errors.Wrap(err, "could not parse address of the object under tombstone") + return fmt.Errorf("could not parse address of the object under tombstone: %w", err) } return h(addr) diff --git a/pkg/local_object_storage/metabase/select.go b/pkg/local_object_storage/metabase/select.go index 88636da42..c8314e4a2 100644 --- a/pkg/local_object_storage/metabase/select.go +++ b/pkg/local_object_storage/metabase/select.go @@ -2,13 +2,13 @@ package meta import ( "encoding/binary" + "errors" "fmt" "strings" "github.com/nspcc-dev/neofs-api-go/pkg/container" "github.com/nspcc-dev/neofs-api-go/pkg/object" v2object "github.com/nspcc-dev/neofs-api-go/v2/object" - "github.com/pkg/errors" "go.etcd.io/bbolt" "go.uber.org/zap" ) diff --git a/pkg/local_object_storage/shard/container.go b/pkg/local_object_storage/shard/container.go index 3ec4d51ae..48995b8fa 100644 --- a/pkg/local_object_storage/shard/container.go +++ b/pkg/local_object_storage/shard/container.go @@ -1,8 +1,9 @@ package shard import ( + "fmt" + "github.com/nspcc-dev/neofs-api-go/pkg/container" - "github.com/pkg/errors" ) type ContainerSizePrm struct { @@ -28,7 +29,7 @@ func (r *ContainerSizeRes) Size() uint64 { func (s *Shard) ContainerSize(prm *ContainerSizePrm) (*ContainerSizeRes, error) { size, err := s.metaBase.ContainerSize(prm.cid) if err != nil { - return nil, errors.Wrap(err, "could not get container size") + return nil, fmt.Errorf("could not get container size: %w", err) } return &ContainerSizeRes{ diff --git a/pkg/local_object_storage/shard/control.go b/pkg/local_object_storage/shard/control.go index 8c29c3d6c..d2795412d 100644 --- a/pkg/local_object_storage/shard/control.go +++ b/pkg/local_object_storage/shard/control.go @@ -1,7 +1,7 @@ package shard import ( - "github.com/pkg/errors" + "fmt" ) // Open opens all Shard's components. @@ -16,7 +16,7 @@ func (s *Shard) Open() error { for _, component := range components { if err := component.Open(); err != nil { - return errors.Wrapf(err, "could not open %T", component) + return fmt.Errorf("could not open %T: %w", component, err) } } @@ -35,7 +35,7 @@ func (s *Shard) Init() error { for _, component := range components { if err := component.Init(); err != nil { - return errors.Wrapf(err, "could not initialize %T", component) + return fmt.Errorf("could not initialize %T: %w", component, err) } } @@ -70,7 +70,7 @@ func (s *Shard) Close() error { for _, component := range components { if err := component.Close(); err != nil { - return errors.Wrapf(err, "could not close %s", component) + return fmt.Errorf("could not close %s: %w", component, err) } } diff --git a/pkg/local_object_storage/shard/delete.go b/pkg/local_object_storage/shard/delete.go index 3a3c22fb4..ef673d215 100644 --- a/pkg/local_object_storage/shard/delete.go +++ b/pkg/local_object_storage/shard/delete.go @@ -1,12 +1,13 @@ package shard import ( + "errors" + objectSDK "github.com/nspcc-dev/neofs-api-go/pkg/object" "github.com/nspcc-dev/neofs-node/pkg/core/object" "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobovnicza" "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobstor" meta "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/metabase" - "github.com/pkg/errors" "go.uber.org/zap" ) diff --git a/pkg/local_object_storage/shard/get.go b/pkg/local_object_storage/shard/get.go index ed9f5172e..2576d2739 100644 --- a/pkg/local_object_storage/shard/get.go +++ b/pkg/local_object_storage/shard/get.go @@ -1,6 +1,7 @@ package shard import ( + "errors" "fmt" objectSDK "github.com/nspcc-dev/neofs-api-go/pkg/object" @@ -8,7 +9,6 @@ import ( "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobovnicza" "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobstor" meta "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/metabase" - "github.com/pkg/errors" "go.uber.org/zap" ) diff --git a/pkg/local_object_storage/shard/list.go b/pkg/local_object_storage/shard/list.go index 9dfeb6276..2a091814c 100644 --- a/pkg/local_object_storage/shard/list.go +++ b/pkg/local_object_storage/shard/list.go @@ -6,7 +6,6 @@ import ( "github.com/nspcc-dev/neofs-api-go/pkg/container" "github.com/nspcc-dev/neofs-api-go/pkg/object" meta "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/metabase" - "github.com/pkg/errors" "go.uber.org/zap" ) @@ -48,7 +47,7 @@ func (s *Shard) List() (*SelectRes, error) { func (s *Shard) ListContainers(_ *ListContainersPrm) (*ListContainersRes, error) { containers, err := s.metaBase.Containers() if err != nil { - return nil, errors.Wrap(err, "could not get list of containers") + return nil, fmt.Errorf("could not get list of containers: %w", err) } return &ListContainersRes{ diff --git a/pkg/local_object_storage/shard/put.go b/pkg/local_object_storage/shard/put.go index e3399f672..2ee802f1f 100644 --- a/pkg/local_object_storage/shard/put.go +++ b/pkg/local_object_storage/shard/put.go @@ -1,10 +1,11 @@ package shard import ( + "fmt" + "github.com/nspcc-dev/neofs-node/pkg/core/object" "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobstor" meta "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/metabase" - "github.com/pkg/errors" "go.uber.org/zap" ) @@ -52,14 +53,14 @@ func (s *Shard) Put(prm *PutPrm) (*PutRes, error) { // res == nil if there is no writeCache or writeCache.Put has been failed if res, err = s.blobStor.Put(putPrm); err != nil { - return nil, errors.Wrap(err, "could not put object to BLOB storage") + return nil, fmt.Errorf("could not put object to BLOB storage: %w", err) } // put to metabase if err := meta.Put(s.metaBase, prm.obj, res.BlobovniczaID()); err != nil { // may we need to handle this case in a special way // since the object has been successfully written to BlobStor - return nil, errors.Wrap(err, "could not put object to metabase") + return nil, fmt.Errorf("could not put object to metabase: %w", err) } return nil, nil diff --git a/pkg/local_object_storage/shard/select.go b/pkg/local_object_storage/shard/select.go index 0ce4823db..2b7a20bd6 100644 --- a/pkg/local_object_storage/shard/select.go +++ b/pkg/local_object_storage/shard/select.go @@ -1,10 +1,11 @@ package shard import ( + "fmt" + "github.com/nspcc-dev/neofs-api-go/pkg/container" objectSDK "github.com/nspcc-dev/neofs-api-go/pkg/object" meta "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/metabase" - "github.com/pkg/errors" ) // SelectPrm groups the parameters of Select operation. @@ -48,7 +49,7 @@ func (r *SelectRes) AddressList() []*objectSDK.Address { func (s *Shard) Select(prm *SelectPrm) (*SelectRes, error) { addrList, err := meta.Select(s.metaBase, prm.cid, prm.filters) if err != nil { - return nil, errors.Wrap(err, "could not select objects from metabase") + return nil, fmt.Errorf("could not select objects from metabase: %w", err) } return &SelectRes{ diff --git a/pkg/morph/client/audit/get_result.go b/pkg/morph/client/audit/get_result.go index 3df80aad3..f4df9488c 100644 --- a/pkg/morph/client/audit/get_result.go +++ b/pkg/morph/client/audit/get_result.go @@ -1,8 +1,9 @@ package audit import ( + "fmt" + "github.com/nspcc-dev/neofs-node/pkg/morph/client" - "github.com/pkg/errors" ) // GetAuditResultArgs groups the arguments @@ -35,14 +36,14 @@ func (c *Client) GetAuditResult(args GetAuditResultArgs) (*GetAuditResultValue, args.id, ) if err != nil { - return nil, errors.Wrapf(err, "could not perform test invocation (%s)", c.getResultMethod) + return nil, fmt.Errorf("could not perform test invocation (%s): %w", c.getResultMethod, err) } else if ln := len(prms); ln != 1 { - return nil, errors.Errorf("unexpected stack item count (%s): %d", c.getResultMethod, ln) + return nil, fmt.Errorf("unexpected stack item count (%s): %d", c.getResultMethod, ln) } resultBytes, err := client.BytesFromStackItem(prms[0]) if err != nil { - return nil, errors.Wrapf(err, "could not get byte array from stack item (%s)", c.getResultMethod) + return nil, fmt.Errorf("could not get byte array from stack item (%s): %w", c.getResultMethod, err) } return &GetAuditResultValue{ diff --git a/pkg/morph/client/audit/list_results.go b/pkg/morph/client/audit/list_results.go index f18c1156b..bafbb513f 100644 --- a/pkg/morph/client/audit/list_results.go +++ b/pkg/morph/client/audit/list_results.go @@ -1,9 +1,10 @@ package audit import ( + "fmt" + "github.com/nspcc-dev/neo-go/pkg/vm/stackitem" "github.com/nspcc-dev/neofs-node/pkg/morph/client" - "github.com/pkg/errors" ) // ListResultsArgs groups the arguments @@ -66,7 +67,7 @@ func (c *Client) ListAuditResults(args ListResultsArgs) (*ListResultsValues, err c.listResultsMethod, ) if err != nil { - return nil, errors.Wrapf(err, "could not perform test invocation (%s)", c.listResultsMethod) + return nil, fmt.Errorf("could not perform test invocation (%s): %w", c.listResultsMethod, err) } return parseAuditResults(items, c.listResultsMethod) @@ -80,7 +81,7 @@ func (c *Client) ListAuditResultsByEpoch(args ListResultsByEpochArgs) (*ListResu args.epoch, ) if err != nil { - return nil, errors.Wrapf(err, "could not perform test invocation (%s)", c.listByEpochResultsMethod) + return nil, fmt.Errorf("could not perform test invocation (%s): %w", c.listByEpochResultsMethod, err) } return parseAuditResults(items, c.listByEpochResultsMethod) @@ -95,7 +96,7 @@ func (c *Client) ListAuditResultsByCID(args ListResultsByCIDArgs) (*ListResultsV args.cid, ) if err != nil { - return nil, errors.Wrapf(err, "could not perform test invocation (%s)", c.listByCIDResultsMethod) + return nil, fmt.Errorf("could not perform test invocation (%s): %w", c.listByCIDResultsMethod, err) } return parseAuditResults(items, c.listByCIDResultsMethod) @@ -111,7 +112,7 @@ func (c *Client) ListAuditResultsByNode(args ListResultsByNodeArgs) (*ListResult args.nodeKey, ) if err != nil { - return nil, errors.Wrapf(err, "could not perform test invocation (%s)", c.listByNodeResultsMethod) + return nil, fmt.Errorf("could not perform test invocation (%s): %w", c.listByNodeResultsMethod, err) } return parseAuditResults(items, c.listByNodeResultsMethod) @@ -119,12 +120,12 @@ func (c *Client) ListAuditResultsByNode(args ListResultsByNodeArgs) (*ListResult func parseAuditResults(items []stackitem.Item, method string) (*ListResultsValues, error) { if ln := len(items); ln != 1 { - return nil, errors.Errorf("unexpected stack item count (%s): %d", method, ln) + return nil, fmt.Errorf("unexpected stack item count (%s): %d", method, ln) } items, err := client.ArrayFromStackItem(items[0]) if err != nil { - return nil, errors.Wrapf(err, "could not get stack item array from stack item (%s)", method) + return nil, fmt.Errorf("could not get stack item array from stack item (%s): %w", method, err) } res := &ListResultsValues{ @@ -134,7 +135,7 @@ func parseAuditResults(items []stackitem.Item, method string) (*ListResultsValue for i := range items { rawRes, err := client.BytesFromStackItem(items[i]) if err != nil { - return nil, errors.Wrapf(err, "could not get byte array from stack item (%s)", method) + return nil, fmt.Errorf("could not get byte array from stack item (%s): %w", method, err) } res.rawResults = append(res.rawResults, rawRes) diff --git a/pkg/morph/client/audit/put_result.go b/pkg/morph/client/audit/put_result.go index 084fb7651..0c4f5710a 100644 --- a/pkg/morph/client/audit/put_result.go +++ b/pkg/morph/client/audit/put_result.go @@ -1,7 +1,7 @@ package audit import ( - "github.com/pkg/errors" + "fmt" ) // PutAuditResultArgs groups the arguments @@ -19,8 +19,13 @@ func (g *PutAuditResultArgs) SetRawResult(v []byte) { // PutAuditResult invokes the call of "put audit result" method // of NeoFS Audit contract. func (c *Client) PutAuditResult(args PutAuditResultArgs) error { - return errors.Wrapf(c.client.Invoke( + err := c.client.Invoke( c.putResultMethod, args.rawResult, - ), "could not invoke method (%s)", c.putResultMethod) + ) + + if err != nil { + return fmt.Errorf("could not invoke method (%s): %w", c.putResultMethod, err) + } + return nil } diff --git a/pkg/morph/client/audit/wrapper/result.go b/pkg/morph/client/audit/wrapper/result.go index 0cd8cbc8c..5b4f30e2f 100644 --- a/pkg/morph/client/audit/wrapper/result.go +++ b/pkg/morph/client/audit/wrapper/result.go @@ -1,10 +1,12 @@ package audit import ( + "errors" + "fmt" + auditAPI "github.com/nspcc-dev/neofs-api-go/pkg/audit" "github.com/nspcc-dev/neofs-api-go/pkg/container" "github.com/nspcc-dev/neofs-node/pkg/morph/client/audit" - "github.com/pkg/errors" ) // ResultID is an identity of audit result inside audit contract. @@ -19,7 +21,7 @@ var errUnsupported = errors.New("unsupported structure version") func (w *ClientWrapper) PutAuditResult(result *auditAPI.Result) error { rawResult, err := result.Marshal() if err != nil { - return errors.Wrap(err, "could not marshal audit result") + return fmt.Errorf("could not marshal audit result: %w", err) } args := audit.PutAuditResultArgs{} @@ -121,7 +123,7 @@ func (w *ClientWrapper) GetAuditResult(id ResultID) (*auditAPI.Result, error) { auditRes := auditAPI.NewResult() if err := auditRes.Unmarshal(value.Result()); err != nil { - return nil, errors.Wrap(err, "could not unmarshal audit result structure") + return nil, fmt.Errorf("could not unmarshal audit result structure: %w", err) } return auditRes, nil diff --git a/pkg/morph/client/balance/balanceOf.go b/pkg/morph/client/balance/balanceOf.go index 52a001410..d1e1a026a 100644 --- a/pkg/morph/client/balance/balanceOf.go +++ b/pkg/morph/client/balance/balanceOf.go @@ -1,10 +1,10 @@ package balance import ( + "fmt" "math/big" "github.com/nspcc-dev/neofs-node/pkg/morph/client" - "github.com/pkg/errors" ) // GetBalanceOfArgs groups the arguments @@ -38,14 +38,14 @@ func (c *Client) BalanceOf(args GetBalanceOfArgs) (*GetBalanceOfValues, error) { args.wallet, ) if err != nil { - return nil, errors.Wrapf(err, "could not perform test invocation (%s)", c.balanceOfMethod) + return nil, fmt.Errorf("could not perform test invocation (%s): %w", c.balanceOfMethod, err) } else if ln := len(prms); ln != 1 { - return nil, errors.Errorf("unexpected stack item count (%s): %d", c.balanceOfMethod, ln) + return nil, fmt.Errorf("unexpected stack item count (%s): %d", c.balanceOfMethod, ln) } amount, err := client.BigIntFromStackItem(prms[0]) if err != nil { - return nil, errors.Wrapf(err, "could not get integer stack item from stack item (%s)", c.balanceOfMethod) + return nil, fmt.Errorf("could not get integer stack item from stack item (%s): %w", c.balanceOfMethod, err) } return &GetBalanceOfValues{ diff --git a/pkg/morph/client/balance/decimals.go b/pkg/morph/client/balance/decimals.go index fb65b76a5..522d299fe 100644 --- a/pkg/morph/client/balance/decimals.go +++ b/pkg/morph/client/balance/decimals.go @@ -1,8 +1,9 @@ package balance import ( + "fmt" + "github.com/nspcc-dev/neofs-node/pkg/morph/client" - "github.com/pkg/errors" ) // DecimalsArgs groups the arguments @@ -28,14 +29,14 @@ func (c *Client) Decimals(args DecimalsArgs) (*DecimalsValues, error) { c.decimalsMethod, ) if err != nil { - return nil, errors.Wrapf(err, "could not perform test invocation (%s)", c.decimalsMethod) + return nil, fmt.Errorf("could not perform test invocation (%s): %w", c.decimalsMethod, err) } else if ln := len(prms); ln != 1 { - return nil, errors.Errorf("unexpected stack item count (%s): %d", c.decimalsMethod, ln) + return nil, fmt.Errorf("unexpected stack item count (%s): %d", c.decimalsMethod, ln) } decimals, err := client.IntFromStackItem(prms[0]) if err != nil { - return nil, errors.Wrapf(err, "could not get integer stack item from stack item (%s)", c.decimalsMethod) + return nil, fmt.Errorf("could not get integer stack item from stack item (%s): %w", c.decimalsMethod, err) } return &DecimalsValues{ diff --git a/pkg/morph/client/balance/transfer.go b/pkg/morph/client/balance/transfer.go index 5305aa54e..c3273183f 100644 --- a/pkg/morph/client/balance/transfer.go +++ b/pkg/morph/client/balance/transfer.go @@ -1,7 +1,7 @@ package balance import ( - "github.com/pkg/errors" + "fmt" ) // TransferXArgs groups the arguments @@ -58,11 +58,16 @@ func (c *Client) transferX(notary bool, args TransferXArgs) error { f = c.client.NotaryInvoke } - return errors.Wrapf(f( + err := f( c.transferXMethod, args.sender, args.recipient, args.amount, args.details, - ), "could not invoke method (%s)", c.transferXMethod) + ) + + if err != nil { + return fmt.Errorf("could not invoke method (%s): %w", c.transferXMethod, err) + } + return nil } diff --git a/pkg/morph/client/balance/wrapper/decimals.go b/pkg/morph/client/balance/wrapper/decimals.go index 2910622f5..2cb8cb6ca 100644 --- a/pkg/morph/client/balance/wrapper/decimals.go +++ b/pkg/morph/client/balance/wrapper/decimals.go @@ -1,8 +1,9 @@ package wrapper import ( + "fmt" + "github.com/nspcc-dev/neofs-node/pkg/morph/client/balance" - "github.com/pkg/errors" ) // Decimals decimal precision of currency transactions @@ -14,7 +15,7 @@ func (w *Wrapper) Decimals() (uint32, error) { // invoke smart contract call values, err := w.client.Decimals(args) if err != nil { - return 0, errors.Wrap(err, "could not invoke smart contract") + return 0, fmt.Errorf("could not invoke smart contract: %w", err) } return uint32(values.Decimals()), nil diff --git a/pkg/morph/client/balance/wrapper/transfer.go b/pkg/morph/client/balance/wrapper/transfer.go index 8152c44f0..d659ebcc5 100644 --- a/pkg/morph/client/balance/wrapper/transfer.go +++ b/pkg/morph/client/balance/wrapper/transfer.go @@ -1,9 +1,10 @@ package wrapper import ( + "fmt" + "github.com/nspcc-dev/neofs-api-go/pkg/owner" "github.com/nspcc-dev/neofs-node/pkg/morph/client/balance" - "github.com/pkg/errors" ) // TransferPrm groups parameters of TransferX method. @@ -30,12 +31,12 @@ func (w *Wrapper) TransferXNotary(p TransferPrm) error { func (w *Wrapper) transferX(notary bool, p TransferPrm) error { from, err := owner.ScriptHashBE(p.From) if err != nil { - return errors.Wrap(err, "invalid sender") + return fmt.Errorf("invalid sender: %w", err) } to, err := owner.ScriptHashBE(p.To) if err != nil { - return errors.Wrap(err, "invalid recipient") + return fmt.Errorf("invalid recipient: %w", err) } // prepare invocation arguments diff --git a/pkg/morph/client/client.go b/pkg/morph/client/client.go index 8fe09f61d..52e8e565b 100644 --- a/pkg/morph/client/client.go +++ b/pkg/morph/client/client.go @@ -2,6 +2,7 @@ package client import ( "context" + "errors" "fmt" "time" @@ -17,7 +18,6 @@ import ( "github.com/nspcc-dev/neo-go/pkg/vm/stackitem" "github.com/nspcc-dev/neo-go/pkg/wallet" "github.com/nspcc-dev/neofs-node/pkg/util/logger" - "github.com/pkg/errors" "go.uber.org/zap" ) @@ -230,7 +230,7 @@ func (c *Client) TxHalt(h util.Uint256) (bool, error) { func (c *Client) NeoFSAlphabetList() (keys.PublicKeys, error) { list, err := c.roleList(noderoles.NeoFSAlphabet) if err != nil { - return nil, errors.Wrap(err, "can't get alphabet nodes role list") + return nil, fmt.Errorf("can't get alphabet nodes role list: %w", err) } return list, nil @@ -239,7 +239,7 @@ func (c *Client) NeoFSAlphabetList() (keys.PublicKeys, error) { func (c *Client) roleList(r noderoles.Role) (keys.PublicKeys, error) { height, err := c.client.GetBlockCount() if err != nil { - return nil, errors.Wrap(err, "can't get chain height") + return nil, fmt.Errorf("can't get chain height: %w", err) } return c.client.GetDesignatedByRole(r, height) @@ -285,7 +285,7 @@ func toStackParameter(value interface{}) (sc.Parameter, error) { return toStackParameter(arr) default: - return result, errors.Errorf("chain/client: unsupported parameter %v", value) + return result, fmt.Errorf("chain/client: unsupported parameter %v", value) } return result, nil diff --git a/pkg/morph/client/container/delete.go b/pkg/morph/client/container/delete.go index edbc82b3a..162f02329 100644 --- a/pkg/morph/client/container/delete.go +++ b/pkg/morph/client/container/delete.go @@ -1,6 +1,8 @@ package container -import "github.com/pkg/errors" +import ( + "fmt" +) // DeleteArgs groups the arguments // of delete container invocation call. @@ -25,9 +27,14 @@ func (p *DeleteArgs) SetSignature(v []byte) { // Delete invokes the call of delete container // method of NeoFS Container contract. func (c *Client) Delete(args DeleteArgs) error { - return errors.Wrapf(c.client.Invoke( + err := c.client.Invoke( c.deleteMethod, args.cid, args.sig, - ), "could not invoke method (%s)", c.deleteMethod) + ) + + if err != nil { + return fmt.Errorf("could not invoke method (%s): %w", c.deleteMethod, err) + } + return nil } diff --git a/pkg/morph/client/container/eacl.go b/pkg/morph/client/container/eacl.go index 4629d832e..ac1e02a15 100644 --- a/pkg/morph/client/container/eacl.go +++ b/pkg/morph/client/container/eacl.go @@ -1,8 +1,9 @@ package container import ( + "fmt" + "github.com/nspcc-dev/neofs-node/pkg/morph/client" - "github.com/pkg/errors" ) // EACLArgs groups the arguments @@ -51,33 +52,33 @@ func (c *Client) EACL(args EACLArgs) (*EACLValues, error) { args.cid, ) if err != nil { - return nil, errors.Wrapf(err, "could not perform test invocation (%s)", c.eaclMethod) + return nil, fmt.Errorf("could not perform test invocation (%s): %w", c.eaclMethod, err) } else if ln := len(prms); ln != 1 { - return nil, errors.Errorf("unexpected stack item count (%s): %d", c.eaclMethod, ln) + return nil, fmt.Errorf("unexpected stack item count (%s): %d", c.eaclMethod, ln) } arr, err := client.ArrayFromStackItem(prms[0]) if err != nil { - return nil, errors.Wrapf(err, "could not get item array of eACL (%s)", c.eaclMethod) + return nil, fmt.Errorf("could not get item array of eACL (%s): %w", c.eaclMethod, err) } if len(arr) != 3 { - return nil, errors.Errorf("unexpected eacl stack item count (%s): %d", c.eaclMethod, len(arr)) + return nil, fmt.Errorf("unexpected eacl stack item count (%s): %d", c.eaclMethod, len(arr)) } eacl, err := client.BytesFromStackItem(arr[0]) if err != nil { - return nil, errors.Wrapf(err, "could not get byte array of eACL (%s)", c.eaclMethod) + return nil, fmt.Errorf("could not get byte array of eACL (%s): %w", c.eaclMethod, err) } sig, err := client.BytesFromStackItem(arr[1]) if err != nil { - return nil, errors.Wrapf(err, "could not get byte array of eACL signature (%s)", c.eaclMethod) + return nil, fmt.Errorf("could not get byte array of eACL signature (%s): %w", c.eaclMethod, err) } pub, err := client.BytesFromStackItem(arr[2]) if err != nil { - return nil, errors.Wrapf(err, "could not get byte array of eACL public key (%s)", c.eaclMethod) + return nil, fmt.Errorf("could not get byte array of eACL public key (%s): %w", c.eaclMethod, err) } return &EACLValues{ diff --git a/pkg/morph/client/container/eacl_set.go b/pkg/morph/client/container/eacl_set.go index e46aba245..efedd8f9e 100644 --- a/pkg/morph/client/container/eacl_set.go +++ b/pkg/morph/client/container/eacl_set.go @@ -1,6 +1,8 @@ package container -import "github.com/pkg/errors" +import ( + "fmt" +) // SetEACLArgs groups the arguments // of set eACL invocation call. @@ -25,9 +27,14 @@ func (p *SetEACLArgs) SetSignature(v []byte) { // SetEACL invokes the call of set eACL method // of NeoFS Container contract. func (c *Client) SetEACL(args SetEACLArgs) error { - return errors.Wrapf(c.client.Invoke( + err := c.client.Invoke( c.setEACLMethod, args.eacl, args.sig, - ), "could not invoke method (%s)", c.setEACLMethod) + ) + + if err != nil { + return fmt.Errorf("could not invoke method (%s): %w", c.setEACLMethod, err) + } + return nil } diff --git a/pkg/morph/client/container/estimations.go b/pkg/morph/client/container/estimations.go index 0a03aa769..af29cf64c 100644 --- a/pkg/morph/client/container/estimations.go +++ b/pkg/morph/client/container/estimations.go @@ -1,7 +1,7 @@ package container import ( - "github.com/pkg/errors" + "fmt" ) type StartEstimation struct { @@ -21,29 +21,29 @@ func (e *StopEstimation) SetEpoch(v int64) { } func (c *Client) StartEstimation(args StartEstimation) error { - return errors.Wrapf(c.client.Invoke( - c.startEstimation, - args.epoch, - ), "could not invoke method (%s)", c.startEstimation) + if err := c.client.Invoke(c.startEstimation, args.epoch); err != nil { + return fmt.Errorf("could not invoke method (%s): %w", c.startEstimation, err) + } + return nil } func (c *Client) StartEstimationNotary(args StartEstimation) error { - return errors.Wrapf(c.client.NotaryInvoke( - c.startEstimation, - args.epoch, - ), "could not invoke method (%s)", c.startEstimation) + if err := c.client.NotaryInvoke(c.startEstimation, args.epoch); err != nil { + return fmt.Errorf("could not invoke method (%s): %w", c.startEstimation, err) + } + return nil } func (c *Client) StopEstimation(args StopEstimation) error { - return errors.Wrapf(c.client.Invoke( - c.stopEstimation, - args.epoch, - ), "could not invoke method (%s)", c.stopEstimation) + if err := c.client.Invoke(c.stopEstimation, args.epoch); err != nil { + return fmt.Errorf("could not invoke method (%s): %w", c.stopEstimation, err) + } + return nil } func (c *Client) StopEstimationNotary(args StopEstimation) error { - return errors.Wrapf(c.client.NotaryInvoke( - c.stopEstimation, - args.epoch, - ), "could not invoke method (%s)", c.stopEstimation) + if err := c.client.NotaryInvoke(c.stopEstimation, args.epoch); err != nil { + return fmt.Errorf("could not invoke method (%s): %w", c.stopEstimation, err) + } + return nil } diff --git a/pkg/morph/client/container/get.go b/pkg/morph/client/container/get.go index fa71a0d7b..bcf586806 100644 --- a/pkg/morph/client/container/get.go +++ b/pkg/morph/client/container/get.go @@ -1,8 +1,9 @@ package container import ( + "fmt" + "github.com/nspcc-dev/neofs-node/pkg/morph/client" - "github.com/pkg/errors" ) // GetArgs groups the arguments @@ -37,14 +38,14 @@ func (c *Client) Get(args GetArgs) (*GetValues, error) { args.cid, ) if err != nil { - return nil, errors.Wrapf(err, "could not perform test invocation (%s)", c.getMethod) + return nil, fmt.Errorf("could not perform test invocation (%s): %w", c.getMethod, err) } else if ln := len(prms); ln != 1 { - return nil, errors.Errorf("unexpected stack item count (%s): %d", c.getMethod, ln) + return nil, fmt.Errorf("unexpected stack item count (%s): %d", c.getMethod, ln) } cnrBytes, err := client.BytesFromStackItem(prms[0]) if err != nil { - return nil, errors.Wrapf(err, "could not get byte array from stack item (%s)", c.getMethod) + return nil, fmt.Errorf("could not get byte array from stack item (%s): %w", c.getMethod, err) } return &GetValues{ diff --git a/pkg/morph/client/container/list.go b/pkg/morph/client/container/list.go index ce1e1e0f6..abec061ae 100644 --- a/pkg/morph/client/container/list.go +++ b/pkg/morph/client/container/list.go @@ -1,8 +1,9 @@ package container import ( + "fmt" + "github.com/nspcc-dev/neofs-node/pkg/morph/client" - "github.com/pkg/errors" ) // ListArgs groups the arguments @@ -41,14 +42,14 @@ func (c *Client) List(args ListArgs) (*ListValues, error) { invokeArgs..., ) if err != nil { - return nil, errors.Wrapf(err, "could not perform test invocation (%s)", c.listMethod) + return nil, fmt.Errorf("could not perform test invocation (%s): %w", c.listMethod, err) } else if ln := len(prms); ln != 1 { - return nil, errors.Errorf("unexpected stack item count (%s): %d", c.listMethod, ln) + return nil, fmt.Errorf("unexpected stack item count (%s): %d", c.listMethod, ln) } prms, err = client.ArrayFromStackItem(prms[0]) if err != nil { - return nil, errors.Wrapf(err, "could not get stack item array from stack item (%s)", c.listMethod) + return nil, fmt.Errorf("could not get stack item array from stack item (%s): %w", c.listMethod, err) } res := &ListValues{ @@ -58,7 +59,7 @@ func (c *Client) List(args ListArgs) (*ListValues, error) { for i := range prms { cid, err := client.BytesFromStackItem(prms[i]) if err != nil { - return nil, errors.Wrapf(err, "could not get byte array from stack item (%s)", c.listMethod) + return nil, fmt.Errorf("could not get byte array from stack item (%s): %w", c.listMethod, err) } res.cidList = append(res.cidList, cid) diff --git a/pkg/morph/client/container/load.go b/pkg/morph/client/container/load.go index 00be06762..c41761759 100644 --- a/pkg/morph/client/container/load.go +++ b/pkg/morph/client/container/load.go @@ -1,8 +1,9 @@ package container import ( + "fmt" + "github.com/nspcc-dev/neofs-node/pkg/morph/client" - "github.com/pkg/errors" ) // PutSizeArgs groups the arguments @@ -43,13 +44,18 @@ func (p *PutSizeArgs) SetReporterKey(v []byte) { // Put invokes the call of put container method // of NeoFS Container contract. func (c *Client) PutSize(args PutSizeArgs) error { - return errors.Wrapf(c.client.Invoke( + err := c.client.Invoke( c.putSizeMethod, args.epoch, args.cid, args.size, args.reporterKey, - ), "could not invoke method (%s)", c.putSizeMethod) + ) + + if err != nil { + return fmt.Errorf("could not invoke method (%s): %w", c.putSizeMethod, err) + } + return nil } // ListSizesArgs groups the arguments @@ -84,14 +90,14 @@ func (c *Client) ListSizes(args ListSizesArgs) (*ListSizesValues, error) { args.epoch, ) if err != nil { - return nil, errors.Wrapf(err, "could not perform test invocation (%s)", c.listSizesMethod) + return nil, fmt.Errorf("could not perform test invocation (%s): %w", c.listSizesMethod, err) } else if ln := len(prms); ln != 1 { - return nil, errors.Errorf("unexpected stack item count (%s): %d", c.listSizesMethod, ln) + return nil, fmt.Errorf("unexpected stack item count (%s): %d", c.listSizesMethod, ln) } prms, err = client.ArrayFromStackItem(prms[0]) if err != nil { - return nil, errors.Wrapf(err, "could not get stack item array from stack item (%s)", c.listSizesMethod) + return nil, fmt.Errorf("could not get stack item array from stack item (%s): %w", c.listSizesMethod, err) } res := &ListSizesValues{ @@ -101,7 +107,7 @@ func (c *Client) ListSizes(args ListSizesArgs) (*ListSizesValues, error) { for i := range prms { id, err := client.BytesFromStackItem(prms[i]) if err != nil { - return nil, errors.Wrapf(err, "could not get ID byte array from stack item (%s)", c.listSizesMethod) + return nil, fmt.Errorf("could not get ID byte array from stack item (%s): %w", c.listSizesMethod, err) } res.ids = append(res.ids, id) @@ -152,28 +158,28 @@ func (c *Client) GetContainerSize(args GetSizeArgs) (*GetSizeValues, error) { args.id, ) if err != nil { - return nil, errors.Wrapf(err, "could not perform test invocation (%s)", c.getSizeMethod) + return nil, fmt.Errorf("could not perform test invocation (%s): %w", c.getSizeMethod, err) } else if ln := len(prms); ln != 1 { - return nil, errors.Errorf("unexpected stack item count (%s): %d", c.getSizeMethod, ln) + return nil, fmt.Errorf("unexpected stack item count (%s): %d", c.getSizeMethod, ln) } prms, err = client.ArrayFromStackItem(prms[0]) if err != nil { - return nil, errors.Wrapf(err, "could not get stack items of estimation fields from stack item (%s)", c.getSizeMethod) + return nil, fmt.Errorf("could not get stack items of estimation fields from stack item (%s): %w", c.getSizeMethod, err) } else if ln := len(prms); ln != 2 { - return nil, errors.Errorf("unexpected stack item count of estimations fields (%s)", c.getSizeMethod) + return nil, fmt.Errorf("unexpected stack item count of estimations fields (%s)", c.getSizeMethod) } es := Estimations{} es.ContainerID, err = client.BytesFromStackItem(prms[0]) if err != nil { - return nil, errors.Wrapf(err, "could not get container ID byte array from stack item (%s)", c.getSizeMethod) + return nil, fmt.Errorf("could not get container ID byte array from stack item (%s): %w", c.getSizeMethod, err) } prms, err = client.ArrayFromStackItem(prms[1]) if err != nil { - return nil, errors.Wrapf(err, "could not get estimation list array from stack item (%s)", c.getSizeMethod) + return nil, fmt.Errorf("could not get estimation list array from stack item (%s): %w", c.getSizeMethod, err) } es.Estimations = make([]Estimation, 0, len(prms)) @@ -181,21 +187,21 @@ func (c *Client) GetContainerSize(args GetSizeArgs) (*GetSizeValues, error) { for i := range prms { arr, err := client.ArrayFromStackItem(prms[i]) if err != nil { - return nil, errors.Wrapf(err, "could not get estimation struct from stack item (%s)", c.getSizeMethod) + return nil, fmt.Errorf("could not get estimation struct from stack item (%s): %w", c.getSizeMethod, err) } else if ln := len(arr); ln != 2 { - return nil, errors.Errorf("unexpected stack item count of estimation fields (%s)", c.getSizeMethod) + return nil, fmt.Errorf("unexpected stack item count of estimation fields (%s)", c.getSizeMethod) } e := Estimation{} e.Reporter, err = client.BytesFromStackItem(arr[0]) if err != nil { - return nil, errors.Wrapf(err, "could not get reporter byte array from stack item (%s)", c.getSizeMethod) + return nil, fmt.Errorf("could not get reporter byte array from stack item (%s): %w", c.getSizeMethod, err) } e.Size, err = client.IntFromStackItem(arr[1]) if err != nil { - return nil, errors.Wrapf(err, "could not get estimation size from stack item (%s)", c.getSizeMethod) + return nil, fmt.Errorf("could not get estimation size from stack item (%s): %w", c.getSizeMethod, err) } es.Estimations = append(es.Estimations, e) diff --git a/pkg/morph/client/container/put.go b/pkg/morph/client/container/put.go index 6f59ea3b2..e693977f4 100644 --- a/pkg/morph/client/container/put.go +++ b/pkg/morph/client/container/put.go @@ -1,7 +1,7 @@ package container import ( - "github.com/pkg/errors" + "fmt" ) // PutArgs groups the arguments @@ -35,10 +35,15 @@ func (p *PutArgs) SetSignature(v []byte) { // Put invokes the call of put container method // of NeoFS Container contract. func (c *Client) Put(args PutArgs) error { - return errors.Wrapf(c.client.Invoke( + err := c.client.Invoke( c.putMethod, args.cnr, args.sig, args.publicKey, - ), "could not invoke method (%s)", c.putMethod) + ) + + if err != nil { + return fmt.Errorf("could not invoke method (%s): %w", c.putMethod, err) + } + return nil } diff --git a/pkg/morph/client/container/wrapper/container.go b/pkg/morph/client/container/wrapper/container.go index aa4da0d08..5e437455a 100644 --- a/pkg/morph/client/container/wrapper/container.go +++ b/pkg/morph/client/container/wrapper/container.go @@ -2,13 +2,14 @@ package wrapper import ( "crypto/sha256" + "errors" + "fmt" "github.com/nspcc-dev/neofs-api-go/pkg/container" "github.com/nspcc-dev/neofs-api-go/pkg/owner" v2refs "github.com/nspcc-dev/neofs-api-go/v2/refs" core "github.com/nspcc-dev/neofs-node/pkg/core/container" client "github.com/nspcc-dev/neofs-node/pkg/morph/client/container" - "github.com/pkg/errors" ) var ( @@ -34,7 +35,7 @@ func (w *Wrapper) Put(cnr *container.Container, pubKey, signature []byte) (*cont data, err := cnr.Marshal() if err != nil { - return nil, errors.Wrap(err, "can't marshal container") + return nil, fmt.Errorf("can't marshal container: %w", err) } id.SetSHA256(sha256.Sum256(data)) @@ -79,7 +80,7 @@ func (w *Wrapper) Get(cid *container.ID) (*container.Container, error) { cnr := container.New() if err := cnr.Unmarshal(rpcAnswer.Container()); err != nil { // use other major version if there any - return nil, errors.Wrap(err, "can't unmarshal container") + return nil, fmt.Errorf("can't unmarshal container: %w", err) } return cnr, nil diff --git a/pkg/morph/client/container/wrapper/eacl.go b/pkg/morph/client/container/wrapper/eacl.go index df4e2ccd3..08a61622b 100644 --- a/pkg/morph/client/container/wrapper/eacl.go +++ b/pkg/morph/client/container/wrapper/eacl.go @@ -1,12 +1,13 @@ package wrapper import ( + "fmt" + "github.com/nspcc-dev/neofs-api-go/pkg" "github.com/nspcc-dev/neofs-api-go/pkg/acl/eacl" containerSDK "github.com/nspcc-dev/neofs-api-go/pkg/container" "github.com/nspcc-dev/neofs-node/pkg/core/container" client "github.com/nspcc-dev/neofs-node/pkg/morph/client/container" - "github.com/pkg/errors" ) // GetEACL reads the extended ACL table from NeoFS system @@ -65,7 +66,7 @@ func (w *Wrapper) PutEACL(table *eacl.Table, signature []byte) error { data, err := table.Marshal() if err != nil { - return errors.Wrap(err, "can't marshal eacl table") + return fmt.Errorf("can't marshal eacl table: %w", err) } args.SetEACL(data) diff --git a/pkg/morph/client/netmap/add_peer.go b/pkg/morph/client/netmap/add_peer.go index ea4a72510..6da371703 100644 --- a/pkg/morph/client/netmap/add_peer.go +++ b/pkg/morph/client/netmap/add_peer.go @@ -1,7 +1,7 @@ package netmap import ( - "github.com/pkg/errors" + "fmt" ) // AddPeerArgs groups the arguments @@ -18,10 +18,8 @@ func (a *AddPeerArgs) SetInfo(v []byte) { // AddPeer invokes the call of add peer method // of NeoFS Netmap contract. func (c *Client) AddPeer(args AddPeerArgs) error { - info := args.info - - return errors.Wrapf(c.client.Invoke( - c.addPeerMethod, - info, - ), "could not invoke method (%s)", c.addPeerMethod) + if err := c.client.Invoke(c.addPeerMethod, args.info); err != nil { + return fmt.Errorf("could not invoke method (%s): %w", c.addPeerMethod, err) + } + return nil } diff --git a/pkg/morph/client/netmap/config.go b/pkg/morph/client/netmap/config.go index 52bd1b369..33e08edc1 100644 --- a/pkg/morph/client/netmap/config.go +++ b/pkg/morph/client/netmap/config.go @@ -1,9 +1,10 @@ package netmap import ( + "fmt" + "github.com/nspcc-dev/neo-go/pkg/vm/stackitem" "github.com/nspcc-dev/neofs-node/pkg/morph/client" - "github.com/pkg/errors" ) // ConfigArgs groups the arguments @@ -36,19 +37,18 @@ func (c *Client) Config(args ConfigArgs, assert func(stackitem.Item) (interface{ args.key, ) if err != nil { - return nil, errors.Wrapf(err, - "could not perform test invocation (%s)", - c.configMethod) + return nil, fmt.Errorf("could not perform test invocation (%s): %w", + c.configMethod, err) } if ln := len(items); ln != 1 { - return nil, errors.Errorf("unexpected stack item count (%s): %d", + return nil, fmt.Errorf("unexpected stack item count (%s): %d", c.configMethod, ln) } val, err := assert(items[0]) if err != nil { - return nil, errors.Wrap(err, "value type assertion failed") + return nil, fmt.Errorf("value type assertion failed: %w", err) } return &ConfigValues{ diff --git a/pkg/morph/client/netmap/epoch.go b/pkg/morph/client/netmap/epoch.go index 070cba880..aee124498 100644 --- a/pkg/morph/client/netmap/epoch.go +++ b/pkg/morph/client/netmap/epoch.go @@ -1,8 +1,9 @@ package netmap import ( + "fmt" + "github.com/nspcc-dev/neofs-node/pkg/morph/client" - "github.com/pkg/errors" ) // EpochArgs groups the arguments @@ -28,19 +29,18 @@ func (c *Client) Epoch(_ EpochArgs) (*EpochValues, error) { c.epochMethod, ) if err != nil { - return nil, errors.Wrapf(err, - "could not perform test invocation (%s)", - c.epochMethod) + return nil, fmt.Errorf("could not perform test invocation (%s): %w", + c.epochMethod, err) } if ln := len(items); ln != 1 { - return nil, errors.Errorf("unexpected stack item count (%s): %d", + return nil, fmt.Errorf("unexpected stack item count (%s): %d", c.epochMethod, ln) } num, err := client.IntFromStackItem(items[0]) if err != nil { - return nil, errors.Wrapf(err, "could not get number from stack item (%s)", c.epochMethod) + return nil, fmt.Errorf("could not get number from stack item (%s): %w", c.epochMethod, err) } return &EpochValues{ diff --git a/pkg/morph/client/netmap/netmap.go b/pkg/morph/client/netmap/netmap.go index 043e33dd1..f75c9aba5 100644 --- a/pkg/morph/client/netmap/netmap.go +++ b/pkg/morph/client/netmap/netmap.go @@ -1,9 +1,10 @@ package netmap import ( + "fmt" + "github.com/nspcc-dev/neo-go/pkg/vm/stackitem" "github.com/nspcc-dev/neofs-node/pkg/morph/client" - "github.com/pkg/errors" ) // GetNetMapArgs groups the arguments @@ -61,9 +62,8 @@ func (c *Client) NetMap(_ GetNetMapArgs) (*GetNetMapValues, error) { c.netMapMethod, ) if err != nil { - return nil, errors.Wrapf(err, - "could not perform test invocation (%s)", - c.netMapMethod) + return nil, fmt.Errorf("could not perform test invocation (%s): %w", + c.netMapMethod, err) } return peersFromStackItems(prms, c.netMapMethod) @@ -78,9 +78,8 @@ func (c *Client) Snapshot(a GetSnapshotArgs) (*GetNetMapValues, error) { int64(a.diff), ) if err != nil { - return nil, errors.Wrapf(err, - "could not perform test invocation (%s)", - c.netMapMethod) + return nil, fmt.Errorf("could not perform test invocation (%s): %w", + c.netMapMethod, err) } return peersFromStackItems(prms, c.snapshotMethod) @@ -94,9 +93,8 @@ func (c *Client) EpochSnapshot(args EpochSnapshotArgs) (*EpochSnapshotValues, er int64(args.epoch), ) if err != nil { - return nil, errors.Wrapf(err, - "could not perform test invocation (%s)", - c.epochSnapshotMethod) + return nil, fmt.Errorf("could not perform test invocation (%s): %w", + c.epochSnapshotMethod, err) } nmVals, err := peersFromStackItems(prms, c.epochSnapshotMethod) @@ -111,15 +109,14 @@ func (c *Client) EpochSnapshot(args EpochSnapshotArgs) (*EpochSnapshotValues, er func peersFromStackItems(stack []stackitem.Item, method string) (*GetNetMapValues, error) { if ln := len(stack); ln != 1 { - return nil, errors.Errorf("unexpected stack item count (%s): %d", + return nil, fmt.Errorf("unexpected stack item count (%s): %d", method, ln) } peers, err := client.ArrayFromStackItem(stack[0]) if err != nil { - return nil, errors.Wrapf(err, - "could not get stack item array from stack item (%s)", - method) + return nil, fmt.Errorf("could not get stack item array from stack item (%s): %w", + method, err) } res := &GetNetMapValues{ @@ -129,8 +126,7 @@ func peersFromStackItems(stack []stackitem.Item, method string) (*GetNetMapValue for i := range peers { peer, err := peerInfoFromStackItem(peers[i]) if err != nil { - return nil, errors.Wrapf(err, - "could not parse stack item (Peer #%d)", i) + return nil, fmt.Errorf("could not parse stack item (Peer #%d): %w", i, err) } res.peers = append(res.peers, peer) @@ -142,9 +138,9 @@ func peersFromStackItems(stack []stackitem.Item, method string) (*GetNetMapValue func peerInfoFromStackItem(prm stackitem.Item) ([]byte, error) { prms, err := client.ArrayFromStackItem(prm) if err != nil { - return nil, errors.Wrapf(err, "could not get stack item array (PeerInfo)") + return nil, fmt.Errorf("could not get stack item array (PeerInfo): %w", err) } else if ln := len(prms); ln != nodeInfoFixedPrmNumber { - return nil, errors.Errorf("unexpected stack item count (PeerInfo): expected %d, has %d", 1, ln) + return nil, fmt.Errorf("unexpected stack item count (PeerInfo): expected %d, has %d", 1, ln) } return client.BytesFromStackItem(prms[0]) diff --git a/pkg/morph/client/netmap/new_epoch.go b/pkg/morph/client/netmap/new_epoch.go index 671901792..d09c13521 100644 --- a/pkg/morph/client/netmap/new_epoch.go +++ b/pkg/morph/client/netmap/new_epoch.go @@ -1,6 +1,8 @@ package netmap -import "github.com/pkg/errors" +import ( + "fmt" +) // NewEpochArgs groups the arguments // of new epoch invocation call. @@ -16,8 +18,8 @@ func (a *NewEpochArgs) SetEpochNumber(v int64) { // NewEpoch invokes the call of new epoch method // of NeoFS Netmap contract. func (c *Client) NewEpoch(args NewEpochArgs) error { - return errors.Wrapf(c.client.Invoke( - c.addPeerMethod, - args.number, - ), "could not invoke method (%s)", c.newEpochMethod) + if err := c.client.Invoke(c.addPeerMethod, args.number); err != nil { + return fmt.Errorf("could not invoke method (%s): %w", c.newEpochMethod, err) + } + return nil } diff --git a/pkg/morph/client/netmap/update_state.go b/pkg/morph/client/netmap/update_state.go index ad50d7d0b..0045a0ce6 100644 --- a/pkg/morph/client/netmap/update_state.go +++ b/pkg/morph/client/netmap/update_state.go @@ -1,7 +1,7 @@ package netmap import ( - "github.com/pkg/errors" + "fmt" ) // UpdateStateArgs groups the arguments @@ -26,9 +26,15 @@ func (u *UpdateStateArgs) SetState(v int64) { // UpdateState invokes the call of update state method // of NeoFS Netmap contract. func (c *Client) UpdateState(args UpdateStateArgs) error { - return errors.Wrapf(c.client.Invoke( + err := c.client.Invoke( c.updateStateMethod, args.state, args.key, - ), "could not invoke method (%s)", c.updateStateMethod) + ) + + if err != nil { + return fmt.Errorf("could not invoke method (%s): %w", c.updateStateMethod, err) + } + + return nil } diff --git a/pkg/morph/client/netmap/wrapper/add_peer.go b/pkg/morph/client/netmap/wrapper/add_peer.go index cc2470850..10f810b68 100644 --- a/pkg/morph/client/netmap/wrapper/add_peer.go +++ b/pkg/morph/client/netmap/wrapper/add_peer.go @@ -1,8 +1,10 @@ package wrapper import ( + "errors" + "fmt" + "github.com/nspcc-dev/neofs-node/pkg/morph/client/netmap" - "github.com/pkg/errors" ) // AddPeer registers peer in NeoFS network through @@ -20,8 +22,8 @@ func (w *Wrapper) AddPeer(nodeInfo *netmap.NodeInfo) error { args := netmap.AddPeerArgs{} args.SetInfo(rawNodeInfo) - return errors.Wrap( - w.client.AddPeer(args), - "could not invoke smart contract", - ) + if err := w.client.AddPeer(args); err != nil { + return fmt.Errorf("could not invoke smart contract: %w", err) + } + return nil } diff --git a/pkg/morph/client/netmap/wrapper/config.go b/pkg/morph/client/netmap/wrapper/config.go index b74cc99d3..6270b1b36 100644 --- a/pkg/morph/client/netmap/wrapper/config.go +++ b/pkg/morph/client/netmap/wrapper/config.go @@ -1,10 +1,10 @@ package wrapper import ( + "fmt" "strconv" "github.com/nspcc-dev/neofs-node/pkg/morph/client/netmap" - "github.com/pkg/errors" ) const ( @@ -24,7 +24,7 @@ const ( func (w *Wrapper) MaxObjectSize() (uint64, error) { objectSize, err := w.readUInt64Config(maxObjectSizeConfig) if err != nil { - return 0, errors.Wrapf(err, "(%T) could not get epoch number", w) + return 0, fmt.Errorf("(%T) could not get epoch number: %w", w, err) } return objectSize, nil @@ -35,7 +35,7 @@ func (w *Wrapper) MaxObjectSize() (uint64, error) { func (w *Wrapper) BasicIncomeRate() (uint64, error) { rate, err := w.readUInt64Config(basicIncomeRateConfig) if err != nil { - return 0, errors.Wrapf(err, "(%T) could not get basic income rate", w) + return 0, fmt.Errorf("(%T) could not get basic income rate: %w", w, err) } return rate, nil @@ -46,7 +46,7 @@ func (w *Wrapper) BasicIncomeRate() (uint64, error) { func (w *Wrapper) AuditFee() (uint64, error) { fee, err := w.readUInt64Config(auditFeeConfig) if err != nil { - return 0, errors.Wrapf(err, "(%T) could not get audit fee", w) + return 0, fmt.Errorf("(%T) could not get audit fee: %w", w, err) } return fee, nil @@ -56,7 +56,7 @@ func (w *Wrapper) AuditFee() (uint64, error) { func (w *Wrapper) EpochDuration() (uint64, error) { epochDuration, err := w.readUInt64Config(epochDurationConfig) if err != nil { - return 0, errors.Wrapf(err, "(%T) could not get epoch duration", w) + return 0, fmt.Errorf("(%T) could not get epoch duration: %w", w, err) } return epochDuration, nil @@ -67,7 +67,7 @@ func (w *Wrapper) EpochDuration() (uint64, error) { func (w *Wrapper) ContainerFee() (uint64, error) { fee, err := w.readUInt64Config(containerFeeConfig) if err != nil { - return 0, errors.Wrapf(err, "(%T) could not get container fee", w) + return 0, fmt.Errorf("(%T) could not get container fee: %w", w, err) } return fee, nil @@ -78,7 +78,7 @@ func (w *Wrapper) ContainerFee() (uint64, error) { func (w *Wrapper) EigenTrustIterations() (uint64, error) { iterations, err := w.readUInt64Config(etIterationsConfig) if err != nil { - return 0, errors.Wrapf(err, "(%T) could not get eigen trust iterations", w) + return 0, fmt.Errorf("(%T) could not get eigen trust iterations: %w", w, err) } return iterations, nil @@ -89,7 +89,7 @@ func (w *Wrapper) EigenTrustIterations() (uint64, error) { func (w *Wrapper) EigenTrustAlpha() (float64, error) { strAlpha, err := w.readStringConfig(etAlphaConfig) if err != nil { - return 0, errors.Wrapf(err, "(%T) could not get eigen trust alpha", w) + return 0, fmt.Errorf("(%T) could not get eigen trust alpha: %w", w, err) } return strconv.ParseFloat(strAlpha, 64) @@ -100,7 +100,7 @@ func (w *Wrapper) EigenTrustAlpha() (float64, error) { func (w *Wrapper) InnerRingCandidateFee() (uint64, error) { fee, err := w.readUInt64Config(irCandidateFeeConfig) if err != nil { - return 0, errors.Wrapf(err, "(%T) could not get inner ring candidate fee", w) + return 0, fmt.Errorf("(%T) could not get inner ring candidate fee: %w", w, err) } return fee, nil @@ -111,7 +111,7 @@ func (w *Wrapper) InnerRingCandidateFee() (uint64, error) { func (w *Wrapper) WithdrawFee() (uint64, error) { fee, err := w.readUInt64Config(withdrawFeeConfig) if err != nil { - return 0, errors.Wrapf(err, "(%T) could not get withdraw fee", w) + return 0, fmt.Errorf("(%T) could not get withdraw fee: %w", w, err) } return fee, nil @@ -130,7 +130,7 @@ func (w *Wrapper) readUInt64Config(key string) (uint64, error) { numeric, ok := v.(int64) if !ok { - return 0, errors.Errorf("(%T) invalid value type %T", w, v) + return 0, fmt.Errorf("(%T) invalid value type %T", w, v) } return uint64(numeric), nil @@ -149,7 +149,7 @@ func (w *Wrapper) readStringConfig(key string) (string, error) { str, ok := v.(string) if !ok { - return "", errors.Errorf("(%T) invalid value type %T", w, v) + return "", fmt.Errorf("(%T) invalid value type %T", w, v) } return str, nil diff --git a/pkg/morph/client/netmap/wrapper/epoch.go b/pkg/morph/client/netmap/wrapper/epoch.go index 9bfe3360d..9f30d852a 100644 --- a/pkg/morph/client/netmap/wrapper/epoch.go +++ b/pkg/morph/client/netmap/wrapper/epoch.go @@ -1,8 +1,9 @@ package wrapper import ( + "fmt" + "github.com/nspcc-dev/neofs-node/pkg/morph/client/netmap" - "github.com/pkg/errors" ) // Epoch receives number of current NeoFS epoch @@ -12,7 +13,7 @@ func (w *Wrapper) Epoch() (uint64, error) { vals, err := w.client.Epoch(args) if err != nil { - return 0, errors.Wrapf(err, "(%T) could not get epoch number", w) + return 0, fmt.Errorf("(%T) could not get epoch number: %w", w, err) } return uint64(vals.Number()), nil diff --git a/pkg/morph/client/netmap/wrapper/netmap.go b/pkg/morph/client/netmap/wrapper/netmap.go index fb96a64ae..a8e99ab18 100644 --- a/pkg/morph/client/netmap/wrapper/netmap.go +++ b/pkg/morph/client/netmap/wrapper/netmap.go @@ -1,9 +1,10 @@ package wrapper import ( + "fmt" + "github.com/nspcc-dev/neofs-api-go/pkg/netmap" client "github.com/nspcc-dev/neofs-node/pkg/morph/client/netmap" - "github.com/pkg/errors" ) // GetNetMap receives information list about storage nodes @@ -43,7 +44,7 @@ func unmarshalNetmap(rawPeers [][]byte) (*netmap.Netmap, error) { for _, peer := range rawPeers { nodeInfo := netmap.NewNodeInfo() if err := nodeInfo.Unmarshal(peer); err != nil { - return nil, errors.Wrap(err, "can't unmarshal peer info") + return nil, fmt.Errorf("can't unmarshal peer info: %w", err) } infos = append(infos, *nodeInfo) diff --git a/pkg/morph/client/netmap/wrapper/update_state.go b/pkg/morph/client/netmap/wrapper/update_state.go index 70902bb32..df712af39 100644 --- a/pkg/morph/client/netmap/wrapper/update_state.go +++ b/pkg/morph/client/netmap/wrapper/update_state.go @@ -1,9 +1,10 @@ package wrapper import ( + "fmt" + "github.com/nspcc-dev/neofs-api-go/pkg/netmap" contract "github.com/nspcc-dev/neofs-node/pkg/morph/client/netmap" - "github.com/pkg/errors" ) // UpdatePeerState changes peer status through Netmap contract @@ -14,10 +15,8 @@ func (w *Wrapper) UpdatePeerState(key []byte, state netmap.NodeState) error { args.SetState(int64(state.ToV2())) // invoke smart contract call - // - // Note: errors.Wrap returns nil on nil error arg. - return errors.Wrap( - w.client.UpdateState(args), - "could not invoke smart contract", - ) + if err := w.client.UpdateState(args); err != nil { + return fmt.Errorf("could not invoke smart contract: %w", err) + } + return nil } diff --git a/pkg/morph/client/notary.go b/pkg/morph/client/notary.go index cb55995c1..04fc8dfc8 100644 --- a/pkg/morph/client/notary.go +++ b/pkg/morph/client/notary.go @@ -1,6 +1,8 @@ package client import ( + "errors" + "fmt" "strings" "github.com/nspcc-dev/neo-go/pkg/core/native/nativenames" @@ -13,7 +15,6 @@ import ( "github.com/nspcc-dev/neo-go/pkg/util" "github.com/nspcc-dev/neo-go/pkg/vm/opcode" "github.com/nspcc-dev/neo-go/pkg/wallet" - "github.com/pkg/errors" "go.uber.org/zap" ) @@ -74,7 +75,7 @@ func (c *Client) EnableNotarySupport(proxy util.Uint160, opts ...NotaryOption) e notaryContract, err := c.client.GetNativeContractHash(nativenames.Notary) if err != nil { - return errors.Wrap(err, "can't get notary contract script hash") + return fmt.Errorf("can't get notary contract script hash: %w", err) } c.notary = ¬ary{ @@ -110,7 +111,7 @@ func (c *Client) DepositNotary(amount fixedn.Fixed8, delta uint32) (util.Uint256 bc, err := c.client.GetBlockCount() if err != nil { - return util.Uint256{}, errors.Wrap(err, "can't get blockchain height") + return util.Uint256{}, fmt.Errorf("can't get blockchain height: %w", err) } txHash, err := c.client.TransferNEP17( @@ -123,7 +124,7 @@ func (c *Client) DepositNotary(amount fixedn.Fixed8, delta uint32) (util.Uint256 nil, ) if err != nil { - return util.Uint256{}, errors.Wrap(err, "can't make notary deposit") + return util.Uint256{}, fmt.Errorf("can't make notary deposit: %w", err) } c.logger.Debug("notary deposit invoke", @@ -148,16 +149,16 @@ func (c *Client) GetNotaryDeposit() (int64, error) { items, err := c.TestInvoke(c.notary.notary, notaryBalanceOfMethod, sh) if err != nil { - return 0, errors.Wrap(err, notaryBalanceErrMsg) + return 0, fmt.Errorf("%v: %w", notaryBalanceErrMsg, err) } if len(items) != 1 { - return 0, errors.Wrap(errUnexpectedItems, notaryBalanceErrMsg) + return 0, fmt.Errorf("%v: %w", notaryBalanceErrMsg, errUnexpectedItems) } bigIntDeposit, err := items[0].TryInteger() if err != nil { - return 0, errors.Wrap(err, notaryBalanceErrMsg) + return 0, fmt.Errorf("%v: %w", notaryBalanceErrMsg, err) } return bigIntDeposit.Int64(), nil @@ -328,7 +329,7 @@ func (c *Client) notaryCosigners(ir []*keys.PublicKey, committee bool) ([]transa multisigScript, err := sc.CreateMultiSigRedeemScript(m, ir) if err != nil { - return nil, errors.Wrap(err, "can't create ir multisig redeem script") + return nil, fmt.Errorf("can't create ir multisig redeem script: %w", err) } s = append(s, transaction.Signer{ @@ -412,7 +413,7 @@ func (c *Client) notaryMultisigAccount(ir []*keys.PublicKey, committee bool) (*w err := multisigAccount.ConvertMultisig(m, ir) if err != nil { - return nil, errors.Wrap(err, "can't make inner ring multisig wallet") + return nil, fmt.Errorf("can't make inner ring multisig wallet: %w", err) } return multisigAccount, nil @@ -421,7 +422,7 @@ func (c *Client) notaryMultisigAccount(ir []*keys.PublicKey, committee bool) (*w func (c *Client) notaryTxValidationLimit() (uint32, error) { bc, err := c.client.GetBlockCount() if err != nil { - return 0, errors.Wrap(err, "can't get current blockchain height") + return 0, fmt.Errorf("can't get current blockchain height: %w", err) } min := bc + c.notary.txValidTime diff --git a/pkg/morph/client/reputation/get.go b/pkg/morph/client/reputation/get.go index c04f05b6c..37606bd25 100644 --- a/pkg/morph/client/reputation/get.go +++ b/pkg/morph/client/reputation/get.go @@ -1,9 +1,10 @@ package reputation import ( + "fmt" + "github.com/nspcc-dev/neo-go/pkg/vm/stackitem" "github.com/nspcc-dev/neofs-node/pkg/morph/client" - "github.com/pkg/errors" ) // GetArgs groups the arguments of "get reputation value" test invocation. @@ -52,7 +53,7 @@ func (c *Client) Get(args GetArgs) (*GetResult, error) { args.peerID, ) if err != nil { - return nil, errors.Wrapf(err, "could not perform test invocation (%s)", c.getMethod) + return nil, fmt.Errorf("could not perform test invocation (%s): %w", c.getMethod, err) } return parseReputations(prms, c.getMethod) @@ -66,7 +67,7 @@ func (c *Client) GetByID(args GetByIDArgs) (*GetResult, error) { args.id, ) if err != nil { - return nil, errors.Wrapf(err, "could not perform test invocation (%s)", c.getByIDMethod) + return nil, fmt.Errorf("could not perform test invocation (%s): %w", c.getByIDMethod, err) } return parseReputations(prms, c.getByIDMethod) @@ -74,12 +75,12 @@ func (c *Client) GetByID(args GetByIDArgs) (*GetResult, error) { func parseReputations(items []stackitem.Item, method string) (*GetResult, error) { if ln := len(items); ln != 1 { - return nil, errors.Errorf("unexpected stack item count (%s): %d", method, ln) + return nil, fmt.Errorf("unexpected stack item count (%s): %d", method, ln) } items, err := client.ArrayFromStackItem(items[0]) if err != nil { - return nil, errors.Wrapf(err, "could not get stack item array from stack item (%s)", method) + return nil, fmt.Errorf("could not get stack item array from stack item (%s): %w", method, err) } res := &GetResult{ @@ -89,7 +90,7 @@ func parseReputations(items []stackitem.Item, method string) (*GetResult, error) for i := range items { rawReputation, err := client.BytesFromStackItem(items[i]) if err != nil { - return nil, errors.Wrapf(err, "could not get byte array from stack item (%s)", method) + return nil, fmt.Errorf("could not get byte array from stack item (%s): %w", method, err) } res.reputations = append(res.reputations, rawReputation) diff --git a/pkg/morph/client/reputation/list.go b/pkg/morph/client/reputation/list.go index 89ddfdf67..53704f5e6 100644 --- a/pkg/morph/client/reputation/list.go +++ b/pkg/morph/client/reputation/list.go @@ -1,8 +1,9 @@ package reputation import ( + "fmt" + "github.com/nspcc-dev/neofs-node/pkg/morph/client" - "github.com/pkg/errors" ) // ListByEpochArgs groups the arguments of @@ -35,14 +36,14 @@ func (c *Client) ListByEpoch(args ListByEpochArgs) (*ListByEpochResult, error) { int64(args.epoch), ) if err != nil { - return nil, errors.Wrapf(err, "could not perform test invocation (%s)", c.listByEpochMethod) + return nil, fmt.Errorf("could not perform test invocation (%s): %w", c.listByEpochMethod, err) } else if ln := len(prms); ln != 1 { - return nil, errors.Errorf("unexpected stack item count (%s): %d", c.listByEpochMethod, ln) + return nil, fmt.Errorf("unexpected stack item count (%s): %d", c.listByEpochMethod, ln) } items, err := client.ArrayFromStackItem(prms[0]) if err != nil { - return nil, errors.Wrapf(err, "could not get stack item array from stack item (%s)", c.listByEpochMethod) + return nil, fmt.Errorf("could not get stack item array from stack item (%s): %w", c.listByEpochMethod, err) } res := &ListByEpochResult{ @@ -52,7 +53,7 @@ func (c *Client) ListByEpoch(args ListByEpochArgs) (*ListByEpochResult, error) { for i := range items { rawReputation, err := client.BytesFromStackItem(items[i]) if err != nil { - return nil, errors.Wrapf(err, "could not get byte array from stack item (%s)", c.listByEpochMethod) + return nil, fmt.Errorf("could not get byte array from stack item (%s): %w", c.listByEpochMethod, err) } res.ids = append(res.ids, rawReputation) diff --git a/pkg/morph/client/reputation/put.go b/pkg/morph/client/reputation/put.go index dfd6d29ad..5ab19b606 100644 --- a/pkg/morph/client/reputation/put.go +++ b/pkg/morph/client/reputation/put.go @@ -1,7 +1,7 @@ package reputation import ( - "github.com/pkg/errors" + "fmt" ) // PutArgs groups the arguments of "put reputation value" invocation call. @@ -28,21 +28,31 @@ func (p *PutArgs) SetValue(v []byte) { // Put invokes direct call of "put reputation value" method of reputation contract. func (c *Client) Put(args PutArgs) error { - return errors.Wrapf(c.client.Invoke( + err := c.client.Invoke( c.putMethod, int64(args.epoch), args.peerID, args.value, - ), "could not invoke method (%s)", c.putMethod) + ) + + if err != nil { + return fmt.Errorf("could not invoke method (%s): %w", c.putMethod, err) + } + return nil } // PutViaNotary invokes notary call of "put reputation value" method of // reputation contract. func (c *Client) PutViaNotary(args PutArgs) error { - return errors.Wrapf(c.client.NotaryInvoke( + err := c.client.NotaryInvoke( c.putMethod, int64(args.epoch), args.peerID, args.value, - ), "could not invoke method (%s)", c.putMethod) + ) + + if err != nil { + return fmt.Errorf("could not invoke method (%s): %w", c.putMethod, err) + } + return err } diff --git a/pkg/morph/client/reputation/wrapper/get.go b/pkg/morph/client/reputation/wrapper/get.go index 06cdc338f..4f4219a5b 100644 --- a/pkg/morph/client/reputation/wrapper/get.go +++ b/pkg/morph/client/reputation/wrapper/get.go @@ -1,9 +1,10 @@ package wrapper import ( + "fmt" + "github.com/nspcc-dev/neofs-api-go/pkg/reputation" reputationClient "github.com/nspcc-dev/neofs-node/pkg/morph/client/reputation" - "github.com/pkg/errors" ) type ( @@ -83,7 +84,7 @@ func parseGetResult(data *reputationClient.GetResult) (*GetResult, error) { err := r.Unmarshal(rawReputations[i]) if err != nil { - return nil, errors.Wrap(err, "can't unmarshal global trust value") + return nil, fmt.Errorf("can't unmarshal global trust value: %w", err) } reputations = append(reputations, r) diff --git a/pkg/morph/client/reputation/wrapper/put.go b/pkg/morph/client/reputation/wrapper/put.go index cf79fa4e6..5be9712c7 100644 --- a/pkg/morph/client/reputation/wrapper/put.go +++ b/pkg/morph/client/reputation/wrapper/put.go @@ -1,9 +1,10 @@ package wrapper import ( + "fmt" + "github.com/nspcc-dev/neofs-api-go/pkg/reputation" reputationClient "github.com/nspcc-dev/neofs-node/pkg/morph/client/reputation" - "github.com/pkg/errors" ) type ( @@ -56,7 +57,7 @@ func preparePutArgs(v PutArgs) (reputationClient.PutArgs, error) { data, err := v.value.Marshal() if err != nil { - return args, errors.Wrap(err, "can't marshal global trust value") + return args, fmt.Errorf("can't marshal global trust value: %w", err) } args.SetEpoch(v.epoch) diff --git a/pkg/morph/client/util.go b/pkg/morph/client/util.go index 883614242..1e18d68b3 100644 --- a/pkg/morph/client/util.go +++ b/pkg/morph/client/util.go @@ -1,10 +1,10 @@ package client import ( + "fmt" "math/big" "github.com/nspcc-dev/neo-go/pkg/vm/stackitem" - "github.com/pkg/errors" ) /* @@ -19,7 +19,7 @@ func BoolFromStackItem(param stackitem.Item) (bool, error) { case stackitem.BooleanT, stackitem.IntegerT, stackitem.ByteArrayT: return param.TryBool() default: - return false, errors.Errorf("chain/client: %s is not a bool type", param.Type()) + return false, fmt.Errorf("chain/client: %s is not a bool type", param.Type()) } } @@ -34,7 +34,7 @@ func IntFromStackItem(param stackitem.Item) (int64, error) { return i.Int64(), nil default: - return 0, errors.Errorf("chain/client: %s is not an integer type", param.Type()) + return 0, fmt.Errorf("chain/client: %s is not an integer type", param.Type()) } } @@ -51,7 +51,7 @@ func BytesFromStackItem(param stackitem.Item) ([]byte, error) { case stackitem.IntegerT: n, err := param.TryInteger() if err != nil { - return nil, errors.Wrap(err, "can't parse integer bytes") + return nil, fmt.Errorf("can't parse integer bytes: %w", err) } return n.Bytes(), nil @@ -61,7 +61,7 @@ func BytesFromStackItem(param stackitem.Item) ([]byte, error) { } fallthrough default: - return nil, errors.Errorf("chain/client: %s is not a byte array type", param.Type()) + return nil, fmt.Errorf("chain/client: %s is not a byte array type", param.Type()) } } @@ -75,19 +75,19 @@ func ArrayFromStackItem(param stackitem.Item) ([]stackitem.Item, error) { case stackitem.ArrayT, stackitem.StructT: items, ok := param.Value().([]stackitem.Item) if !ok { - return nil, errors.Errorf("chain/client: can't convert %T to parameter slice", param.Value()) + return nil, fmt.Errorf("chain/client: can't convert %T to parameter slice", param.Value()) } return items, nil default: - return nil, errors.Errorf("chain/client: %s is not an array type", param.Type()) + return nil, fmt.Errorf("chain/client: %s is not an array type", param.Type()) } } // StringFromStackItem receives string value from the value of a smart contract parameter. func StringFromStackItem(param stackitem.Item) (string, error) { if param.Type() != stackitem.ByteArrayT { - return "", errors.Errorf("chain/client: %s is not an string type", param.Type()) + return "", fmt.Errorf("chain/client: %s is not an string type", param.Type()) } return stackitem.ToString(param) diff --git a/pkg/morph/event/balance/lock.go b/pkg/morph/event/balance/lock.go index 2128e18a2..9acb5ad51 100644 --- a/pkg/morph/event/balance/lock.go +++ b/pkg/morph/event/balance/lock.go @@ -1,11 +1,12 @@ package balance import ( + "fmt" + "github.com/nspcc-dev/neo-go/pkg/util" "github.com/nspcc-dev/neo-go/pkg/vm/stackitem" "github.com/nspcc-dev/neofs-node/pkg/morph/client" "github.com/nspcc-dev/neofs-node/pkg/morph/event" - "github.com/pkg/errors" ) // Lock structure of balance.Lock notification from morph chain. @@ -49,41 +50,41 @@ func ParseLock(params []stackitem.Item) (event.Event, error) { // parse id ev.id, err = client.BytesFromStackItem(params[0]) if err != nil { - return nil, errors.Wrap(err, "could not get lock id") + return nil, fmt.Errorf("could not get lock id: %w", err) } // parse user user, err := client.BytesFromStackItem(params[1]) if err != nil { - return nil, errors.Wrap(err, "could not get lock user value") + return nil, fmt.Errorf("could not get lock user value: %w", err) } ev.user, err = util.Uint160DecodeBytesBE(user) if err != nil { - return nil, errors.Wrap(err, "could not convert lock user value to uint160") + return nil, fmt.Errorf("could not convert lock user value to uint160: %w", err) } // parse lock account lock, err := client.BytesFromStackItem(params[2]) if err != nil { - return nil, errors.Wrap(err, "could not get lock account value") + return nil, fmt.Errorf("could not get lock account value: %w", err) } ev.lock, err = util.Uint160DecodeBytesBE(lock) if err != nil { - return nil, errors.Wrap(err, "could not convert lock account value to uint160") + return nil, fmt.Errorf("could not convert lock account value to uint160: %w", err) } // parse amount ev.amount, err = client.IntFromStackItem(params[3]) if err != nil { - return nil, errors.Wrap(err, "could not get lock amount") + return nil, fmt.Errorf("could not get lock amount: %w", err) } // parse until deadline ev.until, err = client.IntFromStackItem(params[4]) if err != nil { - return nil, errors.Wrap(err, "could not get lock deadline") + return nil, fmt.Errorf("could not get lock deadline: %w", err) } return ev, nil diff --git a/pkg/morph/event/container/delete.go b/pkg/morph/event/container/delete.go index cc0c0d3a6..56fc7be03 100644 --- a/pkg/morph/event/container/delete.go +++ b/pkg/morph/event/container/delete.go @@ -1,10 +1,11 @@ package container import ( + "fmt" + "github.com/nspcc-dev/neo-go/pkg/vm/stackitem" "github.com/nspcc-dev/neofs-node/pkg/morph/client" "github.com/nspcc-dev/neofs-node/pkg/morph/event" - "github.com/pkg/errors" ) // Delete structure of container.Delete notification from morph chain. @@ -36,13 +37,13 @@ func ParseDelete(params []stackitem.Item) (event.Event, error) { // parse container ev.containerID, err = client.BytesFromStackItem(params[0]) if err != nil { - return nil, errors.Wrap(err, "could not get container") + return nil, fmt.Errorf("could not get container: %w", err) } // parse signature ev.signature, err = client.BytesFromStackItem(params[1]) if err != nil { - return nil, errors.Wrap(err, "could not get signature") + return nil, fmt.Errorf("could not get signature: %w", err) } return ev, nil diff --git a/pkg/morph/event/container/estimates.go b/pkg/morph/event/container/estimates.go index fbe88175f..b3e7b0746 100644 --- a/pkg/morph/event/container/estimates.go +++ b/pkg/morph/event/container/estimates.go @@ -1,10 +1,11 @@ package container import ( + "fmt" + "github.com/nspcc-dev/neo-go/pkg/vm/stackitem" "github.com/nspcc-dev/neofs-node/pkg/morph/client" "github.com/nspcc-dev/neofs-node/pkg/morph/event" - "github.com/pkg/errors" ) // StartEstimation structure of container.StartEstimation notification from @@ -59,7 +60,7 @@ func parseEstimation(params []stackitem.Item) (uint64, error) { // parse container epoch, err := client.IntFromStackItem(params[0]) if err != nil { - return 0, errors.Wrap(err, "could not get estimation epoch") + return 0, fmt.Errorf("could not get estimation epoch: %w", err) } return uint64(epoch), nil diff --git a/pkg/morph/event/container/put.go b/pkg/morph/event/container/put.go index 7f0f51480..094dc77a8 100644 --- a/pkg/morph/event/container/put.go +++ b/pkg/morph/event/container/put.go @@ -2,12 +2,12 @@ package container import ( "crypto/elliptic" + "fmt" "github.com/nspcc-dev/neo-go/pkg/crypto/keys" "github.com/nspcc-dev/neo-go/pkg/vm/stackitem" "github.com/nspcc-dev/neofs-node/pkg/morph/client" "github.com/nspcc-dev/neofs-node/pkg/morph/event" - "github.com/pkg/errors" ) // Put structure of container.Put notification from morph chain. @@ -43,24 +43,24 @@ func ParsePut(params []stackitem.Item) (event.Event, error) { // parse container ev.rawContainer, err = client.BytesFromStackItem(params[0]) if err != nil { - return nil, errors.Wrap(err, "could not get container") + return nil, fmt.Errorf("could not get container: %w", err) } // parse signature ev.signature, err = client.BytesFromStackItem(params[1]) if err != nil { - return nil, errors.Wrap(err, "could not get signature") + return nil, fmt.Errorf("could not get signature: %w", err) } // parse public key key, err := client.BytesFromStackItem(params[2]) if err != nil { - return nil, errors.Wrap(err, "could not get public key") + return nil, fmt.Errorf("could not get public key: %w", err) } ev.publicKey, err = keys.NewPublicKeyFromBytes(key, elliptic.P256()) if err != nil { - return nil, errors.Wrap(err, "could not parse public key") + return nil, fmt.Errorf("could not parse public key: %w", err) } return ev, nil diff --git a/pkg/morph/event/listener.go b/pkg/morph/event/listener.go index 615bd8048..1377ab21c 100644 --- a/pkg/morph/event/listener.go +++ b/pkg/morph/event/listener.go @@ -2,6 +2,8 @@ package event import ( "context" + "errors" + "fmt" "sync" "github.com/nspcc-dev/neo-go/pkg/core/block" @@ -9,7 +11,6 @@ import ( "github.com/nspcc-dev/neo-go/pkg/util" "github.com/nspcc-dev/neofs-node/pkg/morph/client" "github.com/nspcc-dev/neofs-node/pkg/morph/subscriber" - "github.com/pkg/errors" "go.uber.org/zap" ) @@ -160,7 +161,7 @@ func (s listener) listenLoop(ctx context.Context, chEvent <-chan *state.Notifica var err error if blockChan, err = s.subscriber.BlockNotifications(); err != nil { if intErr != nil { - intErr <- errors.Wrap(err, "could not open block notifications channel") + intErr <- fmt.Errorf("could not open block notifications channel: %w", err) } else { s.log.Debug("could not open block notifications channel", zap.String("error", err.Error()), @@ -372,9 +373,9 @@ func (s *listener) RegisterBlockHandler(handler BlockHandler) { func NewListener(p ListenerParams) (Listener, error) { switch { case p.Logger == nil: - return nil, errors.Wrap(errNilLogger, newListenerFailMsg) + return nil, fmt.Errorf("%s: %w", newListenerFailMsg, errNilLogger) case p.Subscriber == nil: - return nil, errors.Wrap(errNilSubscriber, newListenerFailMsg) + return nil, fmt.Errorf("%s: %w", newListenerFailMsg, errNilSubscriber) } return &listener{ diff --git a/pkg/morph/event/neofs/bind.go b/pkg/morph/event/neofs/bind.go index 34161e3cb..29b122c07 100644 --- a/pkg/morph/event/neofs/bind.go +++ b/pkg/morph/event/neofs/bind.go @@ -2,13 +2,13 @@ package neofs import ( "crypto/elliptic" + "fmt" "github.com/nspcc-dev/neo-go/pkg/crypto/keys" "github.com/nspcc-dev/neo-go/pkg/util" "github.com/nspcc-dev/neo-go/pkg/vm/stackitem" "github.com/nspcc-dev/neofs-node/pkg/morph/client" "github.com/nspcc-dev/neofs-node/pkg/morph/event" - "github.com/pkg/errors" ) type Bind struct { @@ -36,30 +36,30 @@ func ParseBind(params []stackitem.Item) (event.Event, error) { // parse user user, err := client.BytesFromStackItem(params[0]) if err != nil { - return nil, errors.Wrap(err, "could not get bind user") + return nil, fmt.Errorf("could not get bind user: %w", err) } ev.user, err = util.Uint160DecodeBytesBE(user) if err != nil { - return nil, errors.Wrap(err, "could not convert bind user to uint160") + return nil, fmt.Errorf("could not convert bind user to uint160: %w", err) } // parse keys bindKeys, err := client.ArrayFromStackItem(params[1]) if err != nil { - return nil, errors.Wrap(err, "could not get bind keys") + return nil, fmt.Errorf("could not get bind keys: %w", err) } ev.keys = make([]*keys.PublicKey, 0, len(bindKeys)) for i := range bindKeys { rawKey, err := client.BytesFromStackItem(bindKeys[i]) if err != nil { - return nil, errors.Wrap(err, "could not get bind public key") + return nil, fmt.Errorf("could not get bind public key: %w", err) } key, err := keys.NewPublicKeyFromBytes(rawKey, elliptic.P256()) if err != nil { - return nil, errors.Wrap(err, "could not parse bind public key") + return nil, fmt.Errorf("could not parse bind public key: %w", err) } ev.keys = append(ev.keys, key) diff --git a/pkg/morph/event/neofs/cheque.go b/pkg/morph/event/neofs/cheque.go index 4de88bb19..c289303ae 100644 --- a/pkg/morph/event/neofs/cheque.go +++ b/pkg/morph/event/neofs/cheque.go @@ -1,11 +1,12 @@ package neofs import ( + "fmt" + "github.com/nspcc-dev/neo-go/pkg/util" "github.com/nspcc-dev/neo-go/pkg/vm/stackitem" "github.com/nspcc-dev/neofs-node/pkg/morph/client" "github.com/nspcc-dev/neofs-node/pkg/morph/event" - "github.com/pkg/errors" ) // Cheque structure of neofs.Cheque notification from mainnet chain. @@ -45,35 +46,35 @@ func ParseCheque(params []stackitem.Item) (event.Event, error) { // parse id ev.id, err = client.BytesFromStackItem(params[0]) if err != nil { - return nil, errors.Wrap(err, "could not get cheque id") + return nil, fmt.Errorf("could not get cheque id: %w", err) } // parse user user, err := client.BytesFromStackItem(params[1]) if err != nil { - return nil, errors.Wrap(err, "could not get cheque user") + return nil, fmt.Errorf("could not get cheque user: %w", err) } ev.user, err = util.Uint160DecodeBytesBE(user) if err != nil { - return nil, errors.Wrap(err, "could not convert cheque user to uint160") + return nil, fmt.Errorf("could not convert cheque user to uint160: %w", err) } // parse amount ev.amount, err = client.IntFromStackItem(params[2]) if err != nil { - return nil, errors.Wrap(err, "could not get cheque amount") + return nil, fmt.Errorf("could not get cheque amount: %w", err) } // parse lock account lock, err := client.BytesFromStackItem(params[3]) if err != nil { - return nil, errors.Wrap(err, "could not get cheque lock account") + return nil, fmt.Errorf("could not get cheque lock account: %w", err) } ev.lock, err = util.Uint160DecodeBytesBE(lock) if err != nil { - return nil, errors.Wrap(err, "could not convert cheque lock account to uint160") + return nil, fmt.Errorf("could not convert cheque lock account to uint160: %w", err) } return ev, nil diff --git a/pkg/morph/event/neofs/config.go b/pkg/morph/event/neofs/config.go index af029733a..6c2fe4eb4 100644 --- a/pkg/morph/event/neofs/config.go +++ b/pkg/morph/event/neofs/config.go @@ -1,10 +1,11 @@ package neofs import ( + "fmt" + "github.com/nspcc-dev/neo-go/pkg/vm/stackitem" "github.com/nspcc-dev/neofs-node/pkg/morph/client" "github.com/nspcc-dev/neofs-node/pkg/morph/event" - "github.com/pkg/errors" ) type Config struct { @@ -35,19 +36,19 @@ func ParseConfig(params []stackitem.Item) (event.Event, error) { // parse id ev.id, err = client.BytesFromStackItem(params[0]) if err != nil { - return nil, errors.Wrap(err, "could not get config update id") + return nil, fmt.Errorf("could not get config update id: %w", err) } // parse key ev.key, err = client.BytesFromStackItem(params[1]) if err != nil { - return nil, errors.Wrap(err, "could not get config key") + return nil, fmt.Errorf("could not get config key: %w", err) } // parse value ev.value, err = client.BytesFromStackItem(params[2]) if err != nil { - return nil, errors.Wrap(err, "could not get config value") + return nil, fmt.Errorf("could not get config value: %w", err) } return ev, nil diff --git a/pkg/morph/event/neofs/deposit.go b/pkg/morph/event/neofs/deposit.go index c54de6212..6019f7f28 100644 --- a/pkg/morph/event/neofs/deposit.go +++ b/pkg/morph/event/neofs/deposit.go @@ -1,11 +1,12 @@ package neofs import ( + "fmt" + "github.com/nspcc-dev/neo-go/pkg/util" "github.com/nspcc-dev/neo-go/pkg/vm/stackitem" "github.com/nspcc-dev/neofs-node/pkg/morph/client" "github.com/nspcc-dev/neofs-node/pkg/morph/event" - "github.com/pkg/errors" ) // Deposit structure of neofs.Deposit notification from mainnet chain. @@ -42,35 +43,35 @@ func ParseDeposit(params []stackitem.Item) (event.Event, error) { // parse from from, err := client.BytesFromStackItem(params[0]) if err != nil { - return nil, errors.Wrap(err, "could not get deposit sender") + return nil, fmt.Errorf("could not get deposit sender: %w", err) } ev.from, err = util.Uint160DecodeBytesBE(from) if err != nil { - return nil, errors.Wrap(err, "could not convert deposit sender to uint160") + return nil, fmt.Errorf("could not convert deposit sender to uint160: %w", err) } // parse amount ev.amount, err = client.IntFromStackItem(params[1]) if err != nil { - return nil, errors.Wrap(err, "could not get deposit amount") + return nil, fmt.Errorf("could not get deposit amount: %w", err) } // parse to to, err := client.BytesFromStackItem(params[2]) if err != nil { - return nil, errors.Wrap(err, "could not get deposit receiver") + return nil, fmt.Errorf("could not get deposit receiver: %w", err) } ev.to, err = util.Uint160DecodeBytesBE(to) if err != nil { - return nil, errors.Wrap(err, "could not convert deposit receiver to uint160") + return nil, fmt.Errorf("could not convert deposit receiver to uint160: %w", err) } // parse id ev.id, err = client.BytesFromStackItem(params[3]) if err != nil { - return nil, errors.Wrap(err, "could not get deposit id") + return nil, fmt.Errorf("could not get deposit id: %w", err) } return ev, nil diff --git a/pkg/morph/event/neofs/ir_update.go b/pkg/morph/event/neofs/ir_update.go index d2020dbf3..5387bbe1c 100644 --- a/pkg/morph/event/neofs/ir_update.go +++ b/pkg/morph/event/neofs/ir_update.go @@ -2,12 +2,12 @@ package neofs import ( "crypto/elliptic" + "fmt" "github.com/nspcc-dev/neo-go/pkg/crypto/keys" "github.com/nspcc-dev/neo-go/pkg/vm/stackitem" "github.com/nspcc-dev/neofs-node/pkg/morph/client" "github.com/nspcc-dev/neofs-node/pkg/morph/event" - "github.com/pkg/errors" ) type UpdateInnerRing struct { @@ -32,19 +32,19 @@ func ParseUpdateInnerRing(params []stackitem.Item) (event.Event, error) { // parse keys irKeys, err := client.ArrayFromStackItem(params[0]) if err != nil { - return nil, errors.Wrap(err, "could not get updated inner ring keys") + return nil, fmt.Errorf("could not get updated inner ring keys: %w", err) } ev.keys = make([]*keys.PublicKey, 0, len(irKeys)) for i := range irKeys { rawKey, err := client.BytesFromStackItem(irKeys[i]) if err != nil { - return nil, errors.Wrap(err, "could not get updated inner ring public key") + return nil, fmt.Errorf("could not get updated inner ring public key: %w", err) } key, err := keys.NewPublicKeyFromBytes(rawKey, elliptic.P256()) if err != nil { - return nil, errors.Wrap(err, "could not parse updated inner ring public key") + return nil, fmt.Errorf("could not parse updated inner ring public key: %w", err) } ev.keys = append(ev.keys, key) diff --git a/pkg/morph/event/neofs/unbind.go b/pkg/morph/event/neofs/unbind.go index d5c5618fe..86eaf73ad 100644 --- a/pkg/morph/event/neofs/unbind.go +++ b/pkg/morph/event/neofs/unbind.go @@ -2,13 +2,13 @@ package neofs import ( "crypto/elliptic" + "fmt" "github.com/nspcc-dev/neo-go/pkg/crypto/keys" "github.com/nspcc-dev/neo-go/pkg/util" "github.com/nspcc-dev/neo-go/pkg/vm/stackitem" "github.com/nspcc-dev/neofs-node/pkg/morph/client" "github.com/nspcc-dev/neofs-node/pkg/morph/event" - "github.com/pkg/errors" ) type Unbind struct { @@ -36,30 +36,30 @@ func ParseUnbind(params []stackitem.Item) (event.Event, error) { // parse user user, err := client.BytesFromStackItem(params[0]) if err != nil { - return nil, errors.Wrap(err, "could not get bind user") + return nil, fmt.Errorf("could not get bind user: %w", err) } ev.user, err = util.Uint160DecodeBytesBE(user) if err != nil { - return nil, errors.Wrap(err, "could not convert unbind user to uint160") + return nil, fmt.Errorf("could not convert unbind user to uint160: %w", err) } // parse keys unbindKeys, err := client.ArrayFromStackItem(params[1]) if err != nil { - return nil, errors.Wrap(err, "could not get unbind keys") + return nil, fmt.Errorf("could not get unbind keys: %w", err) } ev.keys = make([]*keys.PublicKey, 0, len(unbindKeys)) for i := range unbindKeys { rawKey, err := client.BytesFromStackItem(unbindKeys[i]) if err != nil { - return nil, errors.Wrap(err, "could not get unbind public key") + return nil, fmt.Errorf("could not get unbind public key: %w", err) } key, err := keys.NewPublicKeyFromBytes(rawKey, elliptic.P256()) if err != nil { - return nil, errors.Wrap(err, "could not parse unbind public key") + return nil, fmt.Errorf("could not parse unbind public key: %w", err) } ev.keys = append(ev.keys, key) diff --git a/pkg/morph/event/neofs/withdraw.go b/pkg/morph/event/neofs/withdraw.go index 6e2bdccaf..2c0c45929 100644 --- a/pkg/morph/event/neofs/withdraw.go +++ b/pkg/morph/event/neofs/withdraw.go @@ -1,11 +1,12 @@ package neofs import ( + "fmt" + "github.com/nspcc-dev/neo-go/pkg/util" "github.com/nspcc-dev/neo-go/pkg/vm/stackitem" "github.com/nspcc-dev/neofs-node/pkg/morph/client" "github.com/nspcc-dev/neofs-node/pkg/morph/event" - "github.com/pkg/errors" ) // Withdraw structure of neofs.Withdraw notification from mainnet chain. @@ -38,24 +39,24 @@ func ParseWithdraw(params []stackitem.Item) (event.Event, error) { // parse user user, err := client.BytesFromStackItem(params[0]) if err != nil { - return nil, errors.Wrap(err, "could not get withdraw user") + return nil, fmt.Errorf("could not get withdraw user: %w", err) } ev.user, err = util.Uint160DecodeBytesBE(user) if err != nil { - return nil, errors.Wrap(err, "could not convert withdraw user to uint160") + return nil, fmt.Errorf("could not convert withdraw user to uint160: %w", err) } // parse amount ev.amount, err = client.IntFromStackItem(params[1]) if err != nil { - return nil, errors.Wrap(err, "could not get withdraw amount") + return nil, fmt.Errorf("could not get withdraw amount: %w", err) } // parse id ev.id, err = client.BytesFromStackItem(params[2]) if err != nil { - return nil, errors.Wrap(err, "could not get withdraw id") + return nil, fmt.Errorf("could not get withdraw id: %w", err) } return ev, nil diff --git a/pkg/morph/event/netmap/add_peer.go b/pkg/morph/event/netmap/add_peer.go index 0bc57270c..f6304f933 100644 --- a/pkg/morph/event/netmap/add_peer.go +++ b/pkg/morph/event/netmap/add_peer.go @@ -1,10 +1,11 @@ package netmap import ( + "fmt" + "github.com/nspcc-dev/neo-go/pkg/vm/stackitem" "github.com/nspcc-dev/neofs-node/pkg/morph/client" "github.com/nspcc-dev/neofs-node/pkg/morph/event" - "github.com/pkg/errors" ) type AddPeer struct { @@ -30,7 +31,7 @@ func ParseAddPeer(prms []stackitem.Item) (event.Event, error) { ev.node, err = client.BytesFromStackItem(prms[0]) if err != nil { - return nil, errors.Wrap(err, "could not get integer epoch number") + return nil, fmt.Errorf("could not get integer epoch number: %w", err) } return ev, nil diff --git a/pkg/morph/event/netmap/epoch.go b/pkg/morph/event/netmap/epoch.go index abaa87d07..406aba806 100644 --- a/pkg/morph/event/netmap/epoch.go +++ b/pkg/morph/event/netmap/epoch.go @@ -1,10 +1,11 @@ package netmap import ( + "fmt" + "github.com/nspcc-dev/neo-go/pkg/vm/stackitem" "github.com/nspcc-dev/neofs-node/pkg/morph/client" "github.com/nspcc-dev/neofs-node/pkg/morph/event" - "github.com/pkg/errors" ) // NewEpoch is a new epoch Neo:Morph event. @@ -30,7 +31,7 @@ func ParseNewEpoch(prms []stackitem.Item) (event.Event, error) { prmEpochNum, err := client.IntFromStackItem(prms[0]) if err != nil { - return nil, errors.Wrap(err, "could not get integer epoch number") + return nil, fmt.Errorf("could not get integer epoch number: %w", err) } return NewEpoch{ diff --git a/pkg/morph/event/netmap/update_peer.go b/pkg/morph/event/netmap/update_peer.go index 64ec47379..950cc1140 100644 --- a/pkg/morph/event/netmap/update_peer.go +++ b/pkg/morph/event/netmap/update_peer.go @@ -2,6 +2,7 @@ package netmap import ( "crypto/elliptic" + "fmt" "github.com/nspcc-dev/neo-go/pkg/crypto/keys" "github.com/nspcc-dev/neo-go/pkg/vm/stackitem" @@ -9,7 +10,6 @@ import ( v2netmap "github.com/nspcc-dev/neofs-api-go/v2/netmap" "github.com/nspcc-dev/neofs-node/pkg/morph/client" "github.com/nspcc-dev/neofs-node/pkg/morph/event" - "github.com/pkg/errors" ) type UpdatePeer struct { @@ -41,18 +41,18 @@ func ParseUpdatePeer(prms []stackitem.Item) (event.Event, error) { // parse public key key, err := client.BytesFromStackItem(prms[1]) if err != nil { - return nil, errors.Wrap(err, "could not get public key") + return nil, fmt.Errorf("could not get public key: %w", err) } ev.publicKey, err = keys.NewPublicKeyFromBytes(key, elliptic.P256()) if err != nil { - return nil, errors.Wrap(err, "could not parse public key") + return nil, fmt.Errorf("could not parse public key: %w", err) } // parse node status st, err := client.IntFromStackItem(prms[0]) if err != nil { - return nil, errors.Wrap(err, "could not get node status") + return nil, fmt.Errorf("could not get node status: %w", err) } ev.status = netmap.NodeStateFromV2(v2netmap.NodeState(st)) diff --git a/pkg/morph/event/parser.go b/pkg/morph/event/parser.go index daa171864..398496902 100644 --- a/pkg/morph/event/parser.go +++ b/pkg/morph/event/parser.go @@ -1,8 +1,9 @@ package event import ( + "fmt" + "github.com/nspcc-dev/neo-go/pkg/vm/stackitem" - "github.com/pkg/errors" ) // Parser is a function that constructs Event @@ -31,7 +32,7 @@ func WrongNumberOfParameters(exp, act int) error { } func (s wrongPrmNumber) Error() string { - return errors.Errorf("wrong parameter count: expected %d, has %d", s.exp, s.act).Error() + return fmt.Errorf("wrong parameter count: expected %d, has %d", s.exp, s.act).Error() } // SetParser is an event parser setter. diff --git a/pkg/morph/event/reputation/put.go b/pkg/morph/event/reputation/put.go index 1acc98730..ebfa3f945 100644 --- a/pkg/morph/event/reputation/put.go +++ b/pkg/morph/event/reputation/put.go @@ -1,11 +1,12 @@ package reputation import ( + "fmt" + "github.com/nspcc-dev/neo-go/pkg/vm/stackitem" "github.com/nspcc-dev/neofs-api-go/pkg/reputation" "github.com/nspcc-dev/neofs-node/pkg/morph/client" "github.com/nspcc-dev/neofs-node/pkg/morph/event" - "github.com/pkg/errors" ) // Put structure of reputation.reputationPut notification from @@ -50,7 +51,7 @@ func ParsePut(prms []stackitem.Item) (event.Event, error) { // parse epoch number epoch, err := client.IntFromStackItem(prms[0]) if err != nil { - return nil, errors.Wrap(err, "could not get integer epoch number") + return nil, fmt.Errorf("could not get integer epoch number: %w", err) } ev.epoch = uint64(epoch) @@ -58,11 +59,11 @@ func ParsePut(prms []stackitem.Item) (event.Event, error) { // parse peer ID value peerID, err := client.BytesFromStackItem(prms[1]) if err != nil { - return nil, errors.Wrap(err, "could not get peer ID value") + return nil, fmt.Errorf("could not get peer ID value: %w", err) } if ln := len(peerID); ln != peerIDLength { - return nil, errors.Errorf("peer ID is %d byte long, expected %d", ln, peerIDLength) + return nil, fmt.Errorf("peer ID is %d byte long, expected %d", ln, peerIDLength) } var publicKey [33]byte @@ -72,12 +73,12 @@ func ParsePut(prms []stackitem.Item) (event.Event, error) { // parse global trust value rawValue, err := client.BytesFromStackItem(prms[2]) if err != nil { - return nil, errors.Wrap(err, "could not get global trust value") + return nil, fmt.Errorf("could not get global trust value: %w", err) } err = ev.value.Unmarshal(rawValue) if err != nil { - return nil, errors.Wrap(err, "could not parse global trust value") + return nil, fmt.Errorf("could not parse global trust value: %w", err) } return ev, nil diff --git a/pkg/morph/subscriber/subscriber.go b/pkg/morph/subscriber/subscriber.go index 39c65107e..56f61fbcb 100644 --- a/pkg/morph/subscriber/subscriber.go +++ b/pkg/morph/subscriber/subscriber.go @@ -2,6 +2,8 @@ package subscriber import ( "context" + "errors" + "fmt" "sync" "time" @@ -10,7 +12,6 @@ import ( "github.com/nspcc-dev/neo-go/pkg/rpc/client" "github.com/nspcc-dev/neo-go/pkg/rpc/response" "github.com/nspcc-dev/neo-go/pkg/util" - "github.com/pkg/errors" "go.uber.org/zap" ) @@ -105,7 +106,7 @@ func (s *subscriber) Close() { func (s *subscriber) BlockNotifications() (<-chan *block.Block, error) { if _, err := s.client.SubscribeForNewBlocks(nil); err != nil { - return nil, errors.Wrap(err, "could not subscribe for new block events") + return nil, fmt.Errorf("could not subscribe for new block events: %w", err) } return s.blockChan, nil @@ -168,7 +169,7 @@ func New(ctx context.Context, p *Params) (Subscriber, error) { } if err := wsClient.Init(); err != nil { - return nil, errors.Wrap(err, "could not init ws client") + return nil, fmt.Errorf("could not init ws client: %w", err) } sub := &subscriber{ diff --git a/pkg/network/address.go b/pkg/network/address.go index 163ebe533..bf47913f6 100644 --- a/pkg/network/address.go +++ b/pkg/network/address.go @@ -1,12 +1,12 @@ package network import ( + "fmt" "net" "strings" "github.com/multiformats/go-multiaddr" manet "github.com/multiformats/go-multiaddr/net" - "github.com/pkg/errors" ) /* @@ -40,7 +40,7 @@ func (a Address) String() string { func (a Address) IPAddrString() (string, error) { ip, err := manet.ToNetAddr(a.ma) if err != nil { - return "", errors.Wrap(err, "could not get net addr") + return "", fmt.Errorf("could not get net addr: %w", err) } return ip.String(), nil @@ -50,7 +50,7 @@ func (a Address) IPAddrString() (string, error) { func (a Address) HostAddrString() (string, error) { _, host, err := manet.DialArgs(a.ma) if err != nil { - return "", errors.Wrap(err, "could not get host addr") + return "", fmt.Errorf("could not get host addr: %w", err) } return host, nil diff --git a/pkg/network/transport/object/grpc/service.go b/pkg/network/transport/object/grpc/service.go index 0b084368a..a57df9db3 100644 --- a/pkg/network/transport/object/grpc/service.go +++ b/pkg/network/transport/object/grpc/service.go @@ -2,12 +2,12 @@ package object import ( "context" + "errors" "io" "github.com/nspcc-dev/neofs-api-go/v2/object" objectGRPC "github.com/nspcc-dev/neofs-api-go/v2/object/grpc" objectSvc "github.com/nspcc-dev/neofs-node/pkg/services/object" - "github.com/pkg/errors" ) // Server wraps NeoFS API Object service and @@ -34,7 +34,7 @@ func (s *Server) Put(gStream objectGRPC.ObjectService_PutServer) error { for { req, err := gStream.Recv() if err != nil { - if errors.Is(errors.Cause(err), io.EOF) { + if errors.Is(err, io.EOF) { resp, err := stream.CloseAndRecv() if err != nil { return err diff --git a/pkg/services/accounting/executor.go b/pkg/services/accounting/executor.go index c523369a3..4a2c14ccb 100644 --- a/pkg/services/accounting/executor.go +++ b/pkg/services/accounting/executor.go @@ -2,9 +2,9 @@ package accounting import ( "context" + "fmt" "github.com/nspcc-dev/neofs-api-go/v2/accounting" - "github.com/pkg/errors" ) type ServiceExecutor interface { @@ -25,7 +25,7 @@ func NewExecutionService(exec ServiceExecutor) Server { func (s *executorSvc) Balance(ctx context.Context, req *accounting.BalanceRequest) (*accounting.BalanceResponse, error) { respBody, err := s.exec.Balance(ctx, req.GetBody()) if err != nil { - return nil, errors.Wrap(err, "could not execute Balance request") + return nil, fmt.Errorf("could not execute Balance request: %w", err) } resp := new(accounting.BalanceResponse) diff --git a/pkg/services/container/announcement/load/route/placement/calls.go b/pkg/services/container/announcement/load/route/placement/calls.go index 61f222d6a..ae11ab434 100644 --- a/pkg/services/container/announcement/load/route/placement/calls.go +++ b/pkg/services/container/announcement/load/route/placement/calls.go @@ -1,9 +1,10 @@ package placementrouter import ( + "fmt" + "github.com/nspcc-dev/neofs-api-go/pkg/container" loadroute "github.com/nspcc-dev/neofs-node/pkg/services/container/announcement/load/route" - "github.com/pkg/errors" ) // NextStage composes container nodes for the container and epoch from a, @@ -19,7 +20,7 @@ func (b *Builder) NextStage(a container.UsedSpaceAnnouncement, passed []loadrout placement, err := b.placementBuilder.BuildPlacement(a.Epoch(), a.ContainerID()) if err != nil { - return nil, errors.Wrapf(err, "could not build placement %s", a.ContainerID()) + return nil, fmt.Errorf("could not build placement %s: %w", a.ContainerID(), err) } res := make([]loadroute.ServerInfo, 0, len(placement)) diff --git a/pkg/services/container/executor.go b/pkg/services/container/executor.go index f5124da54..e6f058a01 100644 --- a/pkg/services/container/executor.go +++ b/pkg/services/container/executor.go @@ -2,9 +2,9 @@ package container import ( "context" + "fmt" "github.com/nspcc-dev/neofs-api-go/v2/container" - "github.com/pkg/errors" ) type ServiceExecutor interface { @@ -32,7 +32,7 @@ func NewExecutionService(exec ServiceExecutor) Server { func (s *executorSvc) Put(ctx context.Context, req *container.PutRequest) (*container.PutResponse, error) { respBody, err := s.exec.Put(ctx, req.GetBody()) if err != nil { - return nil, errors.Wrap(err, "could not execute Put request") + return nil, fmt.Errorf("could not execute Put request: %w", err) } resp := new(container.PutResponse) @@ -44,7 +44,7 @@ func (s *executorSvc) Put(ctx context.Context, req *container.PutRequest) (*cont func (s *executorSvc) Delete(ctx context.Context, req *container.DeleteRequest) (*container.DeleteResponse, error) { respBody, err := s.exec.Delete(ctx, req.GetBody()) if err != nil { - return nil, errors.Wrap(err, "could not execute Delete request") + return nil, fmt.Errorf("could not execute Delete request: %w", err) } resp := new(container.DeleteResponse) @@ -56,7 +56,7 @@ func (s *executorSvc) Delete(ctx context.Context, req *container.DeleteRequest) func (s *executorSvc) Get(ctx context.Context, req *container.GetRequest) (*container.GetResponse, error) { respBody, err := s.exec.Get(ctx, req.GetBody()) if err != nil { - return nil, errors.Wrap(err, "could not execute Get request") + return nil, fmt.Errorf("could not execute Get request: %w", err) } resp := new(container.GetResponse) @@ -68,7 +68,7 @@ func (s *executorSvc) Get(ctx context.Context, req *container.GetRequest) (*cont func (s *executorSvc) List(ctx context.Context, req *container.ListRequest) (*container.ListResponse, error) { respBody, err := s.exec.List(ctx, req.GetBody()) if err != nil { - return nil, errors.Wrap(err, "could not execute List request") + return nil, fmt.Errorf("could not execute List request: %w", err) } resp := new(container.ListResponse) @@ -80,7 +80,7 @@ func (s *executorSvc) List(ctx context.Context, req *container.ListRequest) (*co func (s *executorSvc) SetExtendedACL(ctx context.Context, req *container.SetExtendedACLRequest) (*container.SetExtendedACLResponse, error) { respBody, err := s.exec.SetExtendedACL(ctx, req.GetBody()) if err != nil { - return nil, errors.Wrap(err, "could not execute SetEACL request") + return nil, fmt.Errorf("could not execute SetEACL request: %w", err) } resp := new(container.SetExtendedACLResponse) @@ -92,7 +92,7 @@ func (s *executorSvc) SetExtendedACL(ctx context.Context, req *container.SetExte func (s *executorSvc) GetExtendedACL(ctx context.Context, req *container.GetExtendedACLRequest) (*container.GetExtendedACLResponse, error) { respBody, err := s.exec.GetExtendedACL(ctx, req.GetBody()) if err != nil { - return nil, errors.Wrap(err, "could not execute GetEACL request") + return nil, fmt.Errorf("could not execute GetEACL request: %w", err) } resp := new(container.GetExtendedACLResponse) diff --git a/pkg/services/container/morph/executor.go b/pkg/services/container/morph/executor.go index 5cbe5dfbd..d681e5d04 100644 --- a/pkg/services/container/morph/executor.go +++ b/pkg/services/container/morph/executor.go @@ -2,6 +2,7 @@ package container import ( "context" + "fmt" eaclSDK "github.com/nspcc-dev/neofs-api-go/pkg/acl/eacl" containerSDK "github.com/nspcc-dev/neofs-api-go/pkg/container" @@ -11,7 +12,6 @@ import ( containerMorph "github.com/nspcc-dev/neofs-node/pkg/morph/client/container" "github.com/nspcc-dev/neofs-node/pkg/morph/client/container/wrapper" containerSvc "github.com/nspcc-dev/neofs-node/pkg/services/container" - "github.com/pkg/errors" ) type morphExecutor struct { @@ -33,7 +33,7 @@ func NewExecutor(client *containerMorph.Client) containerSvc.ServiceExecutor { func (s *morphExecutor) Put(ctx context.Context, body *container.PutRequestBody) (*container.PutResponseBody, error) { cnr, err := containerSDK.NewVerifiedFromV2(body.GetContainer()) if err != nil { - return nil, errors.Wrap(err, "invalid format of the container structure") + return nil, fmt.Errorf("invalid format of the container structure: %w", err) } sig := body.GetSignature() diff --git a/pkg/services/control/service.pb.go b/pkg/services/control/service.pb.go index 9456b1fde..b81535b95 100644 --- a/pkg/services/control/service.pb.go +++ b/pkg/services/control/service.pb.go @@ -8,14 +8,15 @@ package control import ( context "context" + reflect "reflect" + sync "sync" + proto "github.com/golang/protobuf/proto" grpc "google.golang.org/grpc" codes "google.golang.org/grpc/codes" status "google.golang.org/grpc/status" protoreflect "google.golang.org/protobuf/reflect/protoreflect" protoimpl "google.golang.org/protobuf/runtime/protoimpl" - reflect "reflect" - sync "sync" ) const ( diff --git a/pkg/services/control/types.pb.go b/pkg/services/control/types.pb.go index 528de009a..a9ef0eeb3 100644 --- a/pkg/services/control/types.pb.go +++ b/pkg/services/control/types.pb.go @@ -7,11 +7,12 @@ package control import ( + reflect "reflect" + sync "sync" + proto "github.com/golang/protobuf/proto" protoreflect "google.golang.org/protobuf/reflect/protoreflect" protoimpl "google.golang.org/protobuf/runtime/protoimpl" - reflect "reflect" - sync "sync" ) const ( diff --git a/pkg/services/object/acl/acl.go b/pkg/services/object/acl/acl.go index 61c98f4e1..c1b78b986 100644 --- a/pkg/services/object/acl/acl.go +++ b/pkg/services/object/acl/acl.go @@ -4,6 +4,7 @@ import ( "bytes" "context" "crypto/ecdsa" + "errors" "fmt" acl "github.com/nspcc-dev/neofs-api-go/pkg/acl/eacl" @@ -23,7 +24,6 @@ import ( objectSvc "github.com/nspcc-dev/neofs-node/pkg/services/object" "github.com/nspcc-dev/neofs-node/pkg/services/object/acl/eacl" eaclV2 "github.com/nspcc-dev/neofs-node/pkg/services/object/acl/eacl/v2" - "github.com/pkg/errors" ) type ( diff --git a/pkg/services/object/acl/classifier.go b/pkg/services/object/acl/classifier.go index b50045bb6..31d226673 100644 --- a/pkg/services/object/acl/classifier.go +++ b/pkg/services/object/acl/classifier.go @@ -3,6 +3,7 @@ package acl import ( "bytes" "crypto/ecdsa" + "fmt" "github.com/nspcc-dev/neofs-api-go/pkg" acl "github.com/nspcc-dev/neofs-api-go/pkg/acl/eacl" @@ -15,7 +16,6 @@ import ( v2signature "github.com/nspcc-dev/neofs-api-go/v2/signature" crypto "github.com/nspcc-dev/neofs-crypto" core "github.com/nspcc-dev/neofs-node/pkg/core/netmap" - "github.com/pkg/errors" "go.uber.org/zap" ) @@ -52,7 +52,7 @@ func (c SenderClassifier) Classify( cid *container.ID, cnr *container.Container) (role acl.Role, isIR bool, key []byte, err error) { if cid == nil { - return 0, false, nil, errors.Wrap(ErrMalformedRequest, "container id is not set") + return 0, false, nil, fmt.Errorf("%w: container id is not set", ErrMalformedRequest) } ownerID, ownerKey, err := requestOwner(req) @@ -95,7 +95,7 @@ func (c SenderClassifier) Classify( func requestOwner(req metaWithToken) (*owner.ID, *ecdsa.PublicKey, error) { if req.vheader == nil { - return nil, nil, errors.Wrap(ErrMalformedRequest, "nil verification header") + return nil, nil, fmt.Errorf("%w: nil verification header", ErrMalformedRequest) } // if session token is presented, use it as truth source @@ -107,13 +107,13 @@ func requestOwner(req metaWithToken) (*owner.ID, *ecdsa.PublicKey, error) { // otherwise get original body signature bodySignature := originalBodySignature(req.vheader) if bodySignature == nil { - return nil, nil, errors.Wrap(ErrMalformedRequest, "nil at body signature") + return nil, nil, fmt.Errorf("%w: nil at body signature", ErrMalformedRequest) } key := crypto.UnmarshalPublicKey(bodySignature.Key()) neo3wallet, err := owner.NEO3WalletFromPublicKey(key) if err != nil { - return nil, nil, errors.Wrap(err, "can't create neo3 wallet") + return nil, nil, fmt.Errorf("can't create neo3 wallet: %w", err) } // form user from public key @@ -202,7 +202,7 @@ func ownerFromToken(token *session.SessionToken) (*owner.ID, *ecdsa.PublicKey, e tokenSignature := token.GetSignature() return tokenSignature.GetKey(), tokenSignature.GetSign() }); err != nil { - return nil, nil, errors.Wrap(ErrMalformedRequest, "invalid session token signature") + return nil, nil, fmt.Errorf("%w: invalid session token signature", ErrMalformedRequest) } // 2. Then check if session token owner issued the session token @@ -211,7 +211,7 @@ func ownerFromToken(token *session.SessionToken) (*owner.ID, *ecdsa.PublicKey, e if !isOwnerFromKey(tokenOwner, tokenIssuerKey) { // todo: in this case we can issue all owner keys from neofs.id and check once again - return nil, nil, errors.Wrap(ErrMalformedRequest, "invalid session token owner") + return nil, nil, fmt.Errorf("%w: invalid session token owner", ErrMalformedRequest) } return tokenOwner, tokenIssuerKey, nil diff --git a/pkg/services/object/get/get_test.go b/pkg/services/object/get/get_test.go index 046bd4708..bbae71d28 100644 --- a/pkg/services/object/get/get_test.go +++ b/pkg/services/object/get/get_test.go @@ -4,6 +4,7 @@ import ( "context" "crypto/rand" "crypto/sha256" + "errors" "fmt" "strconv" "testing" @@ -16,7 +17,6 @@ import ( "github.com/nspcc-dev/neofs-node/pkg/services/object/util" "github.com/nspcc-dev/neofs-node/pkg/services/object_manager/placement" "github.com/nspcc-dev/neofs-node/pkg/util/logger/test" - "github.com/pkg/errors" "github.com/stretchr/testify/require" ) diff --git a/pkg/services/object/get/local.go b/pkg/services/object/get/local.go index bdd5c304d..8c964520d 100644 --- a/pkg/services/object/get/local.go +++ b/pkg/services/object/get/local.go @@ -1,9 +1,10 @@ package getsvc import ( + "errors" + objectSDK "github.com/nspcc-dev/neofs-api-go/pkg/object" "github.com/nspcc-dev/neofs-node/pkg/core/object" - "github.com/pkg/errors" "go.uber.org/zap" ) diff --git a/pkg/services/object/get/remote.go b/pkg/services/object/get/remote.go index b6001d0d0..9de21b645 100644 --- a/pkg/services/object/get/remote.go +++ b/pkg/services/object/get/remote.go @@ -2,11 +2,11 @@ package getsvc import ( "context" + "errors" objectSDK "github.com/nspcc-dev/neofs-api-go/pkg/object" "github.com/nspcc-dev/neofs-node/pkg/core/object" "github.com/nspcc-dev/neofs-node/pkg/network" - "github.com/pkg/errors" "go.uber.org/zap" ) diff --git a/pkg/services/object/get/v2/service.go b/pkg/services/object/get/v2/service.go index 21944428d..5bd13788a 100644 --- a/pkg/services/object/get/v2/service.go +++ b/pkg/services/object/get/v2/service.go @@ -2,13 +2,13 @@ package getsvc import ( "context" + "errors" "github.com/nspcc-dev/neofs-api-go/pkg/object" objectV2 "github.com/nspcc-dev/neofs-api-go/v2/object" objectSvc "github.com/nspcc-dev/neofs-node/pkg/services/object" getsvc "github.com/nspcc-dev/neofs-node/pkg/services/object/get" objutil "github.com/nspcc-dev/neofs-node/pkg/services/object/util" - "github.com/pkg/errors" ) // Service implements Get operation of Object service v2. diff --git a/pkg/services/object/get/v2/util.go b/pkg/services/object/get/v2/util.go index badd3836a..a44c38d75 100644 --- a/pkg/services/object/get/v2/util.go +++ b/pkg/services/object/get/v2/util.go @@ -3,6 +3,8 @@ package getsvc import ( "context" "crypto/sha256" + "errors" + "fmt" "hash" "io" "sync" @@ -22,7 +24,6 @@ import ( getsvc "github.com/nspcc-dev/neofs-node/pkg/services/object/get" "github.com/nspcc-dev/neofs-node/pkg/services/object/util" "github.com/nspcc-dev/tzhash/tz" - "github.com/pkg/errors" ) var errWrongMessageSeq = errors.New("incorrect message sequence") @@ -79,7 +80,7 @@ func (s *Service) toPrm(req *objectV2.GetRequest, stream objectSvc.GetObjectStre // open stream stream, err := rpc.GetObject(c.Raw(), req, rpcclient.WithContext(stream.Context())) if err != nil { - return nil, errors.Wrap(err, "stream opening failed") + return nil, fmt.Errorf("stream opening failed: %w", err) } var ( @@ -93,7 +94,7 @@ func (s *Service) toPrm(req *objectV2.GetRequest, stream objectSvc.GetObjectStre // receive message from server stream err := stream.Read(resp) if err != nil { - if errors.Is(errors.Cause(err), io.EOF) { + if errors.Is(err, io.EOF) { if !headWas { return nil, io.ErrUnexpectedEOF } @@ -101,17 +102,17 @@ func (s *Service) toPrm(req *objectV2.GetRequest, stream objectSvc.GetObjectStre break } - return nil, errors.Wrap(err, "reading the response failed") + return nil, fmt.Errorf("reading the response failed: %w", err) } // verify response structure if err := signature.VerifyServiceMessage(resp); err != nil { - return nil, errors.Wrap(err, "response verification failed") + return nil, fmt.Errorf("response verification failed: %w", err) } switch v := resp.GetBody().GetObjectPart().(type) { default: - return nil, errors.Errorf("unexpected object part %T", v) + return nil, fmt.Errorf("unexpected object part %T", v) case *objectV2.GetObjectPartInit: if headWas { return nil, errWrongMessageSeq @@ -201,7 +202,7 @@ func (s *Service) toRangePrm(req *objectV2.GetRangeRequest, stream objectSvc.Get // open stream stream, err := rpc.GetObjectRange(c.Raw(), req, rpcclient.WithContext(stream.Context())) if err != nil { - return nil, errors.Wrap(err, "could not create Get payload range stream") + return nil, fmt.Errorf("could not create Get payload range stream: %w", err) } payload := make([]byte, 0, body.GetRange().GetLength()) @@ -212,21 +213,21 @@ func (s *Service) toRangePrm(req *objectV2.GetRangeRequest, stream objectSvc.Get // receive message from server stream err := stream.Read(resp) if err != nil { - if errors.Is(errors.Cause(err), io.EOF) { + if errors.Is(err, io.EOF) { break } - return nil, errors.Wrap(err, "reading the response failed") + return nil, fmt.Errorf("reading the response failed: %w", err) } // verify response structure if err := signature.VerifyServiceMessage(resp); err != nil { - return nil, errors.Wrapf(err, "could not verify %T", resp) + return nil, fmt.Errorf("could not verify %T: %w", resp, err) } switch v := resp.GetBody().GetRangePart().(type) { case nil: - return nil, errors.Errorf("unexpected range type %T", v) + return nil, fmt.Errorf("unexpected range type %T", v) case *objectV2.GetRangePartChunk: payload = append(payload, v.GetChunk()...) case *objectV2.SplitInfo: @@ -279,7 +280,7 @@ func (s *Service) toHashRangePrm(req *objectV2.GetRangeHashRequest) (*getsvc.Ran switch t := body.GetType(); t { default: - return nil, errors.Errorf("unknown checksum type %v", t) + return nil, fmt.Errorf("unknown checksum type %v", t) case refs.SHA256: p.SetHashGenerator(func() hash.Hash { return sha256.New() @@ -364,12 +365,12 @@ func (s *Service) toHeadPrm(ctx context.Context, req *objectV2.HeadRequest, resp // send Head request resp, err := rpc.HeadObject(c.Raw(), req, rpcclient.WithContext(ctx)) if err != nil { - return nil, errors.Wrap(err, "sending the request failed") + return nil, fmt.Errorf("sending the request failed: %w", err) } // verify response structure if err := signature.VerifyServiceMessage(resp); err != nil { - return nil, errors.Wrap(err, "response verification failed") + return nil, fmt.Errorf("response verification failed: %w", err) } var ( @@ -379,10 +380,10 @@ func (s *Service) toHeadPrm(ctx context.Context, req *objectV2.HeadRequest, resp switch v := resp.GetBody().GetHeaderPart().(type) { case nil: - return nil, errors.Errorf("unexpected header type %T", v) + return nil, fmt.Errorf("unexpected header type %T", v) case *objectV2.ShortHeader: if !body.GetMainOnly() { - return nil, errors.Errorf("wrong header part type: expected %T, received %T", + return nil, fmt.Errorf("wrong header part type: expected %T, received %T", (*objectV2.ShortHeader)(nil), (*objectV2.HeaderWithSignature)(nil), ) } @@ -399,7 +400,7 @@ func (s *Service) toHeadPrm(ctx context.Context, req *objectV2.HeadRequest, resp hdr.SetHomomorphicHash(h.GetHomomorphicHash()) case *objectV2.HeaderWithSignature: if body.GetMainOnly() { - return nil, errors.Errorf("wrong header part type: expected %T, received %T", + return nil, fmt.Errorf("wrong header part type: expected %T, received %T", (*objectV2.HeaderWithSignature)(nil), (*objectV2.ShortHeader)(nil), ) } @@ -420,7 +421,7 @@ func (s *Service) toHeadPrm(ctx context.Context, req *objectV2.HeadRequest, resp return idSig.GetKey(), idSig.GetSign() }, ); err != nil { - return nil, errors.Wrap(err, "incorrect object header signature") + return nil, fmt.Errorf("incorrect object header signature: %w", err) } case *objectV2.SplitInfo: si := objectSDK.NewSplitInfoFromV2(v) diff --git a/pkg/services/object/head/remote.go b/pkg/services/object/head/remote.go index c8b252a8a..5e4e1c217 100644 --- a/pkg/services/object/head/remote.go +++ b/pkg/services/object/head/remote.go @@ -2,13 +2,14 @@ package headsvc import ( "context" + "errors" + "fmt" "github.com/nspcc-dev/neofs-api-go/pkg/client" objectSDK "github.com/nspcc-dev/neofs-api-go/pkg/object" "github.com/nspcc-dev/neofs-node/pkg/core/object" "github.com/nspcc-dev/neofs-node/pkg/network" "github.com/nspcc-dev/neofs-node/pkg/services/object/util" - "github.com/pkg/errors" ) type ClientConstructor interface { @@ -62,7 +63,7 @@ func (p *RemoteHeadPrm) WithObjectAddress(v *objectSDK.Address) *RemoteHeadPrm { func (h *RemoteHeader) Head(ctx context.Context, prm *RemoteHeadPrm) (*object.Object, error) { key, err := h.keyStorage.GetKey(prm.commonHeadPrm.common.SessionToken()) if err != nil { - return nil, errors.Wrapf(err, "(%T) could not receive private key", h) + return nil, fmt.Errorf("(%T) could not receive private key: %w", h, err) } addr, err := prm.node.HostAddrString() @@ -72,7 +73,7 @@ func (h *RemoteHeader) Head(ctx context.Context, prm *RemoteHeadPrm) (*object.Ob c, err := h.clientCache.Get(addr) if err != nil { - return nil, errors.Wrapf(err, "(%T) could not create SDK client %s", h, addr) + return nil, fmt.Errorf("(%T) could not create SDK client %s: %w", h, addr, err) } p := new(client.ObjectHeaderParams). @@ -90,7 +91,7 @@ func (h *RemoteHeader) Head(ctx context.Context, prm *RemoteHeadPrm) (*object.Ob client.WithKey(key), ) if err != nil { - return nil, errors.Wrapf(err, "(%T) could not head object in %s", h, addr) + return nil, fmt.Errorf("(%T) could not head object in %s: %w", h, addr, err) } return object.NewFromSDK(hdr), nil diff --git a/pkg/services/object/put/distributed.go b/pkg/services/object/put/distributed.go index 81ac32cf4..40442b3f9 100644 --- a/pkg/services/object/put/distributed.go +++ b/pkg/services/object/put/distributed.go @@ -1,6 +1,8 @@ package putsvc import ( + "errors" + "fmt" "sync" "github.com/nspcc-dev/neofs-node/pkg/core/object" @@ -10,7 +12,6 @@ import ( "github.com/nspcc-dev/neofs-node/pkg/services/object_manager/transformer" "github.com/nspcc-dev/neofs-node/pkg/util" "github.com/nspcc-dev/neofs-node/pkg/util/logger" - "github.com/pkg/errors" ) type distributedTarget struct { @@ -48,7 +49,7 @@ func (t *distributedTarget) Close() (*transformer.AccessIdentifiers, error) { append(t.traverseOpts, placement.ForObject(t.obj.ID()))..., ) if err != nil { - return nil, errors.Wrapf(err, "(%T) could not create object placement traverser", t) + return nil, fmt.Errorf("(%T) could not create object placement traverser: %w", t, err) } sz := 0 @@ -66,7 +67,7 @@ func (t *distributedTarget) Close() (*transformer.AccessIdentifiers, error) { t.obj.SetPayload(payload) if err := t.fmt.ValidateContent(t.obj.Object()); err != nil { - return nil, errors.Wrapf(err, "(%T) could not validate payload content", t) + return nil, fmt.Errorf("(%T) could not validate payload content: %w", t, err) } loop: @@ -90,12 +91,12 @@ loop: if err := target.WriteHeader(t.obj); err != nil { svcutil.LogServiceError(t.log, "PUT", addr, - errors.Wrap(err, "could not write header")) + fmt.Errorf("could not write header: %w", err)) return } else if _, err := target.Close(); err != nil { svcutil.LogServiceError(t.log, "PUT", addr, - errors.Wrap(err, "could not close object stream")) + fmt.Errorf("could not close object stream: %w", err)) return } diff --git a/pkg/services/object/put/local.go b/pkg/services/object/put/local.go index 2055b47b1..0750b546f 100644 --- a/pkg/services/object/put/local.go +++ b/pkg/services/object/put/local.go @@ -1,10 +1,11 @@ package putsvc import ( + "fmt" + "github.com/nspcc-dev/neofs-node/pkg/core/object" "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/engine" "github.com/nspcc-dev/neofs-node/pkg/services/object_manager/transformer" - "github.com/pkg/errors" ) type localTarget struct { @@ -31,7 +32,7 @@ func (t *localTarget) Write(p []byte) (n int, err error) { func (t *localTarget) Close() (*transformer.AccessIdentifiers, error) { if err := engine.Put(t.storage, t.obj.Object()); err != nil { - return nil, errors.Wrapf(err, "(%T) could not put object to local storage", t) + return nil, fmt.Errorf("(%T) could not put object to local storage: %w", t, err) } return new(transformer.AccessIdentifiers). diff --git a/pkg/services/object/put/remote.go b/pkg/services/object/put/remote.go index 426c0f51c..e9d3ebde2 100644 --- a/pkg/services/object/put/remote.go +++ b/pkg/services/object/put/remote.go @@ -2,13 +2,13 @@ package putsvc import ( "context" + "fmt" "github.com/nspcc-dev/neofs-api-go/pkg/client" "github.com/nspcc-dev/neofs-node/pkg/core/object" "github.com/nspcc-dev/neofs-node/pkg/network" "github.com/nspcc-dev/neofs-node/pkg/services/object/util" "github.com/nspcc-dev/neofs-node/pkg/services/object_manager/transformer" - "github.com/pkg/errors" ) type remoteTarget struct { @@ -51,7 +51,7 @@ func (t *remoteTarget) WriteHeader(obj *object.RawObject) error { func (t *remoteTarget) Close() (*transformer.AccessIdentifiers, error) { key, err := t.keyStorage.GetKey(t.commonPrm.SessionToken()) if err != nil { - return nil, errors.Wrapf(err, "(%T) could not receive private key", t) + return nil, fmt.Errorf("(%T) could not receive private key: %w", t, err) } addr, err := t.addr.HostAddrString() @@ -61,7 +61,7 @@ func (t *remoteTarget) Close() (*transformer.AccessIdentifiers, error) { c, err := t.clientConstructor.Get(addr) if err != nil { - return nil, errors.Wrapf(err, "(%T) could not create SDK client %s", t, addr) + return nil, fmt.Errorf("(%T) could not create SDK client %s: %w", t, addr, err) } id, err := c.PutObject(t.ctx, new(client.PutObjectParams). @@ -75,7 +75,7 @@ func (t *remoteTarget) Close() (*transformer.AccessIdentifiers, error) { )..., ) if err != nil { - return nil, errors.Wrapf(err, "(%T) could not put object to %s", t, addr) + return nil, fmt.Errorf("(%T) could not put object to %s: %w", t, addr, err) } return new(transformer.AccessIdentifiers). @@ -118,9 +118,9 @@ func (s *RemoteSender) PutObject(ctx context.Context, p *RemotePutPrm) error { } if err := t.WriteHeader(object.NewRawFromObject(p.obj)); err != nil { - return errors.Wrapf(err, "(%T) could not send object header", s) + return fmt.Errorf("(%T) could not send object header: %w", s, err) } else if _, err := t.Close(); err != nil { - return errors.Wrapf(err, "(%T) could not send object", s) + return fmt.Errorf("(%T) could not send object: %w", s, err) } return nil diff --git a/pkg/services/object/put/streamer.go b/pkg/services/object/put/streamer.go index 5305c48dc..cea78b125 100644 --- a/pkg/services/object/put/streamer.go +++ b/pkg/services/object/put/streamer.go @@ -2,13 +2,14 @@ package putsvc import ( "context" + "errors" + "fmt" "github.com/nspcc-dev/neofs-node/pkg/core/netmap" "github.com/nspcc-dev/neofs-node/pkg/network" "github.com/nspcc-dev/neofs-node/pkg/services/object/util" "github.com/nspcc-dev/neofs-node/pkg/services/object_manager/placement" "github.com/nspcc-dev/neofs-node/pkg/services/object_manager/transformer" - "github.com/pkg/errors" ) type Streamer struct { @@ -26,13 +27,13 @@ var errInitRecall = errors.New("init recall") func (p *Streamer) Init(prm *PutInitPrm) error { // initialize destination target if err := p.initTarget(prm); err != nil { - return errors.Wrapf(err, "(%T) could not initialize object target", p) + return fmt.Errorf("(%T) could not initialize object target: %w", p, err) } - return errors.Wrapf( - p.target.WriteHeader(prm.hdr), - "(%T) could not write header to target", p, - ) + if err := p.target.WriteHeader(prm.hdr); err != nil { + return fmt.Errorf("(%T) could not write header to target: %w", p, err) + } + return nil } func (p *Streamer) initTarget(prm *PutInitPrm) error { @@ -43,7 +44,7 @@ func (p *Streamer) initTarget(prm *PutInitPrm) error { // prepare needed put parameters if err := p.preparePrm(prm); err != nil { - return errors.Wrapf(err, "(%T) could not prepare put parameters", p) + return fmt.Errorf("(%T) could not prepare put parameters: %w", p, err) } if prm.hdr.Signature() != nil { @@ -63,12 +64,12 @@ func (p *Streamer) initTarget(prm *PutInitPrm) error { // get private token from local storage sessionKey, err := p.keyStorage.GetKey(sToken) if err != nil { - return errors.Wrapf(err, "(%T) could not receive session key", p) + return fmt.Errorf("(%T) could not receive session key: %w", p, err) } maxSz := p.maxSizeSrc.MaxObjectSize() if maxSz == 0 { - return errors.Errorf("(%T) could not obtain max object size parameter", p) + return fmt.Errorf("(%T) could not obtain max object size parameter", p) } p.target = transformer.NewPayloadSizeLimiter( @@ -92,13 +93,13 @@ func (p *Streamer) preparePrm(prm *PutInitPrm) error { // get latest network map nm, err := netmap.GetLatestNetworkMap(p.netMapSrc) if err != nil { - return errors.Wrapf(err, "(%T) could not get latest network map", p) + return fmt.Errorf("(%T) could not get latest network map: %w", p, err) } // get container to store the object cnr, err := p.cnrSrc.Get(prm.hdr.ContainerID()) if err != nil { - return errors.Wrapf(err, "(%T) could not get container by ID", p) + return fmt.Errorf("(%T) could not get container by ID: %w", p, err) } // add common options @@ -158,7 +159,7 @@ func (p *Streamer) SendChunk(prm *PutChunkPrm) error { _, err := p.target.Write(prm.chunk) - return errors.Wrapf(err, "(%T) could not write payload chunk to target", p) + return fmt.Errorf("(%T) could not write payload chunk to target: %w", p, err) } func (p *Streamer) Close() (*PutResponse, error) { @@ -168,7 +169,7 @@ func (p *Streamer) Close() (*PutResponse, error) { ids, err := p.target.Close() if err != nil { - return nil, errors.Wrapf(err, "(%T) could not close object target", p) + return nil, fmt.Errorf("(%T) could not close object target: %w", p, err) } id := ids.ParentID() diff --git a/pkg/services/object/put/v2/service.go b/pkg/services/object/put/v2/service.go index 9cdebabe7..2f83db192 100644 --- a/pkg/services/object/put/v2/service.go +++ b/pkg/services/object/put/v2/service.go @@ -2,10 +2,10 @@ package putsvc import ( "context" + "fmt" "github.com/nspcc-dev/neofs-node/pkg/services/object" putsvc "github.com/nspcc-dev/neofs-node/pkg/services/object/put" - "github.com/pkg/errors" ) // Service implements Put operation of Object service v2. @@ -37,7 +37,7 @@ func NewService(opts ...Option) *Service { func (s *Service) Put(ctx context.Context) (object.PutObjectStream, error) { stream, err := s.svc.Put(ctx) if err != nil { - return nil, errors.Wrapf(err, "(%T) could not open object put stream", s) + return nil, fmt.Errorf("(%T) could not open object put stream: %w", s, err) } return &streamer{ diff --git a/pkg/services/object/put/v2/streamer.go b/pkg/services/object/put/v2/streamer.go index 5eceb5f15..f4044e34d 100644 --- a/pkg/services/object/put/v2/streamer.go +++ b/pkg/services/object/put/v2/streamer.go @@ -1,9 +1,10 @@ package putsvc import ( + "fmt" + "github.com/nspcc-dev/neofs-api-go/v2/object" putsvc "github.com/nspcc-dev/neofs-node/pkg/services/object/put" - "github.com/pkg/errors" ) type streamer struct { @@ -21,14 +22,14 @@ func (s *streamer) Send(req *object.PutRequest) (err error) { } if err = s.stream.Init(initPrm); err != nil { - err = errors.Wrapf(err, "(%T) could not init object put stream", s) + err = fmt.Errorf("(%T) could not init object put stream: %w", s, err) } case *object.PutObjectPartChunk: if err = s.stream.SendChunk(toChunkPrm(v)); err != nil { - err = errors.Wrapf(err, "(%T) could not send payload chunk", s) + err = fmt.Errorf("(%T) could not send payload chunk: %w", s, err) } default: - err = errors.Errorf("(%T) invalid object put stream part type %T", s, v) + err = fmt.Errorf("(%T) invalid object put stream part type %T", s, v) } return @@ -37,7 +38,7 @@ func (s *streamer) Send(req *object.PutRequest) (err error) { func (s *streamer) CloseAndRecv() (*object.PutResponse, error) { resp, err := s.stream.Close() if err != nil { - return nil, errors.Wrapf(err, "(%T) could not object put stream", s) + return nil, fmt.Errorf("(%T) could not object put stream: %w", s, err) } return fromPutResponse(resp), nil diff --git a/pkg/services/object/put/validation.go b/pkg/services/object/put/validation.go index b2d568944..6de78f48f 100644 --- a/pkg/services/object/put/validation.go +++ b/pkg/services/object/put/validation.go @@ -3,13 +3,13 @@ package putsvc import ( "bytes" "crypto/sha256" + "fmt" "hash" "github.com/nspcc-dev/neofs-api-go/pkg" "github.com/nspcc-dev/neofs-node/pkg/core/object" "github.com/nspcc-dev/neofs-node/pkg/services/object_manager/transformer" "github.com/nspcc-dev/tzhash/tz" - "github.com/pkg/errors" ) type validatingTarget struct { @@ -26,7 +26,7 @@ func (t *validatingTarget) WriteHeader(obj *object.RawObject) error { cs := obj.PayloadChecksum() switch typ := cs.Type(); typ { default: - return errors.Errorf("(%T) unsupported payload checksum type %v", t, typ) + return fmt.Errorf("(%T) unsupported payload checksum type %v", t, typ) case pkg.ChecksumSHA256: t.hash = sha256.New() case pkg.ChecksumTZ: @@ -36,7 +36,7 @@ func (t *validatingTarget) WriteHeader(obj *object.RawObject) error { t.checksum = cs.Sum() if err := t.fmt.Validate(obj.Object()); err != nil { - return errors.Wrapf(err, "(%T) coult not validate object format", t) + return fmt.Errorf("(%T) coult not validate object format: %w", t, err) } return t.nextTarget.WriteHeader(obj) @@ -53,7 +53,7 @@ func (t *validatingTarget) Write(p []byte) (n int, err error) { func (t *validatingTarget) Close() (*transformer.AccessIdentifiers, error) { if !bytes.Equal(t.hash.Sum(nil), t.checksum) { - return nil, errors.Errorf("(%T) incorrect payload checksum", t) + return nil, fmt.Errorf("(%T) incorrect payload checksum", t) } return t.nextTarget.Close() diff --git a/pkg/services/object/response.go b/pkg/services/object/response.go index 4fef5d101..1d16c9799 100644 --- a/pkg/services/object/response.go +++ b/pkg/services/object/response.go @@ -2,11 +2,11 @@ package object import ( "context" + "fmt" "github.com/nspcc-dev/neofs-api-go/v2/object" "github.com/nspcc-dev/neofs-node/pkg/services/util" "github.com/nspcc-dev/neofs-node/pkg/services/util/response" - "github.com/pkg/errors" ) type ResponseService struct { @@ -66,7 +66,7 @@ func (s *putStreamResponser) Send(req *object.PutRequest) error { func (s *putStreamResponser) CloseAndRecv() (*object.PutResponse, error) { r, err := s.stream.CloseAndRecv() if err != nil { - return nil, errors.Wrapf(err, "(%T) could not receive response", s) + return nil, fmt.Errorf("(%T) could not receive response: %w", s, err) } return r.(*object.PutResponse), nil @@ -75,7 +75,7 @@ func (s *putStreamResponser) CloseAndRecv() (*object.PutResponse, error) { func (s *ResponseService) Put(ctx context.Context) (PutObjectStream, error) { stream, err := s.svc.Put(ctx) if err != nil { - return nil, errors.Wrap(err, "could not create Put object streamer") + return nil, fmt.Errorf("could not create Put object streamer: %w", err) } return &putStreamResponser{ diff --git a/pkg/services/object/search/search_test.go b/pkg/services/object/search/search_test.go index 339a8d244..3438b6627 100644 --- a/pkg/services/object/search/search_test.go +++ b/pkg/services/object/search/search_test.go @@ -4,6 +4,7 @@ import ( "context" "crypto/rand" "crypto/sha256" + "errors" "fmt" "strconv" "testing" @@ -15,7 +16,6 @@ import ( "github.com/nspcc-dev/neofs-node/pkg/services/object/util" "github.com/nspcc-dev/neofs-node/pkg/services/object_manager/placement" "github.com/nspcc-dev/neofs-node/pkg/util/logger/test" - "github.com/pkg/errors" "github.com/stretchr/testify/require" ) diff --git a/pkg/services/object/search/v2/util.go b/pkg/services/object/search/v2/util.go index 31d82071a..cf5f93f8b 100644 --- a/pkg/services/object/search/v2/util.go +++ b/pkg/services/object/search/v2/util.go @@ -1,6 +1,8 @@ package searchsvc import ( + "errors" + "fmt" "io" "sync" @@ -16,7 +18,6 @@ import ( objectSvc "github.com/nspcc-dev/neofs-node/pkg/services/object" searchsvc "github.com/nspcc-dev/neofs-node/pkg/services/object/search" "github.com/nspcc-dev/neofs-node/pkg/services/object/util" - "github.com/pkg/errors" ) func (s *Service) toPrm(req *objectV2.SearchRequest, stream objectSvc.SearchStream) (*searchsvc.Prm, error) { @@ -80,16 +81,16 @@ func (s *Service) toPrm(req *objectV2.SearchRequest, stream objectSvc.SearchStre // receive message from server stream err := stream.Read(resp) if err != nil { - if errors.Is(errors.Cause(err), io.EOF) { + if errors.Is(err, io.EOF) { break } - return nil, errors.Wrap(err, "reading the response failed") + return nil, fmt.Errorf("reading the response failed: %w", err) } // verify response structure if err := signature.VerifyServiceMessage(resp); err != nil { - return nil, errors.Wrapf(err, "could not verify %T", resp) + return nil, fmt.Errorf("could not verify %T: %w", resp, err) } chunk := resp.GetBody().GetIDList() diff --git a/pkg/services/object/sign.go b/pkg/services/object/sign.go index 2f3704139..f5b8c4648 100644 --- a/pkg/services/object/sign.go +++ b/pkg/services/object/sign.go @@ -3,10 +3,10 @@ package object import ( "context" "crypto/ecdsa" + "fmt" "github.com/nspcc-dev/neofs-api-go/v2/object" "github.com/nspcc-dev/neofs-node/pkg/services/util" - "github.com/pkg/errors" ) type SignService struct { @@ -74,7 +74,7 @@ func (s *putStreamSigner) Send(req *object.PutRequest) error { func (s *putStreamSigner) CloseAndRecv() (*object.PutResponse, error) { r, err := s.stream.CloseAndRecv() if err != nil { - return nil, errors.Wrap(err, "could not receive response") + return nil, fmt.Errorf("could not receive response: %w", err) } return r.(*object.PutResponse), nil @@ -83,7 +83,7 @@ func (s *putStreamSigner) CloseAndRecv() (*object.PutResponse, error) { func (s *SignService) Put(ctx context.Context) (PutObjectStream, error) { stream, err := s.svc.Put(ctx) if err != nil { - return nil, errors.Wrap(err, "could not create Put object streamer") + return nil, fmt.Errorf("could not create Put object streamer: %w", err) } return &putStreamSigner{ diff --git a/pkg/services/object/util/placement.go b/pkg/services/object/util/placement.go index 393c88b0f..d9ad62f13 100644 --- a/pkg/services/object/util/placement.go +++ b/pkg/services/object/util/placement.go @@ -1,13 +1,14 @@ package util import ( + "fmt" + netmapSDK "github.com/nspcc-dev/neofs-api-go/pkg/netmap" "github.com/nspcc-dev/neofs-api-go/pkg/object" "github.com/nspcc-dev/neofs-node/pkg/core/container" "github.com/nspcc-dev/neofs-node/pkg/core/netmap" "github.com/nspcc-dev/neofs-node/pkg/network" "github.com/nspcc-dev/neofs-node/pkg/services/object_manager/placement" - "github.com/pkg/errors" ) type localPlacement struct { @@ -44,7 +45,7 @@ func NewLocalPlacement(b placement.Builder, s network.LocalAddressSource) placem func (p *localPlacement) BuildPlacement(addr *object.Address, policy *netmapSDK.PlacementPolicy) ([]netmapSDK.Nodes, error) { vs, err := p.builder.BuildPlacement(addr, policy) if err != nil { - return nil, errors.Wrapf(err, "(%T) could not build object placement", p) + return nil, fmt.Errorf("(%T) could not build object placement: %w", p, err) } for i := range vs { @@ -61,7 +62,7 @@ func (p *localPlacement) BuildPlacement(addr *object.Address, policy *netmapSDK. } } - return nil, errors.Errorf("(%T) local node is outside of object placement", p) + return nil, fmt.Errorf("(%T) local node is outside of object placement", p) } // NewRemotePlacementBuilder creates, initializes and returns placement builder that @@ -76,7 +77,7 @@ func NewRemotePlacementBuilder(b placement.Builder, s network.LocalAddressSource func (p *remotePlacement) BuildPlacement(addr *object.Address, policy *netmapSDK.PlacementPolicy) ([]netmapSDK.Nodes, error) { vs, err := p.builder.BuildPlacement(addr, policy) if err != nil { - return nil, errors.Wrapf(err, "(%T) could not build object placement", p) + return nil, fmt.Errorf("(%T) could not build object placement: %w", p, err) } for i := range vs { @@ -122,13 +123,13 @@ func (g *TraverserGenerator) GenerateTraverser(addr *object.Address, epoch uint6 // get network map by epoch nm, err := g.netMapSrc.GetNetMapByEpoch(epoch) if err != nil { - return nil, errors.Wrapf(err, "could not get network map #%d", epoch) + return nil, fmt.Errorf("could not get network map #%d: %w", epoch, err) } // get container related container cnr, err := g.cnrSrc.Get(addr.ContainerID()) if err != nil { - return nil, errors.Wrap(err, "could not get container") + return nil, fmt.Errorf("could not get container: %w", err) } // allocate placement traverser options diff --git a/pkg/services/object_manager/placement/netmap.go b/pkg/services/object_manager/placement/netmap.go index c82725689..5c074b083 100644 --- a/pkg/services/object_manager/placement/netmap.go +++ b/pkg/services/object_manager/placement/netmap.go @@ -1,10 +1,11 @@ package placement import ( + "fmt" + netmapSDK "github.com/nspcc-dev/neofs-api-go/pkg/netmap" "github.com/nspcc-dev/neofs-api-go/pkg/object" "github.com/nspcc-dev/neofs-node/pkg/core/netmap" - "github.com/pkg/errors" ) type netMapBuilder struct { @@ -36,12 +37,12 @@ func (s *netMapSrc) GetNetMap(diff uint64) (*netmapSDK.Netmap, error) { func (b *netMapBuilder) BuildPlacement(a *object.Address, p *netmapSDK.PlacementPolicy) ([]netmapSDK.Nodes, error) { nm, err := netmap.GetLatestNetworkMap(b.nmSrc) if err != nil { - return nil, errors.Wrap(err, "could not get network map") + return nil, fmt.Errorf("could not get network map: %w", err) } cn, err := nm.GetContainerNodes(p, a.ContainerID().ToV2().GetValue()) if err != nil { - return nil, errors.Wrap(err, "could not get container nodes") + return nil, fmt.Errorf("could not get container nodes: %w", err) } return BuildObjectPlacement(nm, cn, a.ObjectID()) @@ -55,7 +56,7 @@ func BuildObjectPlacement(nm *netmapSDK.Netmap, cnrNodes netmapSDK.ContainerNode on, err := nm.GetPlacementVectors(cnrNodes, objectID.GetValue()) if err != nil { - return nil, errors.Wrap(err, "could not get placement vectors for object") + return nil, fmt.Errorf("could not get placement vectors for object: %w", err) } return on, nil diff --git a/pkg/services/object_manager/placement/traverser.go b/pkg/services/object_manager/placement/traverser.go index b578bf0a4..336951feb 100644 --- a/pkg/services/object_manager/placement/traverser.go +++ b/pkg/services/object_manager/placement/traverser.go @@ -1,13 +1,14 @@ package placement import ( + "errors" + "fmt" "sync" "github.com/nspcc-dev/neofs-api-go/pkg/container" "github.com/nspcc-dev/neofs-api-go/pkg/netmap" "github.com/nspcc-dev/neofs-api-go/pkg/object" "github.com/nspcc-dev/neofs-node/pkg/network" - "github.com/pkg/errors" ) // Builder is an interface of the @@ -70,14 +71,14 @@ func NewTraverser(opts ...Option) (*Traverser, error) { } if cfg.builder == nil { - return nil, errors.Wrap(errNilBuilder, invalidOptsMsg) + return nil, fmt.Errorf("%s: %w", invalidOptsMsg, errNilBuilder) } else if cfg.policy == nil { - return nil, errors.Wrap(errNilPolicy, invalidOptsMsg) + return nil, fmt.Errorf("%s: %w", invalidOptsMsg, errNilPolicy) } ns, err := cfg.builder.BuildPlacement(cfg.addr, cfg.policy) if err != nil { - return nil, errors.Wrap(err, "could not build placement") + return nil, fmt.Errorf("could not build placement: %w", err) } var rem []int diff --git a/pkg/services/object_manager/transformer/fmt.go b/pkg/services/object_manager/transformer/fmt.go index a470ef057..0b8b3d5c7 100644 --- a/pkg/services/object_manager/transformer/fmt.go +++ b/pkg/services/object_manager/transformer/fmt.go @@ -2,13 +2,13 @@ package transformer import ( "crypto/ecdsa" + "fmt" "github.com/nspcc-dev/neofs-api-go/pkg" objectSDK "github.com/nspcc-dev/neofs-api-go/pkg/object" "github.com/nspcc-dev/neofs-api-go/pkg/token" "github.com/nspcc-dev/neofs-node/pkg/core/netmap" "github.com/nspcc-dev/neofs-node/pkg/core/object" - "github.com/pkg/errors" ) type formatter struct { @@ -81,7 +81,7 @@ func (f *formatter) Close() (*AccessIdentifiers, error) { rawPar.SetCreationEpoch(curEpoch) if err := objectSDK.SetIDWithSignature(f.prm.Key, rawPar); err != nil { - return nil, errors.Wrap(err, "could not finalize parent object") + return nil, fmt.Errorf("could not finalize parent object: %w", err) } parID = rawPar.ID() @@ -91,15 +91,15 @@ func (f *formatter) Close() (*AccessIdentifiers, error) { } if err := objectSDK.SetIDWithSignature(f.prm.Key, f.obj.SDK()); err != nil { - return nil, errors.Wrap(err, "could not finalize object") + return nil, fmt.Errorf("could not finalize object: %w", err) } if err := f.prm.NextTarget.WriteHeader(f.obj); err != nil { - return nil, errors.Wrap(err, "could not write header to next target") + return nil, fmt.Errorf("could not write header to next target: %w", err) } if _, err := f.prm.NextTarget.Close(); err != nil { - return nil, errors.Wrap(err, "could not close next target") + return nil, fmt.Errorf("could not close next target: %w", err) } return new(AccessIdentifiers). diff --git a/pkg/services/object_manager/transformer/transformer.go b/pkg/services/object_manager/transformer/transformer.go index 5edd1c658..eae8ca2fe 100644 --- a/pkg/services/object_manager/transformer/transformer.go +++ b/pkg/services/object_manager/transformer/transformer.go @@ -10,7 +10,6 @@ import ( objectSDK "github.com/nspcc-dev/neofs-api-go/pkg/object" "github.com/nspcc-dev/neofs-node/pkg/core/object" "github.com/nspcc-dev/tzhash/tz" - "github.com/pkg/errors" ) type payloadSizeLimiter struct { @@ -183,12 +182,12 @@ func (s *payloadSizeLimiter) release(close bool) (*AccessIdentifiers, error) { // release current, get its id if err := s.target.WriteHeader(s.current); err != nil { - return nil, errors.Wrap(err, "could not write header") + return nil, fmt.Errorf("could not write header: %w", err) } ids, err := s.target.Close() if err != nil { - return nil, errors.Wrap(err, "could not close target") + return nil, fmt.Errorf("could not close target: %w", err) } // save identifier of the released object @@ -200,7 +199,7 @@ func (s *payloadSizeLimiter) release(close bool) (*AccessIdentifiers, error) { s.initializeCurrent() if _, err := s.release(false); err != nil { - return nil, errors.Wrap(err, "could not release linking object") + return nil, fmt.Errorf("could not release linking object: %w", err) } } @@ -229,7 +228,7 @@ func (s *payloadSizeLimiter) writeChunk(chunk []byte) error { // we need to release current object if _, err := s.release(false); err != nil { - return errors.Wrap(err, "could not release object") + return fmt.Errorf("could not release object: %w", err) } // initialize another object @@ -248,7 +247,7 @@ func (s *payloadSizeLimiter) writeChunk(chunk []byte) error { } if _, err := s.chunkWriter.Write(chunk[:cut]); err != nil { - return errors.Wrap(err, "could not write chunk to target") + return fmt.Errorf("could not write chunk to target: %w", err) } // increase written bytes counter diff --git a/pkg/services/reputation/eigentrust/routes/calls.go b/pkg/services/reputation/eigentrust/routes/calls.go index b46f33c92..22fa87576 100644 --- a/pkg/services/reputation/eigentrust/routes/calls.go +++ b/pkg/services/reputation/eigentrust/routes/calls.go @@ -1,9 +1,10 @@ package routes import ( + "fmt" + "github.com/nspcc-dev/neofs-node/pkg/services/reputation" "github.com/nspcc-dev/neofs-node/pkg/services/reputation/common" - "github.com/pkg/errors" ) // NextStage builds Manager list for trusted node and returns it directly. @@ -16,7 +17,7 @@ func (b *Builder) NextStage(epoch uint64, t reputation.Trust, passed []common.Se route, err := b.managerBuilder.BuildManagers(epoch, t.Peer()) if err != nil { - return nil, errors.Wrapf(err, "could not build managers for epoch: %d", epoch) + return nil, fmt.Errorf("could not build managers for epoch: %d: %w", epoch, err) } return route, nil diff --git a/pkg/services/reputation/local/controller/calls.go b/pkg/services/reputation/local/controller/calls.go index d4fc9e102..5a73a49a4 100644 --- a/pkg/services/reputation/local/controller/calls.go +++ b/pkg/services/reputation/local/controller/calls.go @@ -2,11 +2,11 @@ package trustcontroller import ( "context" + "errors" "github.com/nspcc-dev/neofs-node/pkg/services/reputation" "github.com/nspcc-dev/neofs-node/pkg/services/reputation/common" "github.com/nspcc-dev/neofs-node/pkg/util/logger" - "github.com/pkg/errors" "go.uber.org/zap" ) diff --git a/pkg/services/reputation/local/routes/calls.go b/pkg/services/reputation/local/routes/calls.go index 8713b53fb..d5d17db6c 100644 --- a/pkg/services/reputation/local/routes/calls.go +++ b/pkg/services/reputation/local/routes/calls.go @@ -1,9 +1,10 @@ package routes import ( + "fmt" + "github.com/nspcc-dev/neofs-node/pkg/services/reputation" "github.com/nspcc-dev/neofs-node/pkg/services/reputation/common" - "github.com/pkg/errors" ) // NextStage builds Manager list for trusting node and returns it directly. @@ -16,7 +17,7 @@ func (b *Builder) NextStage(epoch uint64, t reputation.Trust, passed []common.Se route, err := b.managerBuilder.BuildManagers(epoch, t.TrustingPeer()) if err != nil { - return nil, errors.Wrapf(err, "could not build managers for epoch: %d", epoch) + return nil, fmt.Errorf("could not build managers for epoch: %d: %w", epoch, err) } return route, nil diff --git a/pkg/services/session/executor.go b/pkg/services/session/executor.go index 4aaeeda20..9ca343066 100644 --- a/pkg/services/session/executor.go +++ b/pkg/services/session/executor.go @@ -2,9 +2,9 @@ package session import ( "context" + "fmt" "github.com/nspcc-dev/neofs-api-go/v2/session" - "github.com/pkg/errors" ) type ServiceExecutor interface { @@ -25,7 +25,7 @@ func NewExecutionService(exec ServiceExecutor) Server { func (s *executorSvc) Create(ctx context.Context, req *session.CreateRequest) (*session.CreateResponse, error) { respBody, err := s.exec.Create(ctx, req.GetBody()) if err != nil { - return nil, errors.Wrap(err, "could not execute Create request") + return nil, fmt.Errorf("could not execute Create request: %w", err) } resp := new(session.CreateResponse) diff --git a/pkg/services/session/storage/executor.go b/pkg/services/session/storage/executor.go index 68b663dcd..fc152f288 100644 --- a/pkg/services/session/storage/executor.go +++ b/pkg/services/session/storage/executor.go @@ -5,13 +5,13 @@ import ( "crypto/ecdsa" "crypto/elliptic" "crypto/rand" + "fmt" "github.com/google/uuid" "github.com/mr-tron/base58" "github.com/nspcc-dev/neofs-api-go/pkg/owner" "github.com/nspcc-dev/neofs-api-go/v2/session" crypto "github.com/nspcc-dev/neofs-crypto" - "github.com/pkg/errors" ) func (s *TokenStore) Create(ctx context.Context, body *session.CreateRequestBody) (*session.CreateResponseBody, error) { @@ -22,12 +22,12 @@ func (s *TokenStore) Create(ctx context.Context, body *session.CreateRequestBody uid, err := uuid.NewRandom() if err != nil { - return nil, errors.Wrap(err, "could not generate token ID") + return nil, fmt.Errorf("could not generate token ID: %w", err) } uidBytes, err := uid.MarshalBinary() if err != nil { - return nil, errors.Wrap(err, "could not marshal token ID") + return nil, fmt.Errorf("could not marshal token ID: %w", err) } sk, err := ecdsa.GenerateKey(elliptic.P256(), rand.Reader) diff --git a/pkg/services/util/response/client_stream.go b/pkg/services/util/response/client_stream.go index 2e8196280..0ad3b42fd 100644 --- a/pkg/services/util/response/client_stream.go +++ b/pkg/services/util/response/client_stream.go @@ -1,8 +1,9 @@ package response import ( + "fmt" + "github.com/nspcc-dev/neofs-node/pkg/services/util" - "github.com/pkg/errors" ) // ClientMessageStreamer represents client-side message streamer @@ -17,9 +18,10 @@ type ClientMessageStreamer struct { // Recv calls send method of internal streamer. func (s *ClientMessageStreamer) Send(req interface{}) error { - return errors.Wrapf( - s.send(req), - "(%T) could not send the request", s) + if err := s.send(req); err != nil { + return fmt.Errorf("(%T) could not send the request: %w", s, err) + } + return nil } // CloseAndRecv closes internal stream, receivers the response, @@ -27,7 +29,7 @@ func (s *ClientMessageStreamer) Send(req interface{}) error { func (s *ClientMessageStreamer) CloseAndRecv() (util.ResponseMessage, error) { resp, err := s.close() if err != nil { - return nil, errors.Wrapf(err, "(%T) could not close stream and receive response", s) + return nil, fmt.Errorf("(%T) could not close stream and receive response: %w", s, err) } setMeta(resp, s.cfg) diff --git a/pkg/services/util/response/server_stream.go b/pkg/services/util/response/server_stream.go index 102d582b1..33534f42f 100644 --- a/pkg/services/util/response/server_stream.go +++ b/pkg/services/util/response/server_stream.go @@ -1,8 +1,9 @@ package response import ( + "fmt" + "github.com/nspcc-dev/neofs-node/pkg/services/util" - "github.com/pkg/errors" ) // ServerMessageStreamer represents server-side message streamer @@ -18,7 +19,7 @@ type ServerMessageStreamer struct { func (s *ServerMessageStreamer) Recv() (util.ResponseMessage, error) { m, err := s.recv() if err != nil { - return nil, errors.Wrap(err, "could not receive response message for signing") + return nil, fmt.Errorf("could not receive response message for signing: %w", err) } setMeta(m, s.cfg) diff --git a/pkg/services/util/response/unary.go b/pkg/services/util/response/unary.go index 0ca84b4e2..793bc7d29 100644 --- a/pkg/services/util/response/unary.go +++ b/pkg/services/util/response/unary.go @@ -2,9 +2,9 @@ package response import ( "context" + "fmt" "github.com/nspcc-dev/neofs-node/pkg/services/util" - "github.com/pkg/errors" ) // HandleUnaryRequest call passes request to handler, sets response meta header values and returns it. @@ -12,7 +12,7 @@ func (s *Service) HandleUnaryRequest(ctx context.Context, req interface{}, handl // process request resp, err := handler(ctx, req) if err != nil { - return nil, errors.Wrap(err, "could not handle request") + return nil, fmt.Errorf("could not handle request: %w", err) } setMeta(resp, s.cfg) diff --git a/pkg/services/util/sign.go b/pkg/services/util/sign.go index e9ab13368..5c239b2b2 100644 --- a/pkg/services/util/sign.go +++ b/pkg/services/util/sign.go @@ -3,10 +3,10 @@ package util import ( "context" "crypto/ecdsa" + "fmt" "github.com/nspcc-dev/neofs-api-go/v2/session" "github.com/nspcc-dev/neofs-api-go/v2/signature" - "github.com/pkg/errors" ) // ResponseMessage is an interface of NeoFS response message. @@ -54,7 +54,7 @@ func NewUnarySignService(key *ecdsa.PrivateKey) *SignService { func (s *RequestMessageStreamer) Send(req interface{}) error { // verify request signatures if err := signature.VerifyServiceMessage(req); err != nil { - return errors.Wrap(err, "could not verify request") + return fmt.Errorf("could not verify request: %w", err) } return s.send(req) @@ -63,11 +63,11 @@ func (s *RequestMessageStreamer) Send(req interface{}) error { func (s *RequestMessageStreamer) CloseAndRecv() (ResponseMessage, error) { resp, err := s.close() if err != nil { - return nil, errors.Wrap(err, "could not close stream and receive response") + return nil, fmt.Errorf("could not close stream and receive response: %w", err) } if err := signature.SignServiceMessage(s.key, resp); err != nil { - return nil, errors.Wrap(err, "could not sign response") + return nil, fmt.Errorf("could not sign response: %w", err) } return resp, nil @@ -84,11 +84,11 @@ func (s *SignService) CreateRequestStreamer(sender RequestMessageWriter, closer func (s *ResponseMessageStreamer) Recv() (ResponseMessage, error) { m, err := s.recv() if err != nil { - return nil, errors.Wrap(err, "could not receive response message for signing") + return nil, fmt.Errorf("could not receive response message for signing: %w", err) } if err := signature.SignServiceMessage(s.key, m); err != nil { - return nil, errors.Wrap(err, "could not sign response message") + return nil, fmt.Errorf("could not sign response message: %w", err) } return m, nil @@ -97,12 +97,12 @@ func (s *ResponseMessageStreamer) Recv() (ResponseMessage, error) { func (s *SignService) HandleServerStreamRequest(req interface{}, respWriter ResponseMessageWriter) (ResponseMessageWriter, error) { // verify request signatures if err := signature.VerifyServiceMessage(req); err != nil { - return nil, errors.Wrap(err, "could not verify request") + return nil, fmt.Errorf("could not verify request: %w", err) } return func(resp ResponseMessage) error { if err := signature.SignServiceMessage(s.key, resp); err != nil { - return errors.Wrap(err, "could not sign response message") + return fmt.Errorf("could not sign response message: %w", err) } return respWriter(resp) @@ -112,18 +112,18 @@ func (s *SignService) HandleServerStreamRequest(req interface{}, respWriter Resp func (s *SignService) HandleUnaryRequest(ctx context.Context, req interface{}, handler UnaryHandler) (ResponseMessage, error) { // verify request signatures if err := signature.VerifyServiceMessage(req); err != nil { - return nil, errors.Wrap(err, "could not verify request") + return nil, fmt.Errorf("could not verify request: %w", err) } // process request resp, err := handler(ctx, req) if err != nil { - return nil, errors.Wrap(err, "could not handle request") + return nil, fmt.Errorf("could not handle request: %w", err) } // sign the response if err := signature.SignServiceMessage(s.key, resp); err != nil { - return nil, errors.Wrap(err, "could not sign response") + return nil, fmt.Errorf("could not sign response: %w", err) } return resp, nil diff --git a/pkg/util/http/calls.go b/pkg/util/http/calls.go index acb5ce7d4..e06a6420a 100644 --- a/pkg/util/http/calls.go +++ b/pkg/util/http/calls.go @@ -2,9 +2,8 @@ package httputil import ( "context" + "errors" "net/http" - - "github.com/pkg/errors" ) // Serve listens and serves internal HTTP server. diff --git a/pkg/util/locode/column/coordinates.go b/pkg/util/locode/column/coordinates.go index ed4581d71..076ac38f5 100644 --- a/pkg/util/locode/column/coordinates.go +++ b/pkg/util/locode/column/coordinates.go @@ -1,10 +1,10 @@ package locodecolumn import ( + "fmt" "strings" "github.com/nspcc-dev/neofs-node/pkg/util/locode" - "github.com/pkg/errors" ) const ( @@ -178,12 +178,12 @@ func CoordinatesFromString(s string) (*Coordinates, error) { lat, err := LatitudeFromString(strs[0]) if err != nil { - return nil, errors.Wrap(err, "could not parse latitude") + return nil, fmt.Errorf("could not parse latitude: %w", err) } lng, err := LongitudeFromString(strs[1]) if err != nil { - return nil, errors.Wrap(err, "could not parse longitude") + return nil, fmt.Errorf("could not parse longitude: %w", err) } return &Coordinates{ diff --git a/pkg/util/locode/db/airports/calls.go b/pkg/util/locode/db/airports/calls.go index 33d1fd783..35a6d8aeb 100644 --- a/pkg/util/locode/db/airports/calls.go +++ b/pkg/util/locode/db/airports/calls.go @@ -2,13 +2,14 @@ package airportsdb import ( "encoding/csv" + "errors" + "fmt" "io" "os" "strconv" "github.com/nspcc-dev/neofs-node/pkg/util/locode" locodedb "github.com/nspcc-dev/neofs-node/pkg/util/locode/db" - "github.com/pkg/errors" ) const ( @@ -177,7 +178,7 @@ func (db *DB) scanWords(pm pathMode, num int, wordsHandler func([]string) error) return err } else if ln := len(words); ln != num { - return errors.Errorf("unexpected number of words %d", ln) + return fmt.Errorf("unexpected number of words %d", ln) } if err := wordsHandler(words); err != nil { diff --git a/pkg/util/locode/db/boltdb/calls.go b/pkg/util/locode/db/boltdb/calls.go index 2e88a9336..4176e21b0 100644 --- a/pkg/util/locode/db/boltdb/calls.go +++ b/pkg/util/locode/db/boltdb/calls.go @@ -2,11 +2,12 @@ package locodebolt import ( "encoding/json" + "errors" + "fmt" "os" "path" locodedb "github.com/nspcc-dev/neofs-node/pkg/util/locode/db" - "github.com/pkg/errors" "go.etcd.io/bbolt" ) @@ -21,12 +22,12 @@ func (db *DB) Open() error { err := os.MkdirAll(path.Dir(db.path), db.mode) if err != nil { - return errors.Wrap(err, "could not create dir for BoltDB") + return fmt.Errorf("could not create dir for BoltDB: %w", err) } db.bolt, err = bbolt.Open(db.path, db.mode, db.boltOpts) if err != nil { - return errors.Wrap(err, "could not open BoltDB") + return fmt.Errorf("could not open BoltDB: %w", err) } return nil @@ -110,7 +111,7 @@ func (db *DB) Put(key locodedb.Key, rec locodedb.Record) error { bktCountry, err := tx.CreateBucketIfNotExists(countryKey) if err != nil { - return errors.Wrap(err, "could not create country bucket") + return fmt.Errorf("could not create country bucket: %w", err) } // TODO: write country name once in Country bucket diff --git a/pkg/util/locode/db/continents/geojson/calls.go b/pkg/util/locode/db/continents/geojson/calls.go index 7a7edb563..288fded6f 100644 --- a/pkg/util/locode/db/continents/geojson/calls.go +++ b/pkg/util/locode/db/continents/geojson/calls.go @@ -1,13 +1,13 @@ package continentsdb import ( + "fmt" "io/ioutil" locodedb "github.com/nspcc-dev/neofs-node/pkg/util/locode/db" "github.com/paulmach/orb" "github.com/paulmach/orb/geojson" "github.com/paulmach/orb/planar" - "github.com/pkg/errors" ) const continentProperty = "Continent" @@ -55,12 +55,12 @@ func (db *DB) PointContinent(point *locodedb.Point) (*locodedb.Continent, error) func (db *DB) init() error { data, err := ioutil.ReadFile(db.path) if err != nil { - return errors.Wrap(err, "could not read data file") + return fmt.Errorf("could not read data file: %w", err) } features, err := geojson.UnmarshalFeatureCollection(data) if err != nil { - return errors.Wrap(err, "could not unmarshal GeoJSON feature collection") + return fmt.Errorf("could not unmarshal GeoJSON feature collection: %w", err) } db.features = features.Features diff --git a/pkg/util/locode/db/country.go b/pkg/util/locode/db/country.go index d2679bf0b..c63add3b7 100644 --- a/pkg/util/locode/db/country.go +++ b/pkg/util/locode/db/country.go @@ -1,8 +1,9 @@ package locodedb import ( + "fmt" + locodecolumn "github.com/nspcc-dev/neofs-node/pkg/util/locode/column" - "github.com/pkg/errors" ) // CountryCode represents country code for @@ -14,7 +15,7 @@ type CountryCode locodecolumn.CountryCode func CountryCodeFromString(s string) (*CountryCode, error) { cc, err := locodecolumn.CountryCodeFromString(s) if err != nil { - return nil, errors.Wrap(err, "could not parse country code") + return nil, fmt.Errorf("could not parse country code: %w", err) } return CountryFromColumn(cc) diff --git a/pkg/util/locode/db/db.go b/pkg/util/locode/db/db.go index 1c47dba7d..906c03616 100644 --- a/pkg/util/locode/db/db.go +++ b/pkg/util/locode/db/db.go @@ -1,8 +1,10 @@ package locodedb import ( + "errors" + "fmt" + "github.com/nspcc-dev/neofs-node/pkg/util/locode" - "github.com/pkg/errors" ) // SourceTable is an interface of the UN/LOCODE table. @@ -139,7 +141,7 @@ func FillDatabase(table SourceTable, airports AirportDB, continents ContinentsDB continent, err := continents.PointContinent(geoPoint) if err != nil { - return errors.Wrap(err, "could not calculate continent geo point") + return fmt.Errorf("could not calculate continent geo point: %w", err) } else if continent.Is(ContinentUnknown) { return nil } @@ -155,7 +157,7 @@ func FillDatabase(table SourceTable, airports AirportDB, continents ContinentsDB func LocodeRecord(db DB, sLocode string) (*Record, error) { lc, err := locode.FromString(sLocode) if err != nil { - return nil, errors.Wrap(err, "could not parse locode") + return nil, fmt.Errorf("could not parse locode: %w", err) } key, err := NewKey(*lc) diff --git a/pkg/util/locode/db/location.go b/pkg/util/locode/db/location.go index e353f3927..c7c5262f0 100644 --- a/pkg/util/locode/db/location.go +++ b/pkg/util/locode/db/location.go @@ -1,8 +1,9 @@ package locodedb import ( + "fmt" + locodecolumn "github.com/nspcc-dev/neofs-node/pkg/util/locode/column" - "github.com/pkg/errors" ) // LocationCode represents location code for @@ -14,7 +15,7 @@ type LocationCode locodecolumn.LocationCode func LocationCodeFromString(s string) (*LocationCode, error) { lc, err := locodecolumn.LocationCodeFromString(s) if err != nil { - return nil, errors.Wrap(err, "could not parse location code") + return nil, fmt.Errorf("could not parse location code: %w", err) } return LocationFromColumn(lc) diff --git a/pkg/util/locode/db/record.go b/pkg/util/locode/db/record.go index eea167a8f..b38532121 100644 --- a/pkg/util/locode/db/record.go +++ b/pkg/util/locode/db/record.go @@ -1,9 +1,11 @@ package locodedb import ( + "errors" + "fmt" + "github.com/nspcc-dev/neofs-node/pkg/util/locode" locodecolumn "github.com/nspcc-dev/neofs-node/pkg/util/locode/column" - "github.com/pkg/errors" ) // Key represents the key in NeoFS location database. @@ -17,12 +19,12 @@ type Key struct { func NewKey(lc locode.LOCODE) (*Key, error) { country, err := CountryCodeFromString(lc.CountryCode()) if err != nil { - return nil, errors.Wrap(err, "could not parse country") + return nil, fmt.Errorf("could not parse country: %w", err) } location, err := LocationCodeFromString(lc.LocationCode()) if err != nil { - return nil, errors.Wrap(err, "could not parse location") + return nil, fmt.Errorf("could not parse location: %w", err) } return &Key{ @@ -62,12 +64,12 @@ var errParseCoordinates = errors.New("invalid coordinates") func NewRecord(r locode.Record) (*Record, error) { crd, err := locodecolumn.CoordinatesFromString(r.Coordinates) if err != nil { - return nil, errors.Wrap(errParseCoordinates, err.Error()) + return nil, fmt.Errorf("%w: %v", errParseCoordinates, err) } point, err := PointFromCoordinates(crd) if err != nil { - return nil, errors.Wrap(err, "could not parse geo point") + return nil, fmt.Errorf("could not parse geo point: %w", err) } return &Record{ diff --git a/pkg/util/locode/record.go b/pkg/util/locode/record.go index 8e88ea677..b9922b740 100644 --- a/pkg/util/locode/record.go +++ b/pkg/util/locode/record.go @@ -1,9 +1,8 @@ package locode import ( + "errors" "strings" - - "github.com/pkg/errors" ) // LOCODE represents code from UN/LOCODE coding scheme. diff --git a/pkg/util/locode/table/csv/calls.go b/pkg/util/locode/table/csv/calls.go index 77bce5b14..fae65885b 100644 --- a/pkg/util/locode/table/csv/calls.go +++ b/pkg/util/locode/table/csv/calls.go @@ -2,13 +2,13 @@ package csvlocode import ( "encoding/csv" + "errors" "io" "os" "strings" "github.com/nspcc-dev/neofs-node/pkg/util/locode" locodedb "github.com/nspcc-dev/neofs-node/pkg/util/locode/db" - "github.com/pkg/errors" ) var errInvalidRecord = errors.New("invalid table record")