Skip to content

Commit

Permalink
[nspcc-dev#1247] container: Return ContainerNotFound status error
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Leonard Lyubich authored and aprasolova committed Oct 19, 2022
1 parent 6d77020 commit e5f88c7
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 10 deletions.
10 changes: 7 additions & 3 deletions pkg/core/container/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand All @@ -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.
Expand Down
5 changes: 4 additions & 1 deletion pkg/morph/client/container/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 0 additions & 2 deletions pkg/services/object/acl/v2/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
)
Expand Down
7 changes: 5 additions & 2 deletions pkg/services/object/acl/v2/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package v2

import (
"context"
"errors"
"fmt"

objectV2 "github.com/nspcc-dev/neofs-api-go/v2/object"
Expand Down Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions pkg/services/policer/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package policer

import (
"context"
"errors"
"strings"

"github.com/nspcc-dev/neofs-node/pkg/core/container"
Expand All @@ -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)
Expand Down

0 comments on commit e5f88c7

Please sign in to comment.