[#2095] cli: Do not panic on object range

Also, includes range parsing error messages enhancement.

Signed-off-by: Pavel Karpy <carpawell@nspcc.ru>
This commit is contained in:
Pavel Karpy 2022-11-24 16:25:33 +03:00 committed by Anton Nikiforov
parent 0b78af467e
commit d6196c3971

View file

@ -161,12 +161,21 @@ func getRangeList(cmd *cobra.Command) ([]*object.Range, error) {
offset, err := strconv.ParseUint(r[0], 10, 64)
if err != nil {
return nil, fmt.Errorf("invalid range specifier: %s", vs[i])
return nil, fmt.Errorf("invalid '%s' range offset specifier: %w", vs[i], err)
}
length, err := strconv.ParseUint(r[1], 10, 64)
if err != nil {
return nil, fmt.Errorf("invalid range specifier: %s", vs[i])
return nil, fmt.Errorf("invalid '%s' range length specifier: %w", vs[i], err)
}
if length == 0 {
return nil, fmt.Errorf("invalid '%s' range: zero length", vs[i])
}
if offset+length <= offset {
return nil, fmt.Errorf("invalid '%s' range: uint64 overflow", vs[i])
}
rs[i] = object.NewRange()
rs[i].SetOffset(offset)
rs[i].SetLength(length)