[#149] object/search: Return fixed error if relation not found

Define ErrRelationNotFound error in searchsvc package. Return
ErrRelationNotFound from RelationSearcher.SearchRelation method if search
result is empty.

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
Leonard Lyubich 2020-11-05 19:56:25 +03:00 committed by Alex Vanin
parent 2913aa0fd1
commit 5ad013c10b

View file

@ -17,6 +17,8 @@ type RelationSearcher struct {
queryGenerator func(*object.Address) query.Query
}
var ErrRelationNotFound = errors.New("relation not found")
func (s *RelationSearcher) SearchRelation(ctx context.Context, addr *object.Address, prm *util.CommonPrm) (*object.ID, error) {
streamer, err := s.svc.Search(ctx, new(Prm).
WithContainerID(addr.GetContainerID()).WithCommonPrm(prm).
@ -30,6 +32,10 @@ func (s *RelationSearcher) SearchRelation(ctx context.Context, addr *object.Addr
if err != nil {
return nil, errors.Wrapf(err, "(%T) could not read full search stream", s)
} else if ln := len(res); ln != 1 {
if ln == 0 {
return nil, ErrRelationNotFound
}
return nil, errors.Errorf("(%T) unexpected amount of found objects %d", s, ln)
}