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

Refactor Error Handling - II (Modules) #5429

Merged

Conversation

alexanderbez
Copy link
Contributor

@alexanderbez alexanderbez commented Dec 19, 2019

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:

  • Targeted PR against correct branch (see CONTRIBUTING.md)
  • Linked to Github issue with discussion and accepted design OR link to spec that describes this work.
  • Code follows the module structure standards.
  • Wrote unit and integration tests
  • Updated relevant documentation (docs/) or specification (x/<module>/spec/)
  • Added relevant godoc comments.
  • Added a relevant changelog entry to the Unreleased section in CHANGELOG.md
  • Re-reviewed Files changed in the Github PR explorer

For admin use:

  • Added appropriate labels to PR (ex. WIP, R4R, docs, etc)
  • Reviewers assigned
  • Squashed all commits, uses message "Merge pull request #XYZ: [title]" (coding standards)

@alexanderbez alexanderbez added WIP T: API Breaking Breaking changes that impact APIs and the SDK only (not state machine). labels Dec 19, 2019
@alexanderbez alexanderbez mentioned this pull request Dec 19, 2019
11 tasks
@lgtm-com
Copy link

lgtm-com bot commented Dec 23, 2019

This pull request fixes 7 alerts when merging 2bd6fb9 into 6bee805 - view on LGTM.com

fixed alerts:

  • 7 for Impossible interface nil check

@cosmos cosmos deleted a comment from lgtm-com bot Dec 24, 2019
@cosmos cosmos deleted a comment from lgtm-com bot Dec 24, 2019
@cosmos cosmos deleted a comment from lgtm-com bot Dec 24, 2019
@cosmos cosmos deleted a comment from lgtm-com bot Dec 24, 2019
@cosmos cosmos deleted a comment from lgtm-com bot Dec 24, 2019
@cosmos cosmos deleted a comment from lgtm-com bot Dec 24, 2019
@lgtm-com
Copy link

lgtm-com bot commented Dec 24, 2019

This pull request fixes 7 alerts when merging 0ce6f62 into ff229ac - view on LGTM.com

fixed alerts:

  • 7 for Impossible interface nil check

Copy link
Collaborator

@fedekunze fedekunze left a 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
Copy link
Collaborator

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?

Copy link
Contributor Author

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

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

Copy link
Contributor Author

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.

x/staking/types/errors.go Show resolved Hide resolved
@@ -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) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto ValidateBasic

Copy link
Contributor Author

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.

@lgtm-com
Copy link

lgtm-com bot commented Dec 26, 2019

This pull request fixes 7 alerts when merging ba73422 into ff229ac - view on LGTM.com

fixed alerts:

  • 7 for Impossible interface nil check

@alexanderbez
Copy link
Contributor Author

alexanderbez commented Dec 26, 2019

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

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. x/evidence only has a handful of errors, but it reserves 400-499. It can add and register new errors in the future.

Imo we shouldn't assign codes to the sdkerrors.Register function as it should somehow maintain a variable of the latest registered error code.

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 Register function abstracts this, I no longer have the ability to know.

Keep in mind, this PR does not change existing behavior -- it just makes it more strict.

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?

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 StartingErrCode. Maybe this isn't the ideal solution, but we can address this when the time comes.

@fedekunze
Copy link
Collaborator

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. x/evidence only has a handful of errors, but it reserves 400-499

Is that enforced? For example, an app that imports x/evidence can actually use sdkerrors.Register to register the code 450 (i.e set that code as used) if it's not being used by the evidence module.

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

++

@alexanderbez
Copy link
Contributor Author

alexanderbez commented Dec 27, 2019

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+

@cosmos cosmos deleted a comment from lgtm-com bot Dec 27, 2019
@lgtm-com
Copy link

lgtm-com bot commented Dec 27, 2019

This pull request fixes 7 alerts when merging de33669 into ff229ac - view on LGTM.com

fixed alerts:

  • 7 for Impossible interface nil check

@cosmos cosmos deleted a comment from lgtm-com bot Dec 27, 2019
@alexanderbez alexanderbez merged commit e64d87f into bez/4844-handler-error-refactor Dec 27, 2019
@alexanderbez alexanderbez deleted the bez/4844-handler-error-refactor-2 branch December 27, 2019 16:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T: API Breaking Breaking changes that impact APIs and the SDK only (not state machine).
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants