-
Notifications
You must be signed in to change notification settings - Fork 328
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
put error detail into grpc status #1610
Changes from all commits
53be12c
0097fa8
1a8f3f6
3c5e886
dabc2da
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -212,7 +212,8 @@ func (ap *actPool) Add(act action.SealedEnvelope) error { | |
// Reject action if the gas price is lower than the threshold | ||
if act.GasPrice().Cmp(ap.cfg.MinGasPrice()) < 0 { | ||
actpoolMtc.WithLabelValues("gasPriceLower").Inc() | ||
return errors.Errorf( | ||
return errors.Wrapf( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please make the error more structured than a string. for example,
|
||
action.ErrGasPrice, | ||
"reject the action %x whose gas price %s is lower than minimal gas price threshold", | ||
hash, | ||
act.GasPrice(), | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,6 +25,7 @@ import ( | |
"github.com/iotexproject/iotex-proto/golang/iotextypes" | ||
"github.com/pkg/errors" | ||
"go.uber.org/zap" | ||
"google.golang.org/genproto/googleapis/rpc/errdetails" | ||
"google.golang.org/grpc" | ||
"google.golang.org/grpc/codes" | ||
"google.golang.org/grpc/reflection" | ||
|
@@ -327,7 +328,35 @@ func (api *Server) SendAction(ctx context.Context, in *iotexapi.SendActionReques | |
// Add to local actpool | ||
if err = api.ap.Add(selp); err != nil { | ||
log.L().Debug(err.Error()) | ||
return nil, status.Error(codes.Internal, err.Error()) | ||
var desc string | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. declarations should never be cuddled (from |
||
switch errors.Cause(err) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. only one cuddle assignment allowed before switch statement (from |
||
case action.ErrBalance: | ||
desc = "Invalid balance" | ||
case action.ErrInsufficientBalanceForGas: | ||
desc = "Insufficient balance for gas" | ||
case action.ErrNonce: | ||
desc = "Invalid nonce" | ||
case action.ErrAddress: | ||
desc = "Blacklisted address" | ||
case action.ErrActPool: | ||
desc = "Invalid actpool" | ||
case action.ErrGasPrice: | ||
desc = "Invalid gas price" | ||
default: | ||
desc = "Unknown" | ||
} | ||
st := status.New(codes.Internal, err.Error()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. assignments should only be cuddled with other assignments (from |
||
v := &errdetails.BadRequest_FieldViolation{ | ||
Field: "Action rejected", | ||
Description: desc, | ||
} | ||
br := &errdetails.BadRequest{} | ||
br.FieldViolations = append(br.FieldViolations, v) | ||
st, err := st.WithDetails(br) | ||
if err != nil { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. only one cuddle assignment allowed before if statement (from |
||
log.S().Panicf("Unexpected error attaching metadata: %v", err) | ||
} | ||
return nil, st.Err() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. return statements should not be cuddled if block has more than two lines (from |
||
} | ||
// If there is no error putting into local actpool, | ||
// Broadcast it to the network | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return statements should not be cuddled if block has more than two lines (from
wsl
)