-
Notifications
You must be signed in to change notification settings - Fork 103
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
fix(x/data): return grpc error codes for queries #1579
Conversation
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## main #1579 +/- ##
=======================================
Coverage 78.68% 78.68%
=======================================
Files 251 251
Lines 18849 18849
=======================================
Hits 14832 14832
Misses 3153 3153
Partials 864 864
|
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.
I think the preferred path forward with the new cosmossdk.io/errors
package is to have consumer chains define their own common errors.
It might be worthwhile to open a new package errors
and define some common errors, registered with the package above. we can avoid writing the status.Error(codes.InvalidArgument, "blah blah")
over and over again, and instead just do ourErrorsPackage.InvalidArgument.Wrap("blah blah")
.
wdyt?
Created |
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.
great work! thanks for the changes 🙏🏻
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.
I think the preferred path forward with the new cosmossdk.io/errors package is to have consumer chains define their own common errors.
The goal of this issue was to use the standard gRPC code rather than defining custom errors with different codes. Developers wanting to use their own custom error messages will most likely be writing custom error messages based on the standard gRPC error codes (which is the case for the developers that originally reported this message).
Apologies for the delay on reviewing and the confusion. Maybe we can further discuss on our call tomorrow.
errors/grpc.go
Outdated
var ( | ||
ErrCancelled = errors.RegisterWithGRPCCode(moduleName, 1, codes.Canceled, "cancelled") | ||
ErrUnkown = errors.RegisterWithGRPCCode(moduleName, 2, codes.Unknown, "unknown") | ||
ErrInvalidArgument = errors.RegisterWithGRPCCode(moduleName, 3, codes.InvalidArgument, "invalid argument") | ||
ErrNotFound = errors.RegisterWithGRPCCode(moduleName, 4, codes.NotFound, "not found") | ||
ErrAlreadyExists = errors.RegisterWithGRPCCode(moduleName, 5, codes.AlreadyExists, "already exists") | ||
ErrPermissionDenied = errors.RegisterWithGRPCCode(moduleName, 6, codes.PermissionDenied, "permission denied") | ||
ErrInternal = errors.RegisterWithGRPCCode(moduleName, 7, codes.Internal, "internal") | ||
ErrUnavailable = errors.RegisterWithGRPCCode(moduleName, 8, codes.Unavailable, "unavailable") | ||
ErrUnauthenticated = errors.RegisterWithGRPCCode(moduleName, 9, codes.Unauthenticated, "unauthenticated") | ||
ErrUnimplemented = errors.RegisterWithGRPCCode(moduleName, 10, codes.Unimplemented, "unimplemented") | ||
) |
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.
Where are these error codes coming from? It looks like the expected not found error should be status code 5 rather than 4 according to this: https://grpc.github.io/grpc/core/md_doc_statuscodes.html. This is also the expected error code that was reported by the user (in the issue summary).
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.
Also see https://pkg.go.dev/google.golang.org/grpc/codes. I think we should be using these error codes rather than defining our own... Looks like there is some confusion around the issue per @technicallyty's above request.
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.
Where are these error codes coming from? It looks like the expected not found error should be status code 5 rather than 4 according to this: https://grpc.github.io/grpc/core/md_doc_statuscodes.html. This is also the expected error code that was reported by the user (in the issue summary).
These error codes are just to make sure we don't have duplicate errors in each codespace. Nothing to do with gRPC status codes. For gRPC errors, we are using the third argument (codes.Canceled
).
The current PR fixes the issue related to gRPC status codes. We were getting response on
In this PR
|
I'm still a bit confused why we are registering different error codes. I realize the correct error code is returned in the following example but we are displaying the custom registered error code in the message (a different error code):
|
It would make more sense to me if we were using the same error codes but I'll try to do some digging on best practices. |
Updated error codes to match gRPC 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.
LGTM
Description
Ref: #1577
Author Checklist
All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.
I have...
!
to the type prefix if API or client breaking changeCHANGELOG.md
Reviewers Checklist
All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.
I have...
!
in the type prefix if API or client breaking change