From 5ad013c10b0a635735070fa0447884726df6a506 Mon Sep 17 00:00:00 2001 From: Leonard Lyubich Date: Thu, 5 Nov 2020 19:56:25 +0300 Subject: [PATCH] [#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 --- pkg/services/object/search/relation.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/pkg/services/object/search/relation.go b/pkg/services/object/search/relation.go index 09cb2e740..af8dbd06c 100644 --- a/pkg/services/object/search/relation.go +++ b/pkg/services/object/search/relation.go @@ -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) }