From a91a7ae77f5f0fa05fc7c06044bb8b104038d7b8 Mon Sep 17 00:00:00 2001 From: Viacheslav Gonkivskyi Date: Fri, 1 Mar 2024 11:43:19 +0200 Subject: [PATCH] return empty slice and an error if blobs were not found --- blob/service.go | 15 ++++++++++----- blob/service_test.go | 9 ++++----- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/blob/service.go b/blob/service.go index fc1d630e62..d72b34f1bb 100644 --- a/blob/service.go +++ b/blob/service.go @@ -136,6 +136,7 @@ func (s *Service) GetProof( // GetAll returns all blobs under the given namespaces at the given height. // GetAll can return blobs and an error in case if some requests failed. +// GetAll can return both empty values in case if blobs were not found for the requested namespaces. func (s *Service) GetAll(ctx context.Context, height uint64, namespaces []share.Namespace) ([]*Blob, error) { header, err := s.headerGetter(ctx, height) if err != nil { @@ -158,7 +159,15 @@ func (s *Service) GetAll(ctx context.Context, height uint64, namespaces []share. defer wg.Done() blobs, err := s.getBlobs(ctx, namespace, header) if err != nil { - resultErr[i] = fmt.Errorf("getting blobs for namespace(%s): %w", namespace.String(), err) + resErr := errors.New( + fmt.Sprintf("getting blobs for namespace(%s): %v", namespace.String(), err), + ) + if errors.Is(err, ErrBlobNotFound) { + log.Debug(resErr) + return + } + + resultErr[i] = resErr return } @@ -174,10 +183,6 @@ func (s *Service) GetAll(ctx context.Context, height uint64, namespaces []share. blobs = append(blobs, resBlobs...) } } - - if len(blobs) == 0 { - resultErr = append(resultErr, ErrBlobNotFound) - } return blobs, errors.Join(resultErr...) } diff --git a/blob/service_test.go b/blob/service_test.go index 3e22f887af..7870c1788e 100644 --- a/blob/service_test.go +++ b/blob/service_test.go @@ -255,16 +255,15 @@ func TestBlobService_Get(t *testing.T) { { name: "get all not found", doFn: func() (interface{}, error) { - namespace := share.Namespace(tmrand.Bytes(share.NamespaceSize)) - return service.GetAll(ctx, 1, []share.Namespace{namespace}) + nid, err := share.NewBlobNamespaceV0(tmrand.Bytes(7)) + require.NoError(t, err) + return service.GetAll(ctx, 1, []share.Namespace{nid}) }, expectedResult: func(i interface{}, err error) { blobs, ok := i.([]*Blob) require.True(t, ok) assert.Empty(t, blobs) - require.Error(t, err) - require.ErrorIs(t, err, ErrBlobNotFound) - + require.NoError(t, err) }, }, {