Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle client errors according to NeoFS SDK RC-9 #2469

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 3 additions & 7 deletions cmd/neofs-cli/internal/common/exit.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,11 @@ func ExitOnErr(cmd *cobra.Command, errFmt string, err error) {
aclDenied
)

var (
code int

internalErr = new(sdkstatus.ServerInternal)
accessErr = new(sdkstatus.ObjectAccessDenied)
)
var code int
var accessErr = new(sdkstatus.ObjectAccessDenied)

switch {
case errors.As(err, &internalErr):
case errors.Is(err, sdkstatus.ErrServerInternal):
code = internal
case errors.As(err, &accessErr):
code = aclDenied
Expand Down
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
Loading