Skip to content

Commit 42d8826

Browse files
committed
chore: avoid grpc error in storage layer
Signed-off-by: bestmike007 <i@bestmike007.com>
1 parent e6b7b24 commit 42d8826

File tree

3 files changed

+4
-9
lines changed

3 files changed

+4
-9
lines changed

internal/server/handler.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -715,7 +715,8 @@ func (s *Server) newBlockFile(block *api.BlockMetadata) (*api.BlockFile, error)
715715
compression := storage_utils.GetCompressionType(key)
716716
fileUrl, err := s.blobStorage.PreSign(context.Background(), key)
717717
if err != nil {
718-
return nil, err
718+
s.logger.Error("block file s3 presign error", zap.String("key", key), zap.Error(err))
719+
return nil, status.Errorf(codes.Internal, "internal block file url generation error: %+v", err)
719720
}
720721

721722
return &api.BlockFile{

internal/storage/blobstorage/gcs/blob_storage.go

+1-4
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,10 @@ import (
99
"time"
1010

1111
"cloud.google.com/go/storage"
12-
"github.com/gogo/status"
1312
"github.com/uber-go/tally/v4"
1413
"go.uber.org/fx"
1514
"go.uber.org/zap"
1615
"golang.org/x/xerrors"
17-
"google.golang.org/grpc/codes"
1816
"google.golang.org/protobuf/proto"
1917

2018
"github.com/coinbase/chainstorage/internal/config"
@@ -239,8 +237,7 @@ func (s *blobStorageImpl) PreSign(ctx context.Context, objectKey string) (string
239237
Expires: time.Now().Add(s.presignedUrlExpiration),
240238
})
241239
if err != nil {
242-
s.logger.Error("block file gcs presign error", zap.String("key", objectKey), zap.Error(err))
243-
return "", status.Errorf(codes.Internal, "internal block file url generation error: %+v", err)
240+
return "", xerrors.Errorf("failed to generate presigned url: %w", err)
244241
}
245242
return fileUrl, nil
246243
}

internal/storage/blobstorage/s3/blob_storage.go

+1-4
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,10 @@ import (
1313
"github.com/aws/aws-sdk-go/aws/request"
1414
awss3 "github.com/aws/aws-sdk-go/service/s3"
1515
"github.com/aws/aws-sdk-go/service/s3/s3manager"
16-
"github.com/gogo/status"
1716
"github.com/uber-go/tally/v4"
1817
"go.uber.org/fx"
1918
"go.uber.org/zap"
2019
"golang.org/x/xerrors"
21-
"google.golang.org/grpc/codes"
2220
"google.golang.org/protobuf/proto"
2321

2422
"github.com/coinbase/chainstorage/internal/config"
@@ -228,8 +226,7 @@ func (s *blobStorageImpl) PreSign(ctx context.Context, objectKey string) (string
228226
})
229227
fileUrl, err := getObjectReq.Presign(s.config.AWS.PresignedUrlExpiration)
230228
if err != nil {
231-
s.logger.Error("block file s3 presign error", zap.Reflect("key", objectKey), zap.Error(err))
232-
return "", status.Errorf(codes.Internal, "internal block file url generation error: %+v", err)
229+
return "", xerrors.Errorf("failed to generate presigned url: %w", err)
233230
}
234231
return fileUrl, nil
235232
}

0 commit comments

Comments
 (0)