diff --git a/pkg/core/container/storage.go b/pkg/core/container/storage.go index fc899f36..5f6f23d2 100644 --- a/pkg/core/container/storage.go +++ b/pkg/core/container/storage.go @@ -3,6 +3,7 @@ package container import ( "errors" + apistatus "github.com/nspcc-dev/neofs-sdk-go/client/status" "github.com/nspcc-dev/neofs-sdk-go/container" cid "github.com/nspcc-dev/neofs-sdk-go/container/id" ) @@ -14,15 +15,18 @@ type Source interface { // It returns the pointer to requested container and any error encountered. // // Get must return exactly one non-nil value. - // Get must return ErrNotFound if the container is not in storage. + // Get must return apistatus.ContainerNotFound if the container is not in storage. // // Implementations must not retain the container pointer and modify // the container through it. Get(*cid.ID) (*container.Container, error) } -// ErrNotFound is the error returned when container was not found in storage. -var ErrNotFound = errors.New("container not found") +// IsErrNotFound checks if error returned by Source.Get corresponds +// to missing container. +func IsErrNotFound(err error) bool { + return errors.As(err, new(apistatus.ContainerNotFound)) +} // ErrEACLNotFound is returned by eACL storage implementations when // requested eACL table is not in storage. diff --git a/pkg/morph/client/container/get.go b/pkg/morph/client/container/get.go index bc25e596..43663ec9 100644 --- a/pkg/morph/client/container/get.go +++ b/pkg/morph/client/container/get.go @@ -7,6 +7,7 @@ import ( containerContract "github.com/nspcc-dev/neofs-contract/container" core "github.com/nspcc-dev/neofs-node/pkg/core/container" "github.com/nspcc-dev/neofs-node/pkg/morph/client" + apistatus "github.com/nspcc-dev/neofs-sdk-go/client/status" "github.com/nspcc-dev/neofs-sdk-go/container" cid "github.com/nspcc-dev/neofs-sdk-go/container/id" "github.com/nspcc-dev/neofs-sdk-go/session" @@ -45,7 +46,9 @@ func (c *Client) Get(cid []byte) (*container.Container, error) { res, err := c.client.TestInvoke(prm) if err != nil { if strings.Contains(err.Error(), containerContract.NotFoundError) { - return nil, core.ErrNotFound + var errNotFound apistatus.ContainerNotFound + + return nil, errNotFound } return nil, fmt.Errorf("could not perform test invocation (%s): %w", getMethod, err) } else if ln := len(res); ln != 1 { diff --git a/pkg/services/object/acl/v2/errors.go b/pkg/services/object/acl/v2/errors.go index 77c714c8..5db87fe7 100644 --- a/pkg/services/object/acl/v2/errors.go +++ b/pkg/services/object/acl/v2/errors.go @@ -11,8 +11,6 @@ var ( ErrMalformedRequest = errors.New("malformed request") // ErrUnknownRole is returned when role of the sender is unknown. ErrUnknownRole = errors.New("can't classify request sender") - // ErrUnknownContainer is returned when container fetching errors appeared. - ErrUnknownContainer = errors.New("can't fetch container info") // ErrInvalidVerb is returned when session token verb doesn't include necessary operation. ErrInvalidVerb = errors.New("session token verb is invalid") ) diff --git a/pkg/services/object/acl/v2/service.go b/pkg/services/object/acl/v2/service.go index 43c131af..4d32ad38 100644 --- a/pkg/services/object/acl/v2/service.go +++ b/pkg/services/object/acl/v2/service.go @@ -2,6 +2,7 @@ package v2 import ( "context" + "errors" "fmt" objectV2 "github.com/nspcc-dev/neofs-api-go/v2/object" @@ -410,8 +411,10 @@ func (b Service) findRequestInfo( cid *cidSDK.ID, op eaclSDK.Operation) (info RequestInfo, err error) { cnr, err := b.containers.Get(cid) // fetch actual container - if err != nil || cnr.OwnerID() == nil { - return info, ErrUnknownContainer + if err != nil { + return info, err + } else if cnr.OwnerID() == nil { + return info, errors.New("missing owner in container descriptor") } // find request role and key diff --git a/pkg/services/policer/check.go b/pkg/services/policer/check.go index a7b1b73d..aad915bf 100644 --- a/pkg/services/policer/check.go +++ b/pkg/services/policer/check.go @@ -2,7 +2,6 @@ package policer import ( "context" - "errors" "strings" "github.com/nspcc-dev/neofs-node/pkg/core/container" @@ -21,7 +20,7 @@ func (p *Policer) processObject(ctx context.Context, addr *addressSDK.Address) { zap.Stringer("cid", addr.ContainerID()), zap.String("error", err.Error()), ) - if errors.Is(err, container.ErrNotFound) { + if container.IsErrNotFound(err) { prm := new(engine.InhumePrm) prm.MarkAsGarbage(addr) _, err := p.jobQueue.localStorage.Inhume(prm)