From 71b87155ef81adb6883b5521a2198ae77be7d58a Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Tue, 18 May 2021 11:12:51 +0300 Subject: [PATCH] [#521] *: use stdlib `errors` package Signed-off-by: Evgenii Stratonikov --- cmd/neofs-cli/modules/container.go | 4 +- cmd/neofs-cli/modules/control.go | 7 ++- cmd/neofs-cli/modules/storagegroup.go | 2 +- cmd/neofs-node/attributes.go | 4 +- cmd/neofs-node/config.go | 2 +- cmd/neofs-node/container.go | 21 ++++----- cmd/neofs-node/control.go | 4 +- cmd/neofs-node/netmap.go | 8 ++-- cmd/neofs-node/object.go | 6 +-- cmd/neofs-node/reputation.go | 12 +++--- cmd/neofs-node/reputation/common/remote.go | 7 +-- cmd/neofs-node/reputation/local/storage.go | 2 +- go.mod | 1 - pkg/core/container/fmt.go | 10 +++-- pkg/core/object/errors.go | 2 +- pkg/core/object/fmt.go | 23 +++++----- pkg/core/object/fmt_test.go | 2 +- pkg/innerring/indexer.go | 8 ++-- pkg/innerring/innerring.go | 39 ++++++++--------- pkg/innerring/invoke/enhanced.go | 9 ++-- pkg/innerring/invoke/netmap.go | 6 ++- .../processors/alphabet/processor.go | 6 ++- pkg/innerring/processors/audit/processor.go | 5 ++- pkg/innerring/processors/audit/scheduler.go | 5 ++- pkg/innerring/processors/balance/processor.go | 6 ++- .../processors/container/processor.go | 6 ++- pkg/innerring/processors/governance/list.go | 5 ++- .../processors/governance/processor.go | 6 ++- pkg/innerring/processors/neofs/processor.go | 7 +-- .../netmap/nodevalidation/locode/calls.go | 8 ++-- pkg/innerring/processors/netmap/processor.go | 6 ++- .../processors/reputation/processor.go | 6 ++- .../processors/settlement/processor.go | 3 +- pkg/innerring/settlement.go | 14 +++--- .../blobovnicza/blobovnicza_test.go | 2 +- .../blobovnicza/control.go | 10 +++-- .../blobovnicza/get_range.go | 5 ++- .../blobovnicza/iterate.go | 5 ++- pkg/local_object_storage/blobovnicza/put.go | 8 ++-- pkg/local_object_storage/blobovnicza/sizes.go | 11 +++-- .../blobstor/blobovnicza.go | 18 ++++---- .../blobstor/delete_big.go | 3 +- pkg/local_object_storage/blobstor/exists.go | 3 +- pkg/local_object_storage/blobstor/get_big.go | 10 +++-- .../blobstor/get_range_big.go | 9 ++-- pkg/local_object_storage/blobstor/put.go | 5 ++- pkg/local_object_storage/engine/control.go | 7 +-- pkg/local_object_storage/engine/head.go | 3 +- pkg/local_object_storage/engine/shards.go | 4 +- pkg/local_object_storage/metabase/delete.go | 4 +- .../metabase/delete_test.go | 2 +- .../metabase/graveyard.go | 7 +-- pkg/local_object_storage/metabase/inhume.go | 5 ++- .../metabase/inhume_test.go | 2 +- .../metabase/iterators.go | 11 ++--- pkg/local_object_storage/metabase/select.go | 2 +- pkg/local_object_storage/shard/container.go | 5 ++- pkg/local_object_storage/shard/control.go | 8 ++-- pkg/local_object_storage/shard/delete.go | 3 +- pkg/local_object_storage/shard/get.go | 2 +- pkg/local_object_storage/shard/list.go | 3 +- pkg/local_object_storage/shard/put.go | 7 +-- pkg/local_object_storage/shard/select.go | 5 ++- pkg/morph/client/audit/get_result.go | 9 ++-- pkg/morph/client/audit/list_results.go | 17 ++++---- pkg/morph/client/audit/put_result.go | 11 +++-- pkg/morph/client/audit/wrapper/result.go | 8 ++-- pkg/morph/client/balance/balanceOf.go | 8 ++-- pkg/morph/client/balance/decimals.go | 9 ++-- pkg/morph/client/balance/transfer.go | 11 +++-- pkg/morph/client/balance/wrapper/decimals.go | 5 ++- pkg/morph/client/balance/wrapper/transfer.go | 7 +-- pkg/morph/client/client.go | 8 ++-- pkg/morph/client/container/delete.go | 13 ++++-- pkg/morph/client/container/eacl.go | 17 ++++---- pkg/morph/client/container/eacl_set.go | 13 ++++-- pkg/morph/client/container/estimations.go | 34 +++++++-------- pkg/morph/client/container/get.go | 9 ++-- pkg/morph/client/container/list.go | 11 ++--- pkg/morph/client/container/load.go | 40 ++++++++++-------- pkg/morph/client/container/put.go | 11 +++-- .../client/container/wrapper/container.go | 7 +-- pkg/morph/client/container/wrapper/eacl.go | 5 ++- pkg/morph/client/netmap/add_peer.go | 12 +++--- pkg/morph/client/netmap/config.go | 12 +++--- pkg/morph/client/netmap/epoch.go | 12 +++--- pkg/morph/client/netmap/netmap.go | 32 ++++++-------- pkg/morph/client/netmap/new_epoch.go | 12 +++--- pkg/morph/client/netmap/update_state.go | 12 ++++-- pkg/morph/client/netmap/wrapper/add_peer.go | 12 +++--- pkg/morph/client/netmap/wrapper/config.go | 24 +++++------ pkg/morph/client/netmap/wrapper/epoch.go | 5 ++- pkg/morph/client/netmap/wrapper/netmap.go | 5 ++- .../client/netmap/wrapper/update_state.go | 13 +++--- pkg/morph/client/notary.go | 21 ++++----- pkg/morph/client/reputation/get.go | 13 +++--- pkg/morph/client/reputation/list.go | 11 ++--- pkg/morph/client/reputation/put.go | 20 ++++++--- pkg/morph/client/reputation/wrapper/get.go | 5 ++- pkg/morph/client/reputation/wrapper/put.go | 5 ++- pkg/morph/client/util.go | 16 +++---- pkg/morph/event/balance/lock.go | 17 ++++---- pkg/morph/event/container/delete.go | 7 +-- pkg/morph/event/container/estimates.go | 5 ++- pkg/morph/event/container/put.go | 10 ++--- pkg/morph/event/listener.go | 9 ++-- pkg/morph/event/neofs/bind.go | 12 +++--- pkg/morph/event/neofs/cheque.go | 15 ++++--- pkg/morph/event/neofs/config.go | 9 ++-- pkg/morph/event/neofs/deposit.go | 15 ++++--- pkg/morph/event/neofs/ir_update.go | 8 ++-- pkg/morph/event/neofs/unbind.go | 12 +++--- pkg/morph/event/neofs/withdraw.go | 11 ++--- pkg/morph/event/netmap/add_peer.go | 5 ++- pkg/morph/event/netmap/epoch.go | 5 ++- pkg/morph/event/netmap/update_peer.go | 8 ++-- pkg/morph/event/parser.go | 5 ++- pkg/morph/event/reputation/put.go | 13 +++--- pkg/morph/subscriber/subscriber.go | 7 +-- pkg/network/address.go | 6 +-- pkg/network/transport/object/grpc/service.go | 4 +- pkg/services/accounting/executor.go | 4 +- .../load/route/placement/calls.go | 5 ++- pkg/services/container/executor.go | 14 +++--- pkg/services/container/morph/executor.go | 4 +- pkg/services/control/service.pb.go | Bin 54566 -> 54567 bytes pkg/services/control/types.pb.go | Bin 20076 -> 20077 bytes pkg/services/object/acl/acl.go | 2 +- pkg/services/object/acl/classifier.go | 14 +++--- pkg/services/object/get/get_test.go | 2 +- pkg/services/object/get/local.go | 3 +- pkg/services/object/get/remote.go | 2 +- pkg/services/object/get/v2/service.go | 2 +- pkg/services/object/get/v2/util.go | 37 ++++++++-------- pkg/services/object/head/remote.go | 9 ++-- pkg/services/object/put/distributed.go | 11 ++--- pkg/services/object/put/local.go | 5 ++- pkg/services/object/put/remote.go | 12 +++--- pkg/services/object/put/streamer.go | 27 ++++++------ pkg/services/object/put/v2/service.go | 4 +- pkg/services/object/put/v2/streamer.go | 11 ++--- pkg/services/object/put/validation.go | 8 ++-- pkg/services/object/response.go | 6 +-- pkg/services/object/search/search_test.go | 2 +- pkg/services/object/search/v2/util.go | 9 ++-- pkg/services/object/sign.go | 6 +-- pkg/services/object/util/placement.go | 13 +++--- .../object_manager/placement/netmap.go | 9 ++-- .../object_manager/placement/traverser.go | 9 ++-- .../object_manager/transformer/fmt.go | 10 ++--- .../object_manager/transformer/transformer.go | 11 +++-- .../reputation/eigentrust/routes/calls.go | 5 ++- .../reputation/local/controller/calls.go | 2 +- pkg/services/reputation/local/routes/calls.go | 5 ++- pkg/services/session/executor.go | 4 +- pkg/services/session/storage/executor.go | 6 +-- pkg/services/util/response/client_stream.go | 12 +++--- pkg/services/util/response/server_stream.go | 5 ++- pkg/services/util/response/unary.go | 4 +- pkg/services/util/sign.go | 22 +++++----- pkg/util/http/calls.go | 3 +- pkg/util/locode/column/coordinates.go | 6 +-- pkg/util/locode/db/airports/calls.go | 5 ++- pkg/util/locode/db/boltdb/calls.go | 9 ++-- .../locode/db/continents/geojson/calls.go | 6 +-- pkg/util/locode/db/country.go | 5 ++- pkg/util/locode/db/db.go | 8 ++-- pkg/util/locode/db/location.go | 5 ++- pkg/util/locode/db/record.go | 12 +++--- pkg/util/locode/record.go | 3 +- pkg/util/locode/table/csv/calls.go | 2 +- 171 files changed, 819 insertions(+), 670 deletions(-) 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 9456b1fde8bb27de236c9f43ff636f2a7773d2ce..b81535b9561531dc9bb42076f3b78dd85c498ada 100644 GIT binary patch delta 21 dcmZ3sih21e<_YH~KVX#KcvgsU^M6M5%K&dG3D^Jt delta 19 bcmZ3!ih0>8<_YIFeh^@scurvxllo-