Skip to content

Commit

Permalink
node: Process API client errors according to NeoFS SDK RC-9 docs
Browse files Browse the repository at this point in the history
Currently used SDK revision changed/improved docs and UX of error
handling. Storage node missed these changes on SDK upgrade, so we have
to adjust to them.

Use `errors.Is` when exact error structure is not needed. Actualize docs
of errors returned by internal client.

Fixes #2465.

Signed-off-by: Leonard Lyubich <[email protected]>
  • Loading branch information
cthulhu-rider committed Aug 8, 2023
1 parent 4a0198f commit a6bcf16
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 21 deletions.
14 changes: 5 additions & 9 deletions pkg/services/object/get/remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,11 @@ func (exec *execCtx) processNode(ctx context.Context, info client.NodeInfo) bool
obj, err := client.getObject(exec, info)

var errSplitInfo *objectSDK.SplitInfoError
var errRemoved *apistatus.ObjectAlreadyRemoved
var errOutOfRange *apistatus.ObjectOutOfRange

switch {
default:
var errNotFound apistatus.ObjectNotFound

exec.status = statusUndefined
exec.err = errNotFound
exec.err = apistatus.ErrObjectNotFound

exec.log.Debug("remote call failed",
zap.String("error", err.Error()),
Expand All @@ -45,12 +41,12 @@ func (exec *execCtx) processNode(ctx context.Context, info client.NodeInfo) bool
exec.collectedObject = obj
exec.writeCollectedObject()
}
case errors.As(err, &errRemoved):
case errors.Is(err, apistatus.ErrObjectAlreadyRemoved):
exec.status = statusINHUMED
exec.err = errRemoved
case errors.As(err, &errOutOfRange):
exec.err = err
case errors.Is(err, apistatus.ErrObjectOutOfRange):
exec.status = statusOutOfRange
exec.err = errOutOfRange
exec.err = err
case errors.As(err, &errSplitInfo):
exec.status = statusVIRTUAL
mergeSplitInfo(exec.splitInfo(), errSplitInfo.SplitInfo())
Expand Down
3 changes: 1 addition & 2 deletions pkg/services/object/get/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,7 @@ func (c *clientWrapper) getObject(exec *execCtx, info coreclient.NodeInfo) (*obj

res, err := internalclient.PayloadRange(prm)
if err != nil {
var errAccessDenied *apistatus.ObjectAccessDenied
if errors.As(err, &errAccessDenied) {
if errors.Is(err, apistatus.ErrObjectAccessDenied) {
// Current spec allows other storage node to deny access,
// fallback to GET here.
obj, err := c.get(exec, key)
Expand Down
4 changes: 3 additions & 1 deletion pkg/services/object/head/remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,9 @@ func (p *RemoteHeadPrm) WithObjectAddress(v oid.Address) *RemoteHeadPrm {
return p
}

// Head requests object header from the remote node.
// Head requests object header from the remote node. Returns:
// - [apistatus.ErrObjectNotFound] error if the requested object is missing
// - [apistatus.ErrNodeUnderMaintenance] error if remote node is currently under maintenance
func (h *RemoteHeader) Head(ctx context.Context, prm *RemoteHeadPrm) (*object.Object, error) {
key, err := h.keyStorage.GetKey(nil)
if err != nil {
Expand Down
18 changes: 9 additions & 9 deletions pkg/services/object/internal/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,8 @@ func (x GetObjectRes) Object() *object.Object {
//
// Returns any error which prevented the operation from completing correctly in error return.
// Returns:
// - error of type *object.SplitInfoError if object raw flag is set and requested object is virtual;
// - error of type *apistatus.ObjectAlreadyRemoved if the requested object is marked to be removed.
// - error of type *object.SplitInfoError if object raw flag is set and requested object is virtual
// - [apistatus.ErrObjectAlreadyRemoved] error if the requested object is marked to be removed
//
// GetObject ignores the provided session if it is not related to the requested object.
func GetObject(prm GetObjectPrm) (*GetObjectRes, error) {
Expand Down Expand Up @@ -228,9 +228,9 @@ func (x HeadObjectRes) Header() *object.Object {
//
// Returns any error which prevented the operation from completing correctly in error return.
// Returns:
//
// error of type *object.SplitInfoError if object raw flag is set and requested object is virtual;
// error of type *apistatus.ObjectAlreadyRemoved if the requested object is marked to be removed.
// - error of type *object.SplitInfoError if object raw flag is set and requested object is virtual
// - [apistatus.ErrObjectAlreadyRemoved] error if the requested object is marked to be removed
// - [apistatus.ErrNodeUnderMaintenance] error if remote node is currently under maintenance
//
// HeadObject ignores the provided session if it is not related to the requested object.
func HeadObject(prm HeadObjectPrm) (*HeadObjectRes, error) {
Expand Down Expand Up @@ -321,10 +321,10 @@ const maxInitialBufferSize = 1024 * 1024 // 1 MiB
//
// Returns any error which prevented the operation from completing correctly in error return.
// Returns:
//
// error of type *object.SplitInfoError if object raw flag is set and requested object is virtual;
// error of type *apistatus.ObjectAlreadyRemoved if the requested object is marked to be removed;
// error of type *apistatus.ObjectOutOfRange if the requested range is too big.
// - error of type *object.SplitInfoError if object raw flag is set and requested object is virtual
// - [apistatus.ErrObjectAlreadyRemoved] error if the requested object is marked to be removed
// - [apistatus.ErrObjectOutOfRange] error if the requested range is too big
// - [apistatus.ErrObjectAccessDenied] error if access to the requested object is denied
//
// PayloadRange ignores the provided session if it is not related to the requested object.
func PayloadRange(prm PayloadRangePrm) (*PayloadRangeRes, error) {
Expand Down

0 comments on commit a6bcf16

Please sign in to comment.