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

lint: enable staticcheck #1956

Merged
merged 7 commits into from Jul 8, 2022
Merged

lint: enable staticcheck #1956

merged 7 commits into from Jul 8, 2022

Conversation

p0mvn
Copy link
Member

@p0mvn p0mvn commented Jul 4, 2022

Closes: #XXX

What is the purpose of the change

Follow-up to: #1897

Please note that this is a staticcheck set of rules (a subset of rules from staticcheck binary

Brief Changelog

Testing and Verifying

This change is a trivial rework / code cleanup without any test coverage.

Documentation and Release Note

  • Does this pull request introduce a new feature or user-facing behavior changes? no
  • Is a relevant changelog entry added to the Unreleased section in CHANGELOG.md? no
  • How is the feature or change documented? not applicable

@p0mvn p0mvn marked this pull request as ready for review July 4, 2022 17:25
@p0mvn p0mvn requested a review from a team July 4, 2022 17:25
@@ -13,8 +11,5 @@ func DefaultGenesis() *GenesisState {
// Validate performs basic genesis state validation returning an error upon any
// failure.
func (gs GenesisState) Validate() error {
if gs.LastLockId < 0 {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why was this removed?

Copy link
Member Author

Choose a reason for hiding this comment

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

This is a uint so it cannot be less than 0

x/incentives/types/genesis.go Show resolved Hide resolved
@@ -13,8 +13,6 @@ import (
// NewHandler returns a handler for epochs module messages.
func NewHandler(k keeper.Keeper) sdk.Handler {
return func(ctx sdk.Context, msg sdk.Msg) (*sdk.Result, error) {
ctx = ctx.WithEventManager(sdk.NewEventManager())
Copy link
Contributor

Choose a reason for hiding this comment

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

IMO we shouldn't even have these handler.go files -- it's all legacy code.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm guessing this: cosmos/cosmos-sdk#9650 would be the right way to do it?

x/incentives/types/genesis.go Show resolved Hide resolved
Comment on lines 150 to 156
// N.B: We duplicate the call to db.Close() on top of
// the call in defer statement above to make sure that the resources
// are properly released and any potential error from Close()
// is handled. Close() should be idempotent so this is acceptable.
if err := db.Close(); err != nil {
return err
}
Copy link
Member

Choose a reason for hiding this comment

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

I don't get why are we doing this? The defer handles this more cleanly?

Copy link
Member Author

Choose a reason for hiding this comment

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

If we do defer db.Close(), it does not do error handling.

The new change validates the error while keeping defer db.Close() as well. The code in defer runs even if the code panics, making sure that we always close the resources. Calling this twice should not be a problem because Close() is idempotent

Copy link
Member

Choose a reason for hiding this comment

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

Can we instead do a named return error, (e.g. func compactBlockStore(dbPath string) (rerr error), and then do defer rerr = db.Close(). This is the general pattern for handling errors in a panic.

Encouraging db closing being isolated scope / not handled multiple times is ideal imo.

Copy link
Member Author

Choose a reason for hiding this comment

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

Sweet, yeah followed your advice

Copy link
Member

@ValarDragon ValarDragon left a comment

Choose a reason for hiding this comment

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

LGTM after we resolve the db.Close

@p0mvn
Copy link
Member Author

p0mvn commented Jul 8, 2022

Merging since db.Close addressed + 2 approvals

@p0mvn p0mvn merged commit 1b5a1d3 into main Jul 8, 2022
@p0mvn p0mvn deleted the roman/lint-staticcheck branch July 8, 2022 00:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

None yet

3 participants