-
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
put error detail into grpc status #1610
Conversation
@@ -323,7 +324,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 comment
The reason will be displayed to describe this comment to others. Learn more.
declarations should never be cuddled (from wsl
)
@@ -323,7 +324,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 | |||
switch errors.Cause(err) { |
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.
only one cuddle assignment allowed before switch statement (from wsl
)
default: | ||
desc = "unknown" | ||
} | ||
st := status.New(codes.Internal, err.Error()) |
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.
assignments should only be cuddled with other assignments (from wsl
)
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 comment
The reason will be displayed to describe this comment to others. Learn more.
only one cuddle assignment allowed before if statement (from wsl
)
if err != nil { | ||
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 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
)
Codecov Report
@@ Coverage Diff @@
## master #1610 +/- ##
==========================================
- Coverage 54.92% 54.65% -0.28%
==========================================
Files 154 154
Lines 13459 13500 +41
==========================================
- Hits 7393 7378 -15
- Misses 5099 5160 +61
+ Partials 967 962 -5
Continue to review full report at Codecov.
|
@@ -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 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
)
@@ -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 comment
The reason will be displayed to describe this comment to others. Learn more.
please make the error more structured than a string. for example,
{gasPrice: 123, minGasPrice: 321}
works on #1545
To make it easier for front-end to get an error information when user trys to send action, put the error information into grpc status with details.
This error classification doesn't cover every case, but it would be better to know the general error reason.