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,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
|
||||
}
|
||||
|
|
|
@ -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{
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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{
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue