-
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
Add guidelines on using sdk errors and module errors #1147
Comments
This should likely get upstreamed to the SDK |
@ryanchristo would you suggest modules don't use ErrInvalidRequest and define custom errors? Or would it make sense if the SDK has a core set or general purpose errors like invalid request, unauthorized that modules are encouraged to use? |
I'm not entirely sure at the moment. I'll need to spend more time reviewing how we are currently using errors and how other sdk projects are using errors and maybe best practices for errors in general. We are sticking with using I think general purpose errors defined in the sdk are still nice but more specific module errors could be better utilized. One case in particular that I have found in our case is |
There are already guidelines in the sdk and it looks like we could do a better job of following them. https://docs.cosmos.network/main/building-modules/errors.html Specifically for the case I mentioned above, the sdk actually suggests something like:
|
Note to include use of |
Ref: #1317 (review) Functions that can be used outside the context of a request should not use For example, we have a utility function that validates the format of a batch denom. The utility function that validates the string would return a parse error and the basic message validation that calls the utility function would return an invalid request error that wraps the parse error:
And when being used within basic message validation:
|
Note, |
Note, the new orm errors provide additional information about the field name(s) causing the error. In #1383, a quick fix was made that does not make use of the new orm errors but we take these into consideration when writing guidelines, i.e. whether we want to return the errors as is or continue customizing the error messages. For example:
|
Summary
When to use what sdk errors is not clear and often we default to
ErrInvalidRequest
. We should have clear guidelines on using sdk errors and module specific errors. This could be included in the contributing guidelines (#1003) or in a separate document.Problem Definition
Error messages are inconsistent and guidelines on when to use what errors would help with writing better error messages and as a result improve the user experience.
Proposal
Write guidelines on when to use what errors and then open a followup issue to update codebase according to those guidelines.
For Admin Use
The text was updated successfully, but these errors were encountered: