forked from TrueCloudLab/frostfs-node
[#521] *: use stdlib errors
package
Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
This commit is contained in:
parent
43e575cec2
commit
71b87155ef
171 changed files with 825 additions and 674 deletions
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue