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 a91a7ae
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
15 changes: 10 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,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(

Check warning on line 162 in blob/service.go

View workflow job for this annotation

GitHub Actions / go-ci / Lint

errorf: should replace errors.New(fmt.Sprintf(...)) with fmt.Errorf(...) (revive)
fmt.Sprintf("getting blobs for namespace(%s): %v", namespace.String(), err),
)
if errors.Is(err, ErrBlobNotFound) {
log.Debug(resErr)
return
}

resultErr[i] = resErr
return
}

Expand All @@ -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...)
}

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 a91a7ae

Please sign in to comment.