From 692790a899d117c20d87493e7f617a9a118850ec Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Tue, 8 Feb 2022 14:14:21 +0300 Subject: [PATCH] [#1115] services/object: reuse errors from core service Signed-off-by: Evgenii Stratonikov --- pkg/services/object/put/v2/streamer.go | 16 +++------------- pkg/services/object/put/validation.go | 12 ++++++------ 2 files changed, 9 insertions(+), 19 deletions(-) diff --git a/pkg/services/object/put/v2/streamer.go b/pkg/services/object/put/v2/streamer.go index a1e1103b9..ec1d263dd 100644 --- a/pkg/services/object/put/v2/streamer.go +++ b/pkg/services/object/put/v2/streamer.go @@ -1,7 +1,6 @@ package putsvc import ( - "errors" "fmt" "github.com/nspcc-dev/neofs-api-go/v2/object" @@ -31,15 +30,6 @@ type sizes struct { writtenPayload uint64 // sum size of already cached chunks } -// TODO: errors are copy-pasted from putsvc package -// consider replacing to core library - -// errors related to invalid payload size -var ( - errExceedingMaxSize = errors.New("payload size is greater than the limit") - errWrongPayloadSize = errors.New("wrong payload size") -) - func (s *streamer) Send(req *object.PutRequest) (err error) { switch v := req.GetBody().GetObjectPart().(type) { case *object.PutObjectPartInit: @@ -64,7 +54,7 @@ func (s *streamer) Send(req *object.PutRequest) (err error) { // check payload size limit overflow if s.payloadSz > maxSz { - return errExceedingMaxSize + return putsvc.ErrExceedingMaxSize } s.init = req @@ -75,7 +65,7 @@ func (s *streamer) Send(req *object.PutRequest) (err error) { // check payload size overflow if s.writtenPayload > s.payloadSz { - return errWrongPayloadSize + return putsvc.ErrWrongPayloadSize } } @@ -115,7 +105,7 @@ func (s *streamer) CloseAndRecv() (*object.PutResponse, error) { if s.saveChunks { // check payload size correctness if s.writtenPayload != s.payloadSz { - return nil, errWrongPayloadSize + return nil, putsvc.ErrWrongPayloadSize } } diff --git a/pkg/services/object/put/validation.go b/pkg/services/object/put/validation.go index 80067ef38..20c3bab56 100644 --- a/pkg/services/object/put/validation.go +++ b/pkg/services/object/put/validation.go @@ -31,8 +31,8 @@ type validatingTarget struct { // errors related to invalid payload size var ( - errExceedingMaxSize = errors.New("payload size is greater than the limit") - errWrongPayloadSize = errors.New("wrong payload size") + ErrExceedingMaxSize = errors.New("payload size is greater than the limit") + ErrWrongPayloadSize = errors.New("wrong payload size") ) func (t *validatingTarget) WriteHeader(obj *object.RawObject) error { @@ -41,12 +41,12 @@ func (t *validatingTarget) WriteHeader(obj *object.RawObject) error { // check chunk size if chunkLn > t.payloadSz { - return errWrongPayloadSize + return ErrWrongPayloadSize } // check payload size limit if t.payloadSz > t.maxPayloadSz { - return errExceedingMaxSize + return ErrExceedingMaxSize } cs := obj.PayloadChecksum() @@ -84,7 +84,7 @@ func (t *validatingTarget) Write(p []byte) (n int, err error) { // check if new chunk will overflow payload size if t.writtenPayload+chunkLn > t.payloadSz { - return 0, errWrongPayloadSize + return 0, ErrWrongPayloadSize } _, err = t.hash.Write(p) @@ -103,7 +103,7 @@ func (t *validatingTarget) Write(p []byte) (n int, err error) { func (t *validatingTarget) Close() (*transformer.AccessIdentifiers, error) { // check payload size correctness if t.payloadSz != t.writtenPayload { - return nil, errWrongPayloadSize + return nil, ErrWrongPayloadSize } if !bytes.Equal(t.hash.Sum(nil), t.checksum) {