-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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
Refactor Error Handling - II (Modules) #5429
Refactor Error Handling - II (Modules) #5429
Conversation
This pull request fixes 7 alerts when merging 2bd6fb9 into 6bee805 - view on LGTM.com fixed alerts:
|
This pull request fixes 7 alerts when merging 0ce6f62 into ff229ac - view on LGTM.com fixed alerts:
|
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.
ACK. Minor nits that can be addressed in other PRs.
I also noticed that the error registration has a big gap between the error codes. For eg: x/distribution module errors that reserve codes 300-399
, but only uses 300-311. Then comes x/evidence
(sorted alphabetically) that reserves codes 400-499
(again, it uses only 400-403). Imo we shouldn't assign codes to the sdkerrors.Register
function as it should somehow maintain a variable of the latest registered error code.
In the same context, what do we do with the error codes if we introduce another module in-between x/distribution
and x/evidence
? Should we assign it another range (say 800-899)? Or should we push the error codes so that it's assigned 400-499?
@@ -44,7 +40,7 @@ type ( | |||
GetDescription() string | |||
ProposalRoute() string | |||
ProposalType() string | |||
ValidateBasic() sdk.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.
do we need to update legacy types too?
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 doubt it since the build passes?
@@ -67,55 +67,55 @@ func (c Commission) String() string { | |||
|
|||
// Validate performs basic sanity validation checks of initial commission | |||
// parameters. If validation fails, an SDK error is returned. | |||
func (c CommissionRates) Validate() sdk.Error { | |||
func (c CommissionRates) Validate() 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.
nit, this should be ValidateBasic
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.
Agree -- outside the scope of the PR though.
@@ -331,21 +332,21 @@ func (d Description) UpdateDescription(d2 Description) (Description, sdk.Error) | |||
} | |||
|
|||
// EnsureLength ensures the length of a validator's description. | |||
func (d Description) EnsureLength() (Description, sdk.Error) { | |||
func (d Description) EnsureLength() (Description, 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.
ditto ValidateBasic
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.
Agree -- outside the scope of the PR though.
This pull request fixes 7 alerts when merging ba73422 into ff229ac - view on LGTM.com fixed alerts:
|
There are no gaps. Each module "reserves" a range of error codes, but by no means does it have to utilize every single code. e.g.
I'd counter your suggestion by stating that abstracting error codes in the registration process defeats the entire purpose of errors codes (assuming this is what you're suggesting). The entire point is that if I see an error with code C and codespace S, I know exactly where to look -- module S and error with code C. If the Keep in mind, this PR does not change existing behavior -- it just makes it more strict.
Ok, the distribution of error code ranges was not meant to be alphabetic -- I just did it that way to keep mental tabs. When you introduce a new module (regardless of where it fits alphabetically), you simply assign it an error code range that isn't used. It can be 800-899, 1000-1099, etc. However, I do agree that In the future, when a boundless set of modules exist, we'll need to introduce the ability for these ranges to be modified, because we cannot expect developers to know ever module's range out there. e.g. var StartingErrCode uint32 = 400
var (
ErrEmptyValidatorAddr = sdkerrors.Register(ModuleName, StartingErrCode, "empty validator address")
ErrBadValidatorAddr = sdkerrors.Register(ModuleName, StartingErrCode+1, "validator address is invalid")
// ...
) If I have my own module and it ends up conflicting with this, I simply update |
Is that enforced? For example, an app that imports x/evidence can actually use
++ |
Actually, my entire argument is moot. Codespaces only have to be unique per codespace/code, this means all modules can use any codes they like -- they just have to be unique per "codespace" (i.e. module). I'll go ahead and update all codes to be 0+ |
This pull request fixes 7 alerts when merging de33669 into ff229ac - view on LGTM.com fixed alerts:
|
Part II PR of #5421 where all modules and tests are updated.
Not sure how to best recommend review on this one as it's...pretty large. Simulation and unit tests are passing.
For contributor use:
docs/
) or specification (x/<module>/spec/
)godoc
comments.Unreleased
section inCHANGELOG.md
Files changed
in the Github PR explorerFor admin use:
WIP
,R4R
,docs
, etc)