[#521] *: use stdlib errors package

Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
This commit is contained in:
Evgenii Stratonikov 2021-05-18 11:12:51 +03:00 committed by Alex Vanin
parent 43e575cec2
commit 71b87155ef
171 changed files with 825 additions and 674 deletions

View file

@ -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

View file

@ -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"

View file

@ -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

View file

@ -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)

View file

@ -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)

View file

@ -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

View file

@ -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)

View file

@ -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

View file

@ -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 {