forked from TrueCloudLab/frostfs-api-go
[#199] sdk: Refactor string parse errors
Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
parent
fe336fd5ba
commit
79f72e10c9
9 changed files with 15 additions and 35 deletions
|
@ -5,7 +5,6 @@ import (
|
|||
"crypto/sha256"
|
||||
|
||||
"github.com/mr-tron/base58"
|
||||
"github.com/nspcc-dev/neofs-api-go/internal"
|
||||
"github.com/nspcc-dev/neofs-api-go/v2/refs"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
@ -13,9 +12,7 @@ import (
|
|||
// ID represents v2-compatible container identifier.
|
||||
type ID refs.ContainerID
|
||||
|
||||
// ErrBadID should be returned when bytes slice isn't Container.ID size (sha256.Size).
|
||||
// Notice: if byte slice changed, please, replace error message.
|
||||
const ErrBadID = internal.Error("object.ID should be 32 bytes length")
|
||||
var errInvalidIDString = errors.New("incorrect format of the string container ID")
|
||||
|
||||
// NewIDFromV2 wraps v2 ContainerID message to ID.
|
||||
func NewIDFromV2(idV2 *refs.ContainerID) *ID {
|
||||
|
@ -53,7 +50,7 @@ func (id *ID) Parse(s string) error {
|
|||
if err != nil {
|
||||
return errors.Wrap(err, "could not parse container.ID from string")
|
||||
} else if len(data) != sha256.Size {
|
||||
return ErrBadID
|
||||
return errInvalidIDString
|
||||
}
|
||||
|
||||
(*refs.ContainerID)(id).SetValue(data)
|
||||
|
|
|
@ -70,7 +70,7 @@ func TestID_Parse(t *testing.T) {
|
|||
str := base58.Encode(cs)
|
||||
cid := NewID()
|
||||
|
||||
require.EqualError(t, cid.Parse(str), ErrBadID.Error())
|
||||
require.Error(t, cid.Parse(str))
|
||||
})
|
||||
}
|
||||
})
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue