Skip to content

Commit

Permalink
refactor: api error functions naming convention (Layr-Labs#831)
Browse files Browse the repository at this point in the history
  • Loading branch information
samlaf authored and ian-shim committed Oct 25, 2024
1 parent 2631695 commit 27f55f0
Show file tree
Hide file tree
Showing 12 changed files with 120 additions and 96 deletions.
34 changes: 20 additions & 14 deletions api/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,32 +8,38 @@ import (
// The canonical errors from the EigenDA gRPC API endpoints.
//
// Notes:
// - Start the error space small (but sufficient), and expand when there is an important
// failure case to separate out.
// - Avoid simply wrapping system-internal errors without checking if they are appropriate
// in user-facing errors defined here. Consider map and convert system-internal errors
// before return to users from APIs.
// - We start with a small (but sufficient) subset of google's error code convention,
// and expand when there is an important failure case to separate out. See:
// https://cloud.google.com/apis/design/errors#handling_errors
// - Make sure that internally propagated errors are eventually wrapped in one of the
// user-facing errors defined here, since grpc otherwise returns an UNKNOWN error code,
// which is harder to debug and understand for users.

func NewGRPCError(code codes.Code, msg string) error {
func newErrorGRPC(code codes.Code, msg string) error {
return status.Error(code, msg)
}

// HTTP Mapping: 400 Bad Request
func NewInvalidArgError(msg string) error {
return NewGRPCError(codes.InvalidArgument, msg)
func NewErrorInvalidArg(msg string) error {
return newErrorGRPC(codes.InvalidArgument, msg)
}

// HTTP Mapping: 404 Not Found
func NewNotFoundError(msg string) error {
return NewGRPCError(codes.NotFound, msg)
func NewErrorNotFound(msg string) error {
return newErrorGRPC(codes.NotFound, msg)
}

// HTTP Mapping: 429 Too Many Requests
func NewResourceExhaustedError(msg string) error {
return NewGRPCError(codes.ResourceExhausted, msg)
func NewErrorResourceExhausted(msg string) error {
return newErrorGRPC(codes.ResourceExhausted, msg)
}

// HTTP Mapping: 500 Internal Server Error
func NewInternalError(msg string) error {
return NewGRPCError(codes.Internal, msg)
func NewErrorInternal(msg string) error {
return newErrorGRPC(codes.Internal, msg)
}

// HTTP Mapping: 501 Not Implemented
func NewErrorUnimplemented() error {
return newErrorGRPC(codes.Unimplemented, "not implemented")
}
24 changes: 20 additions & 4 deletions api/grpc/disperser/disperser_grpc.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 8 additions & 2 deletions api/proto/disperser/disperser.proto
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,16 @@ option go_package = "github.com/Layr-Labs/eigenda/api/grpc/disperser";

// Disperser defines the public APIs for dispersing blobs.
service Disperser {
// This API accepts blob to disperse from clients.
// DisperseBlob accepts a single blob to be dispersed.
// This executes the dispersal async, i.e. it returns once the request
// is accepted. The client could use GetBlobStatus() API to poll the the
// is accepted. The client should use GetBlobStatus() API to poll the
// processing status of the blob.
//
// If DisperseBlob returns the following error codes:
// INVALID_ARGUMENT (400): request is invalid for a reason specified in the error msg.
// RESOURCE_EXHAUSTED (429): request is rate limited for the quorum specified in the error msg.
// user should retry after the specified duration.
// INTERNAL (500): serious error, user should NOT retry.
rpc DisperseBlob(DisperseBlobRequest) returns (DisperseBlobReply) {}


Expand Down
8 changes: 3 additions & 5 deletions common/aws/dynamodb/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func (c *Client) DeleteTable(ctx context.Context, tableName string) error {
_, err := c.dynamoClient.DeleteTable(ctx, &dynamodb.DeleteTableInput{
TableName: aws.String(tableName)})
if err != nil {
return err
return fmt.Errorf("failed to delete table %s: %w", tableName, err)
}
return nil
}
Expand All @@ -103,9 +103,8 @@ func (c *Client) PutItem(ctx context.Context, tableName string, item Item) (err
TableName: aws.String(tableName), Item: item,
})
if err != nil {
return err
return fmt.Errorf("failed to put item in table %s: %w", tableName, err)
}

return nil
}

Expand All @@ -115,9 +114,8 @@ func (c *Client) PutItemWithCondition(ctx context.Context, tableName string, ite
ConditionExpression: aws.String(condition),
})
if err != nil {
return err
return fmt.Errorf("failed to put item in table %s: %w", tableName, err)
}

return nil
}

Expand Down
4 changes: 2 additions & 2 deletions common/aws/s3/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ func (s *client) DownloadObject(ctx context.Context, bucket string, key string)
func (s *client) UploadObject(ctx context.Context, bucket string, key string, data []byte) error {
var partMiBs int64 = 10
uploader := manager.NewUploader(s.s3Client, func(u *manager.Uploader) {
u.PartSize = partMiBs * 1024 * 1024 // 10MB per part
u.Concurrency = 3 //The number of goroutines to spin up in parallel per call to Upload when sending parts
u.PartSize = partMiBs * 1024 * 1024 // 10MiB per part
u.Concurrency = 3 //The number of goroutines to spin up in parallel per call to upload when sending parts
})

_, err := uploader.Upload(ctx, &s3.PutObjectInput{
Expand Down
Loading

0 comments on commit 27f55f0

Please sign in to comment.