Skip to content

Commit

Permalink
fix: tolerate nil initializer
Browse files Browse the repository at this point in the history
  • Loading branch information
j75689 committed Jan 5, 2023
1 parent c740cd4 commit 17348b9
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions x/upgrade/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package keeper
import (
"encoding/binary"
"encoding/json"
"fmt"
"os"
"path"
"path/filepath"
Expand Down Expand Up @@ -32,7 +31,6 @@ type Keeper struct {
}

// NewKeeper constructs an upgrade Keeper which requires the following arguments:
// skipUpgradeHeights - map of heights to skip an upgrade
// storeKey - a store key with which to access upgrade's store
// cdc - the app-wide binary codec
// homePath - root directory of the application's config
Expand Down Expand Up @@ -325,15 +323,15 @@ func (k Keeper) HasHandler(name string) bool {
// ApplyUpgrade will execute the handler associated with the Plan and mark the plan as done.
func (k Keeper) ApplyUpgrade(ctx sdk.Context, plan types.Plan) {
initializer := k.upgradeInitializer[plan.Name]
if initializer == nil {
ctx.Logger().Error("missing initializer to upgrade [" + plan.Name + "]")
return
}

err := initializer()
if err != nil {
ctx.Logger().Error("failed to init upgrade ["+plan.Name+"]", "err", err)
return
if initializer != nil {
err := initializer()
if err != nil {
ctx.Logger().Error("failed to init upgrade ["+plan.Name+"]", "err", err)
return
}
} else {
ctx.Logger().Error("missing initializer to upgrade [" + plan.Name + "]")
}

handler := k.upgradeHandlers[plan.Name]
Expand Down Expand Up @@ -439,7 +437,8 @@ func (k Keeper) InitUpgraded(ctx sdk.Context) error {
if height < ctx.BlockHeight() {
f := k.upgradeInitializer[upgradeName]
if f == nil {
return fmt.Errorf("missing initializer for the upgrade [" + upgradeName + "]")
k.Logger(ctx).Error("missing initializer for the upgrade [" + upgradeName + "]")
continue
}

err := f()
Expand Down

0 comments on commit 17348b9

Please sign in to comment.