Skip to content

Commit

Permalink
return empty slice and an error if blobs were not found
Browse files Browse the repository at this point in the history
  • Loading branch information
vgonkivs committed Mar 1, 2024
1 parent d17722d commit 8e85dd7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
13 changes: 8 additions & 5 deletions blob/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -158,7 +159,13 @@ 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 := fmt.Errorf("getting blobs for namespace(%s): %w", namespace.String(), err)
if errors.Is(err, ErrBlobNotFound) {
log.Debug(resErr)
return
}

resultErr[i] = resErr
return
}

Expand All @@ -174,10 +181,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...)
}

Expand Down
9 changes: 4 additions & 5 deletions blob/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
},
},
{
Expand Down

0 comments on commit 8e85dd7

Please sign in to comment.