Skip to content
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

Merged

Conversation

koseoyoung
Copy link
Contributor

@koseoyoung koseoyoung commented Nov 5, 2019

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.

@koseoyoung koseoyoung requested a review from a team as a code owner November 5, 2019 19:55
@@ -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

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) {

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())

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 {

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()

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
Copy link

codecov bot commented Nov 5, 2019

Codecov Report

Merging #1610 into master will decrease coverage by 0.27%.
The diff coverage is 0%.

Impacted file tree graph

@@            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
Impacted Files Coverage Δ
api/api.go 50.55% <0%> (-1.33%) ⬇️
blockchain/blockchain.go 42.94% <0%> (-1.68%) ⬇️
db/trie/branchnode.go 65.59% <0%> (-1.61%) ⬇️
blockchain/blockdao/indexbuilder.go 28.43% <0%> (-1.17%) ⬇️
blockchain/blockdao/blockdao.go 45.26% <0%> (-1.06%) ⬇️
blockchain/genesis/genesis.go 64.21% <0%> (-0.19%) ⬇️
config/config.go 46.49% <0%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 0fccd01...dabc2da. Read the comment docs.

@@ -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(

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)

@koseoyoung koseoyoung merged commit 05b935b into iotexproject:master Nov 6, 2019
@@ -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(
Copy link
Contributor

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}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants