-
Notifications
You must be signed in to change notification settings - Fork 609
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
lint: enable staticcheck #1956
Conversation
@@ -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 { |
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.
Why was this removed?
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.
This is a uint
so it cannot be less than 0
x/epochs/handler.go
Outdated
@@ -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()) |
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.
IMO we shouldn't even have these handler.go
files -- it's all legacy code.
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'm guessing this: cosmos/cosmos-sdk#9650 would be the right way to do it?
cmd/osmosisd/cmd/forceprune.go
Outdated
// 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 | ||
} |
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 don't get why are we doing this? The defer handles this more cleanly?
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.
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
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.
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.
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.
Sweet, yeah followed your advice
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.
LGTM after we resolve the db.Close
Merging since db.Close addressed + 2 approvals |
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 fromstaticcheck
binaryBrief Changelog
defer Close()
GenerateSaveCoinKey
uint
sTesting and Verifying
This change is a trivial rework / code cleanup without any test coverage.
Documentation and Release Note
Unreleased
section inCHANGELOG.md
? no