From e0afe0807c6b6af668d06295c6d09b4e6bc9e3b9 Mon Sep 17 00:00:00 2001 From: Evgenii Baidakov Date: Tue, 16 May 2023 15:44:58 +0400 Subject: [PATCH] client: Fix error checking for go 1.18-19 Should be reverted/updated when minimum version of Go will be set to 1.20 Signed-off-by: Evgenii Baidakov --- client/status/common.go | 8 ++++---- client/status/container.go | 6 ++++-- client/status/object.go | 14 ++++++++------ client/status/session.go | 6 ++++-- client/status/status.go | 6 +----- 5 files changed, 21 insertions(+), 19 deletions(-) diff --git a/client/status/common.go b/client/status/common.go index ef33f08..ec01eb9 100644 --- a/client/status/common.go +++ b/client/status/common.go @@ -45,7 +45,7 @@ func (x ServerInternal) Error() string { func (x ServerInternal) Is(target error) bool { switch target.(type) { default: - return false + return errors.Is(Error, target) case ServerInternal, *ServerInternal: return true } @@ -103,7 +103,7 @@ func (x WrongMagicNumber) Error() string { func (x WrongMagicNumber) Is(target error) bool { switch target.(type) { default: - return false + return errors.Is(Error, target) case WrongMagicNumber, *WrongMagicNumber: return true } @@ -188,7 +188,7 @@ func (x SignatureVerification) Error() string { func (x SignatureVerification) Is(target error) bool { switch target.(type) { default: - return false + return errors.Is(Error, target) case SignatureVerification, *SignatureVerification: return true } @@ -257,7 +257,7 @@ func (x NodeUnderMaintenance) Error() string { func (x NodeUnderMaintenance) Is(target error) bool { switch target.(type) { default: - return false + return errors.Is(Error, target) case NodeUnderMaintenance, *NodeUnderMaintenance: return true } diff --git a/client/status/container.go b/client/status/container.go index 3c92c18..c643123 100644 --- a/client/status/container.go +++ b/client/status/container.go @@ -1,6 +1,8 @@ package apistatus import ( + "errors" + "github.com/nspcc-dev/neofs-api-go/v2/container" "github.com/nspcc-dev/neofs-api-go/v2/status" ) @@ -38,7 +40,7 @@ func (x ContainerNotFound) Error() string { func (x ContainerNotFound) Is(target error) bool { switch target.(type) { default: - return false + return errors.Is(Error, target) case ContainerNotFound, *ContainerNotFound: return true } @@ -86,7 +88,7 @@ func (x EACLNotFound) Error() string { func (x EACLNotFound) Is(target error) bool { switch target.(type) { default: - return false + return errors.Is(Error, target) case EACLNotFound, *EACLNotFound: return true } diff --git a/client/status/object.go b/client/status/object.go index 1fbebb6..2726088 100644 --- a/client/status/object.go +++ b/client/status/object.go @@ -1,6 +1,8 @@ package apistatus import ( + "errors" + "github.com/nspcc-dev/neofs-api-go/v2/object" "github.com/nspcc-dev/neofs-api-go/v2/status" ) @@ -50,7 +52,7 @@ func (x ObjectLocked) Error() string { func (x ObjectLocked) Is(target error) bool { switch target.(type) { default: - return false + return errors.Is(Error, target) case ObjectLocked, *ObjectLocked: return true } @@ -97,7 +99,7 @@ func (x LockNonRegularObject) Error() string { func (x LockNonRegularObject) Is(target error) bool { switch target.(type) { default: - return false + return errors.Is(Error, target) case LockNonRegularObject, *LockNonRegularObject: return true } @@ -144,7 +146,7 @@ func (x ObjectAccessDenied) Error() string { func (x ObjectAccessDenied) Is(target error) bool { switch target.(type) { default: - return false + return errors.Is(Error, target) case ObjectAccessDenied, *ObjectAccessDenied: return true } @@ -202,7 +204,7 @@ func (x ObjectNotFound) Error() string { func (x ObjectNotFound) Is(target error) bool { switch target.(type) { default: - return false + return errors.Is(Error, target) case ObjectNotFound, *ObjectNotFound: return true } @@ -249,7 +251,7 @@ func (x ObjectAlreadyRemoved) Error() string { func (x ObjectAlreadyRemoved) Is(target error) bool { switch target.(type) { default: - return false + return errors.Is(Error, target) case ObjectAlreadyRemoved, *ObjectAlreadyRemoved: return true } @@ -297,7 +299,7 @@ func (x ObjectOutOfRange) Error() string { func (x ObjectOutOfRange) Is(target error) bool { switch target.(type) { default: - return false + return errors.Is(Error, target) case ObjectOutOfRange, *ObjectOutOfRange: return true } diff --git a/client/status/session.go b/client/status/session.go index 26c649d..a6a04c0 100644 --- a/client/status/session.go +++ b/client/status/session.go @@ -1,6 +1,8 @@ package apistatus import ( + "errors" + "github.com/nspcc-dev/neofs-api-go/v2/session" "github.com/nspcc-dev/neofs-api-go/v2/status" ) @@ -38,7 +40,7 @@ func (x SessionTokenNotFound) Error() string { func (x SessionTokenNotFound) Is(target error) bool { switch target.(type) { default: - return false + return errors.Is(Error, target) case SessionTokenNotFound, *SessionTokenNotFound: return true } @@ -85,7 +87,7 @@ func (x SessionTokenExpired) Error() string { func (x SessionTokenExpired) Is(target error) bool { switch target.(type) { default: - return false + return errors.Is(Error, target) case SessionTokenExpired, *SessionTokenExpired: return true } diff --git a/client/status/status.go b/client/status/status.go index 0917289..a220f2f 100644 --- a/client/status/status.go +++ b/client/status/status.go @@ -1,9 +1,5 @@ package apistatus -import ( - "errors" -) - // Status defines a variety of NeoFS API status returns. // // All statuses are split into two disjoint subsets: successful and failed, and: @@ -26,7 +22,7 @@ type Status any // Note: direct assignment may not be compatibility-safe. func ErrFromStatus(st Status) error { if err, ok := st.(error); ok { - return errors.Join(Error, err) + return err } return nil