[#1115] services/object: reuse errors from core service

Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
This commit is contained in:
Evgenii Stratonikov 2022-02-08 14:14:21 +03:00 committed by Alex Vanin
parent 4caa330ddc
commit 692790a899
2 changed files with 9 additions and 19 deletions

View file

@ -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
}
}

View file

@ -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) {