From df6538c68ca3c72d94688fe818d427ee771253c9 Mon Sep 17 00:00:00 2001 From: Pavel Karpy Date: Wed, 29 Jun 2022 20:24:56 +0300 Subject: [PATCH] [#282] apistatus: Support `OUT_OF_RANGE` error Signed-off-by: Pavel Karpy --- client/object_get.go | 1 + client/object_hash.go | 1 + client/status/object.go | 31 +++++++++++++++++++++++++++++++ client/status/v2.go | 2 ++ client/status/v2_test.go | 12 ++++++++++++ 5 files changed, 47 insertions(+) diff --git a/client/object_get.go b/client/object_get.go index 7ea20e72..29844bb5 100644 --- a/client/object_get.go +++ b/client/object_get.go @@ -684,6 +684,7 @@ func (x *ObjectRangeReader) close(ignoreEOF bool) (*ResObjectRange, error) { // - *apistatus.ObjectNotFound; // - *apistatus.ObjectAccessDenied; // - *apistatus.ObjectAlreadyRemoved; +// - *apistatus.ObjectOutOfRange; // - *apistatus.SessionTokenExpired. func (x *ObjectRangeReader) Close() (*ResObjectRange, error) { return x.close(true) diff --git a/client/object_hash.go b/client/object_hash.go index 16b8b933..48bfcbc7 100644 --- a/client/object_hash.go +++ b/client/object_hash.go @@ -152,6 +152,7 @@ func (x ResObjectHash) Checksums() [][]byte { // - *apistatus.ContainerNotFound; // - *apistatus.ObjectNotFound; // - *apistatus.ObjectAccessDenied; +// - *apistatus.ObjectOutOfRange; // - *apistatus.SessionTokenExpired. func (c *Client) ObjectHash(ctx context.Context, prm PrmObjectHash) (*ResObjectHash, error) { switch { diff --git a/client/status/object.go b/client/status/object.go index cf6674a6..a7c0b910 100644 --- a/client/status/object.go +++ b/client/status/object.go @@ -165,3 +165,34 @@ func (x ObjectAlreadyRemoved) ToStatusV2() *status.Status { x.v2.SetMessage("object already removed") return &x.v2 } + +// ObjectOutOfRange describes status of the failure because of the incorrect +// provided object ranges. +// Instances provide Status and StatusV2 interfaces. +type ObjectOutOfRange struct { + v2 status.Status +} + +func (x ObjectOutOfRange) Error() string { + return errMessageStatusV2( + globalizeCodeV2(object.StatusOutOfRange, object.GlobalizeFail), + x.v2.Message(), + ) +} + +// implements local interface defined in FromStatusV2 func. +func (x *ObjectOutOfRange) fromStatusV2(st *status.Status) { + x.v2 = *st +} + +// ToStatusV2 implements StatusV2 interface method. +// If the value was returned by FromStatusV2, returns the source message. +// Otherwise, returns message with +// * code: OUT_OF_RANGE; +// * string message: "out of range"; +// * details: empty. +func (x ObjectOutOfRange) ToStatusV2() *status.Status { + x.v2.SetCode(globalizeCodeV2(object.StatusOutOfRange, object.GlobalizeFail)) + x.v2.SetMessage("out of range") + return &x.v2 +} diff --git a/client/status/v2.go b/client/status/v2.go index 627014cb..7fcead50 100644 --- a/client/status/v2.go +++ b/client/status/v2.go @@ -71,6 +71,8 @@ func FromStatusV2(st *status.Status) Status { decoder = new(ObjectNotFound) case object.StatusAlreadyRemoved: decoder = new(ObjectAlreadyRemoved) + case object.StatusOutOfRange: + decoder = new(ObjectOutOfRange) } case container.LocalizeFailStatus(&code): //nolint:exhaustive diff --git a/client/status/v2_test.go b/client/status/v2_test.go index de27095d..86733011 100644 --- a/client/status/v2_test.go +++ b/client/status/v2_test.go @@ -95,6 +95,12 @@ func TestToStatusV2(t *testing.T) { }), codeV2: 2052, }, + { + status: (statusConstructor)(func() apistatus.Status { + return new(apistatus.ObjectOutOfRange) + }), + codeV2: 2053, + }, { status: (statusConstructor)(func() apistatus.Status { return new(apistatus.ContainerNotFound) @@ -230,6 +236,12 @@ func TestFromStatusV2(t *testing.T) { }), codeV2: 2052, }, + { + status: statusConstructor(func() apistatus.Status { + return new(apistatus.ObjectOutOfRange) + }), + codeV2: 2053, + }, { status: (statusConstructor)(func() apistatus.Status { return new(apistatus.ContainerNotFound)