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

Remove Redundant Staking Errors #9231

Merged
merged 8 commits into from
May 19, 2021

Conversation

jeebster
Copy link
Contributor

@jeebster jeebster commented Apr 29, 2021

Description

closes: #5450


Before we can merge this PR, please make sure that all the following items have been
checked off. If any of the checklist items are not applicable, please leave them but
write a little note why.

  • 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
  • Review Codecov Report in the comment section below once CI passes

@jeebster jeebster mentioned this pull request Apr 29, 2021
4 tasks
@jeebster jeebster force-pushed the jeebster/5450-staking-errors-refactor branch from 30d5bfb to f76023b Compare May 1, 2021 00:43
@codecov
Copy link

codecov bot commented May 1, 2021

Codecov Report

Merging #9231 (d5d99fe) into master (9d05048) will decrease coverage by 0.07%.
The diff coverage is 51.02%.

❗ Current head d5d99fe differs from pull request most recent head 986fa22. Consider uploading reports for the commit 986fa22 to get more accurate results
Impacted file tree graph

@@            Coverage Diff             @@
##           master    #9231      +/-   ##
==========================================
- Coverage   60.38%   60.30%   -0.08%     
==========================================
  Files         587      588       +1     
  Lines       36920    36999      +79     
==========================================
+ Hits        22294    22313      +19     
- Misses      12651    12710      +59     
- Partials     1975     1976       +1     
Impacted Files Coverage Δ
x/staking/client/cli/tx.go 17.98% <0.00%> (ø)
x/staking/keeper/delegation.go 70.73% <0.00%> (ø)
x/staking/keeper/msg_server.go 0.43% <0.00%> (-0.02%) ⬇️
store/rootmulti/store.go 68.23% <50.00%> (-0.24%) ⬇️
x/staking/types/msg.go 57.32% <77.27%> (+2.39%) ⬆️
store/cachemulti/store.go 11.32% <80.00%> (ø)
x/staking/client/testutil/suite.go 99.49% <100.00%> (ø)

@jeebster jeebster force-pushed the jeebster/5450-staking-errors-refactor branch 2 times, most recently from 3d237c2 to f0017fa Compare May 7, 2021 15:02
@jeebster jeebster marked this pull request as ready for review May 7, 2021 21:22
x/staking/client/cli/tx.go Outdated Show resolved Hide resolved
return types.ErrMinSelfDelegationInvalid
return sdkerrors.Wrap(
sdkerrors.ErrInvalidRequest,
"minimum self delegation must be a positive integer",
Copy link
Contributor

Choose a reason for hiding this comment

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

s/positive/valid

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry, not sure what you mean by this...would you like the message argument rephrased?

return txBldr, nil, types.ErrMinSelfDelegationInvalid
return txBldr, nil, sdkerrors.Wrap(
sdkerrors.ErrInvalidRequest,
"minimum self delegation must be a positive integer",
Copy link
Contributor

Choose a reason for hiding this comment

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

s/positive/valid

Copy link
Contributor Author

Choose a reason for hiding this comment

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

See aforementioned

Comment on lines 926 to 929
return shares, sdkerrors.Wrap(
sdkerrors.ErrInvalidRequest,
"invalid shares amount",
)
Copy link
Contributor

Choose a reason for hiding this comment

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

There is no need for all the wrapping. Can we have a single line?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure thing. Is there support for such formatting via the package linters/formatters so this can be automated for all contributors?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Addressed in 8c69a6f3c

Comment on lines 109 to 112
return sdkerrors.Wrap(
sdkerrors.ErrInvalidRequest,
"validator address is invalid",
)
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: single line :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

See aforementioned

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Addressed in 8c69a6f3c

Comment on lines +120 to +123
return sdkerrors.Wrap(
sdkerrors.ErrInvalidRequest,
"invalid delegation amount",
)
Copy link
Contributor

Choose a reason for hiding this comment

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

single line :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

See aforementioned

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Addressed in 8c69a6f3c

@jeebster jeebster force-pushed the jeebster/5450-staking-errors-refactor branch from f0017fa to 8c69a6f Compare May 13, 2021 00:38
@@ -122,7 +123,7 @@ func NewEditValidatorCmd() *cobra.Command {
if minSelfDelegationString != "" {
msb, ok := sdk.NewIntFromString(minSelfDelegationString)
if !ok {
return types.ErrMinSelfDelegationInvalid
return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "minimum self delegation must be a positive integer")
Copy link
Collaborator

Choose a reason for hiding this comment

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

you can use the wrap method of the error, it makes the code a bit shorter

sdkerrors.ErrInvalidRequest.Wrap("minimum self delegation must be a positive integer"

Same in other places.

Copy link
Contributor Author

@jeebster jeebster May 17, 2021

Choose a reason for hiding this comment

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

@robert-zaremba Thanks for bringing this to my attention, I'll take a look at the Wrap() implementation. I see both implementation strategies in the repository, please let me know which is preferred and whether refactoring should be executed accordingly

Copy link
Member

Choose a reason for hiding this comment

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

I think this is more of a nit. We use the design currently coded throughout the repo and the one robert mentioned in a few places.

@robert-zaremba want to approve this?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm not blocking it - I only made a suggestion. The PR already got enough approvals.

Copy link
Collaborator

Choose a reason for hiding this comment

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

BTW - we implemented the Wrap method for the error types 2-3 months ago, that why it's not use that much.

@jeebster jeebster force-pushed the jeebster/5450-staking-errors-refactor branch from 8c69a6f to 4914118 Compare May 19, 2021 00:32
@tac0turtle tac0turtle added the A:automerge Automatically merge PR once all prerequisites pass. label May 19, 2021
@mergify mergify bot merged commit ad49ec1 into cosmos:master May 19, 2021
@jeebster jeebster deleted the jeebster/5450-staking-errors-refactor branch May 25, 2021 00:35
roysc pushed a commit to vulcanize/cosmos-sdk that referenced this pull request Jun 23, 2021
* refactor(staking errors): 'invalid' errors: use ErrInvalidRequest, remove unused error types

* refactor(staking errors): fix error registration codes

* support(staking errors): add changelog entry

* fix(staking test suite): update expected error codes relative to refactor

* chore(staking errors): code formatting

Co-authored-by: Marko <marbar3778@yahoo.com>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A:automerge Automatically merge PR once all prerequisites pass. C:CLI C:x/staking
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Remove Redundant Staking Errors
5 participants