[#1247] container: Return ContainerNotFound status error

Replace `core/container.ErrNotFound` error returned by `Source.Get`
interface method with `apistatus.ContainerNotFound` status error. This
error is returned by storage node's server as NeoFS API statuses.

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
Leonard Lyubich 2022-03-17 11:17:45 +03:00 committed by Alex Vanin
parent 70ffdf3478
commit 967650f2ed
5 changed files with 17 additions and 10 deletions

View file

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

View file

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

View file

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

View file

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

View file

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