From e11b1728beb9921050cc6544b0c12f62f7ba058f Mon Sep 17 00:00:00 2001 From: Alex Vanin Date: Wed, 2 Dec 2020 14:25:25 +0300 Subject: [PATCH] [#218] pkg/object: Define custom error for SplitInfo Signed-off-by: Alex Vanin --- pkg/client/object.go | 5 +++-- pkg/object/error.go | 19 +++++++++++++++++++ pkg/object/error_test.go | 32 ++++++++++++++++++++++++++++++++ 3 files changed, 54 insertions(+), 2 deletions(-) create mode 100644 pkg/object/error.go create mode 100644 pkg/object/error_test.go diff --git a/pkg/client/object.go b/pkg/client/object.go index df60f6f..21d0d50 100644 --- a/pkg/client/object.go +++ b/pkg/client/object.go @@ -445,8 +445,9 @@ func (c *Client) getObjectV2(ctx context.Context, p *GetObjectParams, opts ...Ca } else { payload = append(payload, v.GetChunk()...) } - case *v2object.SplitInfo: // what else can we do here? - return nil, errors.New("object not found, split info has been provided") + case *v2object.SplitInfo: + si := object.NewSplitInfoFromV2(v) + return nil, object.NewSplitInfoError(si) default: panic(fmt.Sprintf("unexpected Get object part type %T", v)) } diff --git a/pkg/object/error.go b/pkg/object/error.go new file mode 100644 index 0000000..98bd3f2 --- /dev/null +++ b/pkg/object/error.go @@ -0,0 +1,19 @@ +package object + +type SplitInfoError struct { + si *SplitInfo +} + +const splitInfoErrorMsg = "object not found, split info has been provided" + +func (s SplitInfoError) Error() string { + return splitInfoErrorMsg +} + +func (s SplitInfoError) SplitInfo() *SplitInfo { + return s.si +} + +func NewSplitInfoError(v *SplitInfo) SplitInfoError { + return SplitInfoError{si: v} +} diff --git a/pkg/object/error_test.go b/pkg/object/error_test.go new file mode 100644 index 0000000..ce3bcd2 --- /dev/null +++ b/pkg/object/error_test.go @@ -0,0 +1,32 @@ +package object_test + +import ( + "errors" + "testing" + + "github.com/nspcc-dev/neofs-api-go/pkg/object" + "github.com/stretchr/testify/require" +) + +func TestNewSplitInfoError(t *testing.T) { + var ( + si = generateSplitInfo() + + err error = object.NewSplitInfoError(si) + ) + + require.True(t, errors.As(err, new(object.SplitInfoError))) + + siErr, ok := err.(object.SplitInfoError) + require.True(t, ok) + require.Equal(t, si, siErr.SplitInfo()) +} + +func generateSplitInfo() *object.SplitInfo { + si := object.NewSplitInfo() + si.SetSplitID(object.NewSplitID()) + si.SetLastPart(generateID()) + si.SetLink(generateID()) + + return si +}