diff --git a/e2e/relayer/relayer.go b/e2e/relayer/relayer.go index dc663379d01..5fc73bcc9ba 100644 --- a/e2e/relayer/relayer.go +++ b/e2e/relayer/relayer.go @@ -40,7 +40,7 @@ func New(t *testing.T, cfg Config, logger *zap.Logger, dockerClient *dockerclien case Hermes: return newHermesRelayer(t, cfg.Tag, logger, dockerClient, network, cfg.Image) default: - panic(fmt.Sprintf("unknown relayer specified: %s", cfg.Type)) + panic(fmt.Errorf("unknown relayer specified: %s", cfg.Type)) } } diff --git a/e2e/testsuite/testsuite.go b/e2e/testsuite/testsuite.go index bf8e351db7d..a4ec8b0f340 100644 --- a/e2e/testsuite/testsuite.go +++ b/e2e/testsuite/testsuite.go @@ -2,6 +2,7 @@ package testsuite import ( "context" + "errors" "fmt" "strings" @@ -272,7 +273,7 @@ func (s *E2ETestSuite) RecoverRelayerWallets(ctx context.Context, ibcrelayer ibc // StartRelayer starts the given ibcrelayer. func (s *E2ETestSuite) StartRelayer(ibcrelayer ibc.Relayer) { if s.startRelayerFn == nil { - panic("cannot start relayer before it is created!") + panic(errors.New("cannot start relayer before it is created!")) } s.startRelayerFn(ibcrelayer) diff --git a/modules/apps/27-interchain-accounts/controller/ibc_middleware.go b/modules/apps/27-interchain-accounts/controller/ibc_middleware.go index bf6f047bbef..b51592a12d8 100644 --- a/modules/apps/27-interchain-accounts/controller/ibc_middleware.go +++ b/modules/apps/27-interchain-accounts/controller/ibc_middleware.go @@ -1,6 +1,8 @@ package controller import ( + "errors" + errorsmod "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" @@ -239,7 +241,7 @@ func (IBCMiddleware) SendPacket( timeoutTimestamp uint64, data []byte, ) (uint64, error) { - panic("SendPacket not supported for ICA controller module. Please use SendTx") + panic(errors.New("SendPacket not supported for ICA controller module. Please use SendTx")) } // WriteAcknowledgement implements the ICS4 Wrapper interface @@ -249,7 +251,7 @@ func (IBCMiddleware) WriteAcknowledgement( packet ibcexported.PacketI, ack ibcexported.Acknowledgement, ) error { - panic("WriteAcknowledgement not supported for ICA controller module") + panic(errors.New("WriteAcknowledgement not supported for ICA controller module")) } // GetAppVersion returns the interchain accounts metadata. diff --git a/modules/apps/27-interchain-accounts/controller/keeper/genesis.go b/modules/apps/27-interchain-accounts/controller/keeper/genesis.go index 10655ff3367..c943eab8304 100644 --- a/modules/apps/27-interchain-accounts/controller/keeper/genesis.go +++ b/modules/apps/27-interchain-accounts/controller/keeper/genesis.go @@ -21,7 +21,7 @@ func InitGenesis(ctx sdk.Context, keeper Keeper, state genesistypes.ControllerGe // use the controller scoped keeper to claim the port capability if err := keeper.ClaimCapability(ctx, capability, host.PortPath(portID)); err != nil { - panic(fmt.Sprintf("could not claim port capability: %v", err)) + panic(fmt.Errorf("could not claim port capability: %v", err)) } } } diff --git a/modules/apps/27-interchain-accounts/controller/keeper/handshake.go b/modules/apps/27-interchain-accounts/controller/keeper/handshake.go index ea87c19bf40..0ce3802b48e 100644 --- a/modules/apps/27-interchain-accounts/controller/keeper/handshake.go +++ b/modules/apps/27-interchain-accounts/controller/keeper/handshake.go @@ -64,7 +64,7 @@ func (k Keeper) OnChanOpenInit( if found { channel, found := k.channelKeeper.GetChannel(ctx, portID, activeChannelID) if !found { - panic(fmt.Sprintf("active channel mapping set for %s but channel does not exist in channel store", activeChannelID)) + panic(fmt.Errorf("active channel mapping set for %s but channel does not exist in channel store", activeChannelID)) } if channel.IsOpen() { @@ -73,7 +73,7 @@ func (k Keeper) OnChanOpenInit( appVersion, found := k.GetAppVersion(ctx, portID, activeChannelID) if !found { - panic(fmt.Sprintf("active channel mapping set for %s, but channel does not exist in channel store", activeChannelID)) + panic(fmt.Errorf("active channel mapping set for %s, but channel does not exist in channel store", activeChannelID)) } if !icatypes.IsPreviousMetadataEqual(appVersion, metadata) { diff --git a/modules/apps/27-interchain-accounts/controller/keeper/keeper.go b/modules/apps/27-interchain-accounts/controller/keeper/keeper.go index 78980421d65..0ac0ececc24 100644 --- a/modules/apps/27-interchain-accounts/controller/keeper/keeper.go +++ b/modules/apps/27-interchain-accounts/controller/keeper/keeper.go @@ -2,6 +2,7 @@ package keeper import ( "bytes" + "errors" "fmt" "strings" @@ -53,7 +54,7 @@ func NewKeeper( } if strings.TrimSpace(authority) == "" { - panic(fmt.Errorf("authority must be non-empty")) + panic(errors.New("authority must be non-empty")) } return Keeper{ @@ -290,7 +291,7 @@ func (k Keeper) GetParams(ctx sdk.Context) types.Params { store := ctx.KVStore(k.storeKey) bz := store.Get([]byte(types.ParamsKey)) if bz == nil { // only panic on unset params and not on empty params - panic("ica/controller params are not set in store") + panic(errors.New("ica/controller params are not set in store")) } var params types.Params diff --git a/modules/apps/27-interchain-accounts/host/keeper/genesis.go b/modules/apps/27-interchain-accounts/host/keeper/genesis.go index 28d58c3f766..c4d9dc1aa0b 100644 --- a/modules/apps/27-interchain-accounts/host/keeper/genesis.go +++ b/modules/apps/27-interchain-accounts/host/keeper/genesis.go @@ -21,7 +21,7 @@ func InitGenesis(ctx sdk.Context, keeper Keeper, state genesistypes.HostGenesisS // use the host scoped keeper to claim the port capability if err := keeper.ClaimCapability(ctx, capability, host.PortPath(state.Port)); err != nil { - panic(fmt.Sprintf("could not claim port capability: %v", err)) + panic(fmt.Errorf("could not claim port capability: %v", err)) } } @@ -34,7 +34,7 @@ func InitGenesis(ctx sdk.Context, keeper Keeper, state genesistypes.HostGenesisS } if err := state.Params.Validate(); err != nil { - panic(fmt.Sprintf("could not set ica host params at genesis: %v", err)) + panic(fmt.Errorf("could not set ica host params at genesis: %v", err)) } keeper.SetParams(ctx, state.Params) } diff --git a/modules/apps/27-interchain-accounts/host/keeper/handshake.go b/modules/apps/27-interchain-accounts/host/keeper/handshake.go index 6e21866c18f..f3a202a3bae 100644 --- a/modules/apps/27-interchain-accounts/host/keeper/handshake.go +++ b/modules/apps/27-interchain-accounts/host/keeper/handshake.go @@ -48,7 +48,7 @@ func (k Keeper) OnChanOpenTry( if found { channel, found := k.channelKeeper.GetChannel(ctx, portID, activeChannelID) if !found { - panic(fmt.Sprintf("active channel mapping set for %s but channel does not exist in channel store", activeChannelID)) + panic(fmt.Errorf("active channel mapping set for %s but channel does not exist in channel store", activeChannelID)) } if channel.IsOpen() { @@ -57,7 +57,7 @@ func (k Keeper) OnChanOpenTry( appVersion, found := k.GetAppVersion(ctx, portID, activeChannelID) if !found { - panic(fmt.Sprintf("active channel mapping set for %s, but channel does not exist in channel store", activeChannelID)) + panic(fmt.Errorf("active channel mapping set for %s, but channel does not exist in channel store", activeChannelID)) } if !icatypes.IsPreviousMetadataEqual(appVersion, metadata) { diff --git a/modules/apps/27-interchain-accounts/host/keeper/keeper.go b/modules/apps/27-interchain-accounts/host/keeper/keeper.go index b60ac4d652c..d063c9a932a 100644 --- a/modules/apps/27-interchain-accounts/host/keeper/keeper.go +++ b/modules/apps/27-interchain-accounts/host/keeper/keeper.go @@ -1,6 +1,7 @@ package keeper import ( + "errors" "fmt" "strings" @@ -51,7 +52,7 @@ func NewKeeper( ) Keeper { // ensure ibc interchain accounts module account is set if addr := accountKeeper.GetModuleAddress(icatypes.ModuleName); addr == nil { - panic("the Interchain Accounts module account has not been set") + panic(errors.New("the Interchain Accounts module account has not been set")) } // set KeyTable if it has not already been set @@ -60,7 +61,7 @@ func NewKeeper( } if strings.TrimSpace(authority) == "" { - panic(fmt.Errorf("authority must be non-empty")) + panic(errors.New("authority must be non-empty")) } return Keeper{ @@ -243,7 +244,7 @@ func (k Keeper) GetParams(ctx sdk.Context) types.Params { store := ctx.KVStore(k.storeKey) bz := store.Get([]byte(types.ParamsKey)) if bz == nil { // only panic on unset params and not on empty params - panic("ica/host params are not set in store") + panic(errors.New("ica/host params are not set in store")) } var params types.Params diff --git a/modules/apps/27-interchain-accounts/host/keeper/keeper_test.go b/modules/apps/27-interchain-accounts/host/keeper/keeper_test.go index 95dd3f8b89c..a300832818d 100644 --- a/modules/apps/27-interchain-accounts/host/keeper/keeper_test.go +++ b/modules/apps/27-interchain-accounts/host/keeper/keeper_test.go @@ -73,7 +73,7 @@ func NewICAPath(chainA, chainB *ibctesting.TestChain, encoding string) *ibctesti case icatypes.EncodingProto3JSON: version = TestVersionWithJSONEncoding default: - panic(fmt.Sprintf("unsupported encoding type: %s", encoding)) + panic(fmt.Errorf("unsupported encoding type: %s", encoding)) } path.EndpointA.ChannelConfig.PortID = icatypes.HostPortID diff --git a/modules/apps/27-interchain-accounts/module.go b/modules/apps/27-interchain-accounts/module.go index 0236b295852..0c60f84185a 100644 --- a/modules/apps/27-interchain-accounts/module.go +++ b/modules/apps/27-interchain-accounts/module.go @@ -132,7 +132,7 @@ func (am AppModule) InitModule(ctx sdk.Context, controllerParams controllertypes if am.hostKeeper != nil { if err := hostParams.Validate(); err != nil { - panic(fmt.Sprintf("could not set ica host params at initialization: %v", err)) + panic(fmt.Errorf("could not set ica host params at initialization: %v", err)) } hostkeeper.InitGenesis(ctx, *am.hostKeeper, genesistypes.HostGenesisState{ @@ -156,7 +156,7 @@ func (am AppModule) RegisterServices(cfg module.Configurator) { controllerMigrator := controllerkeeper.NewMigrator(am.controllerKeeper) if err := cfg.RegisterMigration(types.ModuleName, 1, controllerMigrator.AssertChannelCapabilityMigrations); err != nil { - panic(fmt.Sprintf("failed to migrate interchainaccounts app from version 1 to 2 (channel capabilities owned by controller submodule check): %v", err)) + panic(fmt.Errorf("failed to migrate interchainaccounts app from version 1 to 2 (channel capabilities owned by controller submodule check): %v", err)) } hostMigrator := hostkeeper.NewMigrator(am.hostKeeper) @@ -166,7 +166,7 @@ func (am AppModule) RegisterServices(cfg module.Configurator) { } return controllerMigrator.MigrateParams(ctx) }); err != nil { - panic(fmt.Sprintf("failed to migrate interchainaccounts app from version 2 to 3 (self-managed params migration): %v", err)) + panic(fmt.Errorf("failed to migrate interchainaccounts app from version 2 to 3 (self-managed params migration): %v", err)) } } diff --git a/modules/apps/27-interchain-accounts/simulation/decoder.go b/modules/apps/27-interchain-accounts/simulation/decoder.go index e6cb57a15f2..c45dd9a0447 100644 --- a/modules/apps/27-interchain-accounts/simulation/decoder.go +++ b/modules/apps/27-interchain-accounts/simulation/decoder.go @@ -24,7 +24,7 @@ func NewDecodeStore() func(kvA, kvB kv.Pair) string { return fmt.Sprintf("IsMiddlewareEnabled A: %s\nIsMiddlewareEnabled B: %s", string(kvA.Value), string(kvB.Value)) default: - panic(fmt.Sprintf("invalid %s key prefix %s", types.ModuleName, kvA.Key)) + panic(fmt.Errorf("invalid %s key prefix %s", types.ModuleName, kvA.Key)) } } } diff --git a/modules/apps/29-fee/keeper/escrow.go b/modules/apps/29-fee/keeper/escrow.go index 59a1a607a74..e21dc85fb99 100644 --- a/modules/apps/29-fee/keeper/escrow.go +++ b/modules/apps/29-fee/keeper/escrow.go @@ -69,7 +69,7 @@ func (k Keeper) DistributePacketFeesOnAcknowledgement(ctx sdk.Context, forwardRe // check if refundAcc address works refundAddr, err := sdk.AccAddressFromBech32(packetFee.RefundAddress) if err != nil { - panic(fmt.Sprintf("could not parse refundAcc %s to sdk.AccAddress", packetFee.RefundAddress)) + panic(fmt.Errorf("could not parse refundAcc %s to sdk.AccAddress", packetFee.RefundAddress)) } k.distributePacketFeeOnAcknowledgement(cacheCtx, refundAddr, forwardAddr, reverseRelayer, packetFee) @@ -122,7 +122,7 @@ func (k Keeper) DistributePacketFeesOnTimeout(ctx sdk.Context, timeoutRelayer sd // check if refundAcc address works refundAddr, err := sdk.AccAddressFromBech32(packetFee.RefundAddress) if err != nil { - panic(fmt.Sprintf("could not parse refundAcc %s to sdk.AccAddress", packetFee.RefundAddress)) + panic(fmt.Errorf("could not parse refundAcc %s to sdk.AccAddress", packetFee.RefundAddress)) } k.distributePacketFeeOnTimeout(cacheCtx, refundAddr, timeoutRelayer, packetFee) diff --git a/modules/apps/callbacks/callbacks_test.go b/modules/apps/callbacks/callbacks_test.go index 5696a68429e..9796913cef6 100644 --- a/modules/apps/callbacks/callbacks_test.go +++ b/modules/apps/callbacks/callbacks_test.go @@ -2,6 +2,7 @@ package ibccallbacks_test import ( "encoding/json" + "errors" "fmt" "testing" @@ -46,7 +47,7 @@ func SetupTestingApp() (ibctesting.TestingApp, map[string]json.RawMessage) { func GetSimApp(chain *ibctesting.TestChain) *simapp.SimApp { app, ok := chain.App.(*simapp.SimApp) if !ok { - panic("chain is not a simapp.SimApp") + panic(errors.New("chain is not a simapp.SimApp")) } return app } diff --git a/modules/apps/callbacks/ibc_middleware.go b/modules/apps/callbacks/ibc_middleware.go index ea4835b590a..c7438df23be 100644 --- a/modules/apps/callbacks/ibc_middleware.go +++ b/modules/apps/callbacks/ibc_middleware.go @@ -1,6 +1,7 @@ package ibccallbacks import ( + "errors" "fmt" errorsmod "cosmossdk.io/errors" @@ -48,15 +49,15 @@ func NewIBCMiddleware( } if ics4Wrapper == nil { - panic(fmt.Errorf("ICS4Wrapper cannot be nil")) + panic(errors.New("ICS4Wrapper cannot be nil")) } if contractKeeper == nil { - panic(fmt.Errorf("contract keeper cannot be nil")) + panic(errors.New("contract keeper cannot be nil")) } if maxCallbackGas == 0 { - panic(fmt.Errorf("maxCallbackGas cannot be zero")) + panic(errors.New("maxCallbackGas cannot be zero")) } return IBCMiddleware{ diff --git a/modules/apps/callbacks/testing/simapp/export.go b/modules/apps/callbacks/testing/simapp/export.go index 40891d5182e..375a9a642fc 100644 --- a/modules/apps/callbacks/testing/simapp/export.go +++ b/modules/apps/callbacks/testing/simapp/export.go @@ -2,6 +2,7 @@ package simapp import ( "encoding/json" + "errors" "log" storetypes "cosmossdk.io/store/types" @@ -206,7 +207,7 @@ func (app *SimApp) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs [] addr := sdk.ValAddress(stakingtypes.AddressFromValidatorsKey(iter.Key())) validator, err := app.StakingKeeper.GetValidator(ctx, addr) if err != nil { - panic("expected validator, not found") + panic(errors.New("expected validator, not found")) } validator.UnbondingHeight = 0 @@ -216,7 +217,7 @@ func (app *SimApp) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs [] err = app.StakingKeeper.SetValidator(ctx, validator) if err != nil { - panic("couldn't set validator") + panic(errors.New("couldn't set validator")) } counter++ } diff --git a/modules/apps/transfer/keeper/genesis.go b/modules/apps/transfer/keeper/genesis.go index 483342c5230..0a98db41e2f 100644 --- a/modules/apps/transfer/keeper/genesis.go +++ b/modules/apps/transfer/keeper/genesis.go @@ -24,7 +24,7 @@ func (k Keeper) InitGenesis(ctx sdk.Context, state types.GenesisState) { // and claims the returned capability err := k.BindPort(ctx, state.PortId) if err != nil { - panic(fmt.Sprintf("could not claim port capability: %v", err)) + panic(fmt.Errorf("could not claim port capability: %v", err)) } } diff --git a/modules/apps/transfer/keeper/keeper.go b/modules/apps/transfer/keeper/keeper.go index e3e0da974fc..782fcdb94b8 100644 --- a/modules/apps/transfer/keeper/keeper.go +++ b/modules/apps/transfer/keeper/keeper.go @@ -1,6 +1,7 @@ package keeper import ( + "errors" "fmt" "strings" @@ -56,7 +57,7 @@ func NewKeeper( ) Keeper { // ensure ibc transfer module account is set if addr := authKeeper.GetModuleAddress(types.ModuleName); addr == nil { - panic("the IBC transfer module account has not been set") + panic(errors.New("the IBC transfer module account has not been set")) } // set KeyTable if it has not already been set if !legacySubspace.HasKeyTable() { @@ -64,7 +65,7 @@ func NewKeeper( } if strings.TrimSpace(authority) == "" { - panic(fmt.Errorf("authority must be non-empty")) + panic(errors.New("authority must be non-empty")) } return Keeper{ @@ -128,7 +129,7 @@ func (k Keeper) GetParams(ctx sdk.Context) types.Params { store := ctx.KVStore(k.storeKey) bz := store.Get([]byte(types.ParamsKey)) if bz == nil { // only panic on unset params and not on empty params - panic("transfer params are not set in store") + panic(errors.New("transfer params are not set in store")) } var params types.Params @@ -239,7 +240,7 @@ func (k Keeper) GetTotalEscrowForDenom(ctx sdk.Context, denom string) sdk.Coin { // if the amount is negative. func (k Keeper) SetTotalEscrowForDenom(ctx sdk.Context, coin sdk.Coin) { if coin.Amount.IsNegative() { - panic(fmt.Sprintf("amount cannot be negative: %s", coin.Amount)) + panic(fmt.Errorf("amount cannot be negative: %s", coin.Amount)) } store := ctx.KVStore(k.storeKey) diff --git a/modules/apps/transfer/keeper/mbt_relay_test.go b/modules/apps/transfer/keeper/mbt_relay_test.go index dc67080e928..ee7d60f6f71 100644 --- a/modules/apps/transfer/keeper/mbt_relay_test.go +++ b/modules/apps/transfer/keeper/mbt_relay_test.go @@ -6,6 +6,7 @@ package keeper_test import ( "encoding/json" + "errors" "fmt" "os" "strconv" @@ -99,7 +100,7 @@ func AddressFromString(address string) string { func AddressFromTla(addr []string) string { if len(addr) != 3 { - panic("failed to convert from TLA+ address: wrong number of address components") + panic(errors.New("failed to convert from TLA+ address: wrong number of address components")) } s := "" if len(addr[0]) == 0 && len(addr[1]) == 0 { //nolint:gocritic @@ -109,7 +110,7 @@ func AddressFromTla(addr []string) string { // escrow address: ics20-1\x00port/channel s = fmt.Sprintf("%s\x00%s/%s", types.Version, addr[0], addr[1]) } else { - panic("failed to convert from TLA+ address: neither simple nor escrow address") + panic(errors.New("failed to convert from TLA+ address: neither simple nor escrow address")) } return s } @@ -333,7 +334,7 @@ func (suite *KeeperTestSuite) TestModelBasedRelay() { var sender sdk.AccAddress sender, err = sdk.AccAddressFromBech32(tc.packet.Data.Sender) if err != nil { - panic("MBT failed to convert sender address") + panic(errors.New("MBT failed to convert sender address")) } registerDenomFn() denomTrace := types.ParseDenomTrace(tc.packet.Data.Denom) @@ -342,7 +343,7 @@ func (suite *KeeperTestSuite) TestModelBasedRelay() { if err == nil { amount, ok := sdkmath.NewIntFromString(tc.packet.Data.Amount) if !ok { - panic("MBT failed to parse amount from string") + panic(errors.New("MBT failed to parse amount from string")) } msg := types.NewMsgTransfer( tc.packet.SourcePort, diff --git a/modules/apps/transfer/keeper/migrations.go b/modules/apps/transfer/keeper/migrations.go index c0bb192ea49..ae13ab7c80e 100644 --- a/modules/apps/transfer/keeper/migrations.go +++ b/modules/apps/transfer/keeper/migrations.go @@ -49,7 +49,7 @@ func (m Migrator) MigrateTraces(ctx sdk.Context) error { // The new form of parsing will result in a token denomination change. // A bank migration is required. A panic should occur to prevent the // chain from using corrupted state. - panic(fmt.Sprintf("migration will result in corrupted state. Previous IBC token (%s) requires a bank migration. Expected denom trace (%s)", dt, newTrace)) + panic(fmt.Errorf("migration will result in corrupted state. Previous IBC token (%s) requires a bank migration. Expected denom trace (%s)", dt, newTrace)) } if !equalTraces(newTrace, dt) { diff --git a/modules/apps/transfer/keeper/relay.go b/modules/apps/transfer/keeper/relay.go index 91389d1921c..abe804d0718 100644 --- a/modules/apps/transfer/keeper/relay.go +++ b/modules/apps/transfer/keeper/relay.go @@ -126,7 +126,7 @@ func (k Keeper) sendTransfer( // NOTE: should not happen as the module account was // retrieved on the step above and it has enough balace // to burn. - panic(fmt.Sprintf("cannot burn coins after a successful send to a module account: %v", err)) + panic(fmt.Errorf("cannot burn coins after a successful send to a module account: %v", err)) } } @@ -367,7 +367,7 @@ func (k Keeper) refundPacketToken(ctx sdk.Context, packet channeltypes.Packet, d } if err := k.bankKeeper.SendCoinsFromModuleToAccount(ctx, types.ModuleName, sender, sdk.NewCoins(token)); err != nil { - panic(fmt.Sprintf("unable to send coins from module to account despite previously minting coins to module account: %v", err)) + panic(fmt.Errorf("unable to send coins from module to account despite previously minting coins to module account: %v", err)) } return nil diff --git a/modules/apps/transfer/module.go b/modules/apps/transfer/module.go index 90a70047a71..1e2852bdb5b 100644 --- a/modules/apps/transfer/module.go +++ b/modules/apps/transfer/module.go @@ -122,19 +122,19 @@ func (am AppModule) RegisterServices(cfg module.Configurator) { m := keeper.NewMigrator(am.keeper) if err := cfg.RegisterMigration(types.ModuleName, 1, m.MigrateTraces); err != nil { - panic(fmt.Sprintf("failed to migrate transfer app from version 1 to 2 (denom trace format migration): %v", err)) + panic(fmt.Errorf("failed to migrate transfer app from version 1 to 2 (denom trace format migration): %v", err)) } if err := cfg.RegisterMigration(types.ModuleName, 2, m.MigrateTotalEscrowForDenom); err != nil { - panic(fmt.Sprintf("failed to migrate transfer app from version 2 to 3 (total escrow entry migration): %v", err)) + panic(fmt.Errorf("failed to migrate transfer app from version 2 to 3 (total escrow entry migration): %v", err)) } if err := cfg.RegisterMigration(types.ModuleName, 3, m.MigrateParams); err != nil { - panic(fmt.Sprintf("failed to migrate transfer app version 3 to 4 (self-managed params migration): %v", err)) + panic(fmt.Errorf("failed to migrate transfer app version 3 to 4 (self-managed params migration): %v", err)) } if err := cfg.RegisterMigration(types.ModuleName, 4, m.MigrateDenomMetadata); err != nil { - panic(fmt.Sprintf("failed to migrate transfer app from version 4 to 5 (set denom metadata migration): %v", err)) + panic(fmt.Errorf("failed to migrate transfer app from version 4 to 5 (set denom metadata migration): %v", err)) } } diff --git a/modules/apps/transfer/simulation/decoder.go b/modules/apps/transfer/simulation/decoder.go index f371ea3da4d..bcd8d8c2c73 100644 --- a/modules/apps/transfer/simulation/decoder.go +++ b/modules/apps/transfer/simulation/decoder.go @@ -28,7 +28,7 @@ func NewDecodeStore(cdc TransferUnmarshaler) func(kvA, kvB kv.Pair) string { return fmt.Sprintf("DenomTrace A: %s\nDenomTrace B: %s", denomTraceA.IBCDenom(), denomTraceB.IBCDenom()) default: - panic(fmt.Sprintf("invalid %s key prefix %X", types.ModuleName, kvA.Key[:1])) + panic(fmt.Errorf("invalid %s key prefix %X", types.ModuleName, kvA.Key[:1])) } } } diff --git a/modules/capability/keeper/keeper.go b/modules/capability/keeper/keeper.go index 3283449b5aa..e5d853f0285 100644 --- a/modules/capability/keeper/keeper.go +++ b/modules/capability/keeper/keeper.go @@ -1,6 +1,7 @@ package keeper import ( + "errors" "fmt" "strings" @@ -70,14 +71,14 @@ func NewKeeper(cdc codec.BinaryCodec, storeKey, memKey storetypes.StoreKey) *Kee // already has a ScopedKeeper. func (k *Keeper) ScopeToModule(moduleName string) ScopedKeeper { if k.sealed { - panic("cannot scope to module via a sealed capability keeper") + panic(errors.New("cannot scope to module via a sealed capability keeper")) } if strings.TrimSpace(moduleName) == "" { - panic("cannot scope to an empty module name") + panic(errors.New("cannot scope to an empty module name")) } if _, ok := k.scopedModules[moduleName]; ok { - panic(fmt.Sprintf("cannot create multiple scoped keepers for the same module name: %s", moduleName)) + panic(fmt.Errorf("cannot create multiple scoped keepers for the same module name: %s", moduleName)) } k.scopedModules[moduleName] = struct{}{} @@ -95,7 +96,7 @@ func (k *Keeper) ScopeToModule(moduleName string) ScopedKeeper { // Seal may be called during app initialization for applications that do not wish to create scoped keepers dynamically. func (k *Keeper) Seal() { if k.sealed { - panic("cannot initialize and seal an already sealed capability keeper") + panic(errors.New("cannot initialize and seal an already sealed capability keeper")) } k.sealed = true @@ -116,7 +117,7 @@ func (k *Keeper) InitMemStore(ctx sdk.Context) { memStoreType := memStore.GetStoreType() if memStoreType != storetypes.StoreTypeMemory { - panic(fmt.Sprintf("invalid memory store type; got %s, expected: %s", memStoreType, storetypes.StoreTypeMemory)) + panic(fmt.Errorf("invalid memory store type; got %s, expected: %s", memStoreType, storetypes.StoreTypeMemory)) } // create context with no block gas meter to ensure we do not consume gas during local initialization logic. @@ -156,11 +157,11 @@ func (k *Keeper) IsInitialized(ctx sdk.Context) bool { // It will panic if the provided index is 0, or if the index is already set. func (k Keeper) InitializeIndex(ctx sdk.Context, index uint64) error { if index == 0 { - panic("SetIndex requires index > 0") + panic(errors.New("SetIndex requires index > 0")) } latest := k.GetLatestIndex(ctx) if latest > 0 { - panic("SetIndex requires index to not be set") + panic(errors.New("SetIndex requires index to not be set")) } // set the global index to the passed index @@ -390,7 +391,7 @@ func (sk ScopedKeeper) GetCapability(ctx sdk.Context, name string) (*types.Capab cap := sk.capMap[index] if cap == nil { - panic("capability found in memstore is missing from map") + panic(errors.New("capability found in memstore is missing from map")) } return cap, true diff --git a/modules/capability/simulation/decoder.go b/modules/capability/simulation/decoder.go index c064f2d6604..651cdb542fe 100644 --- a/modules/capability/simulation/decoder.go +++ b/modules/capability/simulation/decoder.go @@ -28,7 +28,7 @@ func NewDecodeStore(cdc codec.Codec) func(kvA, kvB kv.Pair) string { return fmt.Sprintf("CapabilityOwners A: %v\nCapabilityOwners B: %v\n", capOwnersA, capOwnersB) default: - panic(fmt.Sprintf("invalid %s key prefix %X (%s)", types.ModuleName, kvA.Key, kvA.Key)) + panic(fmt.Errorf("invalid %s key prefix %X (%s)", types.ModuleName, kvA.Key, kvA.Key)) } } } diff --git a/modules/core/02-client/genesis.go b/modules/core/02-client/genesis.go index 37fe651cb5d..17b6e663364 100644 --- a/modules/core/02-client/genesis.go +++ b/modules/core/02-client/genesis.go @@ -1,6 +1,7 @@ package client import ( + "errors" "fmt" sdk "github.com/cosmos/cosmos-sdk/types" @@ -14,7 +15,7 @@ import ( // state. func InitGenesis(ctx sdk.Context, k keeper.Keeper, gs types.GenesisState) { if err := gs.Params.Validate(); err != nil { - panic(fmt.Sprintf("invalid ibc client genesis state parameters: %v", err)) + panic(fmt.Errorf("invalid ibc client genesis state parameters: %v", err)) } k.SetParams(ctx, gs.Params) @@ -27,11 +28,11 @@ func InitGenesis(ctx sdk.Context, k keeper.Keeper, gs types.GenesisState) { for _, client := range gs.Clients { cs, ok := client.ClientState.GetCachedValue().(exported.ClientState) if !ok { - panic("invalid client state") + panic(errors.New("invalid client state")) } if !gs.Params.IsAllowedClient(cs.ClientType()) { - panic(fmt.Sprintf("client state type %s is not registered on the allowlist", cs.ClientType())) + panic(fmt.Errorf("client state type %s is not registered on the allowlist", cs.ClientType())) } k.SetClientState(ctx, client.ClientId, cs) @@ -41,7 +42,7 @@ func InitGenesis(ctx sdk.Context, k keeper.Keeper, gs types.GenesisState) { for _, consState := range cs.ConsensusStates { consensusState, ok := consState.ConsensusState.GetCachedValue().(exported.ConsensusState) if !ok { - panic(fmt.Sprintf("invalid consensus state with client ID %s at height %s", cs.ClientId, consState.Height)) + panic(fmt.Errorf("invalid consensus state with client ID %s at height %s", cs.ClientId, consState.Height)) } k.SetClientConsensusState(ctx, cs.ClientId, consState.Height, consensusState) @@ -53,7 +54,7 @@ func InitGenesis(ctx sdk.Context, k keeper.Keeper, gs types.GenesisState) { // if the localhost already exists in state (included in the genesis file), // it must be overwritten to ensure its stored height equals the context block height if err := k.CreateLocalhostClient(ctx); err != nil { - panic(fmt.Sprintf("failed to initialise localhost client: %s", err.Error())) + panic(fmt.Errorf("failed to initialise localhost client: %s", err.Error())) } } diff --git a/modules/core/02-client/keeper/keeper.go b/modules/core/02-client/keeper/keeper.go index 8efb679e18e..887587ce9c9 100644 --- a/modules/core/02-client/keeper/keeper.go +++ b/modules/core/02-client/keeper/keeper.go @@ -1,6 +1,7 @@ package keeper import ( + "errors" "fmt" "reflect" "strings" @@ -120,7 +121,7 @@ func (k Keeper) GetNextClientSequence(ctx sdk.Context) uint64 { store := ctx.KVStore(k.storeKey) bz := store.Get([]byte(types.KeyNextClientSequence)) if len(bz) == 0 { - panic("next client sequence is nil") + panic(errors.New("next client sequence is nil")) } return sdk.BigEndianToUint64(bz) @@ -425,7 +426,7 @@ func (k Keeper) GetParams(ctx sdk.Context) types.Params { store := ctx.KVStore(k.storeKey) bz := store.Get([]byte(types.ParamsKey)) if bz == nil { // only panic on unset params and not on empty params - panic("client params are not set in store") + panic(errors.New("client params are not set in store")) } var params types.Params diff --git a/modules/core/02-client/migrations/v7/solomachine.go b/modules/core/02-client/migrations/v7/solomachine.go index 4b9b1a82fa6..7a8799e6129 100644 --- a/modules/core/02-client/migrations/v7/solomachine.go +++ b/modules/core/02-client/migrations/v7/solomachine.go @@ -1,6 +1,8 @@ package v7 import ( + "errors" + storetypes "cosmossdk.io/store/types" "github.com/cosmos/cosmos-sdk/codec" @@ -52,75 +54,75 @@ func (cs ConsensusState) UnpackInterfaces(unpacker codectypes.AnyUnpacker) error // ClientType panics! func (ClientState) ClientType() string { - panic("legacy solo machine is deprecated!") + panic(errors.New("legacy solo machine is deprecated")) } // GetLatestHeight panics! func (ClientState) GetLatestHeight() exported.Height { - panic("legacy solo machine is deprecated!") + panic(errors.New("legacy solo machine is deprecated")) } // Status panics! func (ClientState) Status(_ sdk.Context, _ storetypes.KVStore, _ codec.BinaryCodec) exported.Status { - panic("legacy solo machine is deprecated!") + panic(errors.New("legacy solo machine is deprecated")) } // Validate panics! func (ClientState) Validate() error { - panic("legacy solo machine is deprecated!") + panic(errors.New("legacy solo machine is deprecated")) } // ZeroCustomFields panics! func (ClientState) ZeroCustomFields() exported.ClientState { - panic("legacy solo machine is deprecated!") + panic(errors.New("legacy solo machine is deprecated")) } // Initialize panics! func (ClientState) Initialize(_ sdk.Context, _ codec.BinaryCodec, _ storetypes.KVStore, _ exported.ConsensusState) error { - panic("legacy solo machine is deprecated!") + panic(errors.New("legacy solo machine is deprecated")) } // ExportMetadata panics! func (ClientState) ExportMetadata(_ storetypes.KVStore) []exported.GenesisMetadata { - panic("legacy solo machine is deprecated!") + panic(errors.New("legacy solo machine is deprecated")) } // CheckForMisbehaviour panics! func (ClientState) CheckForMisbehaviour(_ sdk.Context, _ codec.BinaryCodec, _ storetypes.KVStore, _ exported.ClientMessage) bool { - panic("legacy solo machine is deprecated!") + panic(errors.New("legacy solo machine is deprecated")) } // UpdateStateOnMisbehaviour panics! func (*ClientState) UpdateStateOnMisbehaviour( _ sdk.Context, _ codec.BinaryCodec, _ storetypes.KVStore, _ exported.ClientMessage, ) { - panic("legacy solo machine is deprecated!") + panic(errors.New("legacy solo machine is deprecated")) } // VerifyClientMessage panics! func (*ClientState) VerifyClientMessage( _ sdk.Context, _ codec.BinaryCodec, _ storetypes.KVStore, _ exported.ClientMessage, ) error { - panic("legacy solo machine is deprecated!") + panic(errors.New("legacy solo machine is deprecated")) } // UpdateState panis! func (*ClientState) UpdateState(_ sdk.Context, _ codec.BinaryCodec, _ storetypes.KVStore, _ exported.ClientMessage) []exported.Height { - panic("legacy solo machine is deprecated!") + panic(errors.New("legacy solo machine is deprecated")) } // CheckHeaderAndUpdateState panics! func (*ClientState) CheckHeaderAndUpdateState( _ sdk.Context, _ codec.BinaryCodec, _ storetypes.KVStore, _ exported.ClientMessage, ) (exported.ClientState, exported.ConsensusState, error) { - panic("legacy solo machine is deprecated!") + panic(errors.New("legacy solo machine is deprecated")) } // CheckMisbehaviourAndUpdateState panics! func (ClientState) CheckMisbehaviourAndUpdateState( _ sdk.Context, _ codec.BinaryCodec, _ storetypes.KVStore, _ exported.ClientMessage, ) (exported.ClientState, error) { - panic("legacy solo machine is deprecated!") + panic(errors.New("legacy solo machine is deprecated")) } // CheckSubstituteAndUpdateState panics! @@ -128,7 +130,7 @@ func (ClientState) CheckSubstituteAndUpdateState( ctx sdk.Context, _ codec.BinaryCodec, _, _ storetypes.KVStore, _ exported.ClientState, ) error { - panic("legacy solo machine is deprecated!") + panic(errors.New("legacy solo machine is deprecated")) } // VerifyUpgradeAndUpdateState panics! @@ -136,7 +138,7 @@ func (ClientState) VerifyUpgradeAndUpdateState( _ sdk.Context, _ codec.BinaryCodec, _ storetypes.KVStore, _ exported.ClientState, _ exported.ConsensusState, _, _ []byte, ) error { - panic("legacy solo machine is deprecated!") + panic(errors.New("legacy solo machine is deprecated")) } // VerifyClientState panics! @@ -144,7 +146,7 @@ func (ClientState) VerifyClientState( store storetypes.KVStore, cdc codec.BinaryCodec, _ exported.Height, _ exported.Prefix, _ string, _ []byte, clientState exported.ClientState, ) error { - panic("legacy solo machine is deprecated!") + panic(errors.New("legacy solo machine is deprecated")) } // VerifyClientConsensusState panics! @@ -153,7 +155,7 @@ func (ClientState) VerifyClientConsensusState( exported.Height, string, exported.Height, exported.Prefix, []byte, exported.ConsensusState, ) error { - panic("legacy solo machine is deprecated!") + panic(errors.New("legacy solo machine is deprecated")) } // VerifyConnectionState panics! @@ -161,7 +163,7 @@ func (ClientState) VerifyConnectionState( storetypes.KVStore, codec.BinaryCodec, exported.Height, exported.Prefix, []byte, string, exported.ConnectionI, ) error { - panic("legacy solo machine is deprecated!") + panic(errors.New("legacy solo machine is deprecated")) } // VerifyChannelState panics! @@ -169,7 +171,7 @@ func (ClientState) VerifyChannelState( storetypes.KVStore, codec.BinaryCodec, exported.Height, exported.Prefix, []byte, string, string, exported.ChannelI, ) error { - panic("legacy solo machine is deprecated!") + panic(errors.New("legacy solo machine is deprecated")) } // VerifyPacketCommitment panics! @@ -178,7 +180,7 @@ func (ClientState) VerifyPacketCommitment( uint64, uint64, exported.Prefix, []byte, string, string, uint64, []byte, ) error { - panic("legacy solo machine is deprecated!") + panic(errors.New("legacy solo machine is deprecated")) } // VerifyPacketAcknowledgement panics! @@ -187,7 +189,7 @@ func (ClientState) VerifyPacketAcknowledgement( uint64, uint64, exported.Prefix, []byte, string, string, uint64, []byte, ) error { - panic("legacy solo machine is deprecated!") + panic(errors.New("legacy solo machine is deprecated")) } // VerifyPacketReceiptAbsence panics! @@ -196,7 +198,7 @@ func (ClientState) VerifyPacketReceiptAbsence( uint64, uint64, exported.Prefix, []byte, string, string, uint64, ) error { - panic("legacy solo machine is deprecated!") + panic(errors.New("legacy solo machine is deprecated")) } // VerifyNextSequenceRecv panics! @@ -205,14 +207,14 @@ func (ClientState) VerifyNextSequenceRecv( uint64, uint64, exported.Prefix, []byte, string, string, uint64, ) error { - panic("legacy solo machine is deprecated!") + panic(errors.New("legacy solo machine is deprecated")) } // GetTimestampAtHeight panics! func (ClientState) GetTimestampAtHeight( sdk.Context, storetypes.KVStore, codec.BinaryCodec, exported.Height, ) (uint64, error) { - panic("legacy solo machine is deprecated!") + panic(errors.New("legacy solo machine is deprecated")) } // VerifyMembership panics! @@ -227,7 +229,7 @@ func (*ClientState) VerifyMembership( path exported.Path, value []byte, ) error { - panic("legacy solo machine is deprecated!") + panic(errors.New("legacy solo machine is deprecated")) } // VerifyNonMembership panics! @@ -241,20 +243,20 @@ func (*ClientState) VerifyNonMembership( proof []byte, path exported.Path, ) error { - panic("legacy solo machine is deprecated") + panic(errors.New("legacy solo machine is deprecated")) } // ClientType panics! func (ConsensusState) ClientType() string { - panic("legacy solo machine is deprecated!") + panic(errors.New("legacy solo machine is deprecated")) } // GetTimestamp panics! func (ConsensusState) GetTimestamp() uint64 { - panic("legacy solo machine is deprecated!") + panic(errors.New("legacy solo machine is deprecated")) } // ValidateBasic panics! func (ConsensusState) ValidateBasic() error { - panic("legacy solo machine is deprecated!") + panic(errors.New("legacy solo machine is deprecated")) } diff --git a/modules/core/02-client/types/height.go b/modules/core/02-client/types/height.go index 104f6020fe1..ca75a1e7ff1 100644 --- a/modules/core/02-client/types/height.go +++ b/modules/core/02-client/types/height.go @@ -56,7 +56,7 @@ func (h Height) GetRevisionHeight() uint64 { func (h Height) Compare(other exported.Height) int64 { height, ok := other.(Height) if !ok { - panic(fmt.Sprintf("cannot compare against invalid height type: %T. expected height type: %T", other, h)) + panic(fmt.Errorf("cannot compare against invalid height type: %T. expected height type: %T", other, h)) } var a, b big.Int if h.RevisionNumber != height.RevisionNumber { @@ -178,7 +178,7 @@ func ParseChainID(chainID string) uint64 { revision, err := strconv.ParseUint(splitStr[len(splitStr)-1], 10, 64) // sanity check: error should always be nil since regex only allows numbers in last element if err != nil { - panic(fmt.Sprintf("regex allowed non-number value as last split element for chainID: %s", chainID)) + panic(fmt.Errorf("regex allowed non-number value as last split element for chainID: %s", chainID)) } return revision } diff --git a/modules/core/03-connection/keeper/keeper.go b/modules/core/03-connection/keeper/keeper.go index e56de3558ef..d6621a52473 100644 --- a/modules/core/03-connection/keeper/keeper.go +++ b/modules/core/03-connection/keeper/keeper.go @@ -1,6 +1,8 @@ package keeper import ( + "errors" + errorsmod "cosmossdk.io/errors" "cosmossdk.io/log" storetypes "cosmossdk.io/store/types" @@ -136,7 +138,7 @@ func (k Keeper) GetNextConnectionSequence(ctx sdk.Context) uint64 { store := ctx.KVStore(k.storeKey) bz := store.Get([]byte(types.KeyNextConnectionSequence)) if len(bz) == 0 { - panic("next connection sequence is nil") + panic(errors.New("next connection sequence is nil")) } return sdk.BigEndianToUint64(bz) @@ -228,7 +230,7 @@ func (k Keeper) GetParams(ctx sdk.Context) types.Params { store := ctx.KVStore(k.storeKey) bz := store.Get([]byte(types.ParamsKey)) if bz == nil { // only panic on unset params and not on empty params - panic("connection params are not set in store") + panic(errors.New("connection params are not set in store")) } var params types.Params diff --git a/modules/core/04-channel/keeper/handshake.go b/modules/core/04-channel/keeper/handshake.go index 6e48f7048f3..30420a67270 100644 --- a/modules/core/04-channel/keeper/handshake.go +++ b/modules/core/04-channel/keeper/handshake.go @@ -275,7 +275,7 @@ func (k Keeper) WriteOpenAckChannel( ) { channel, found := k.GetChannel(ctx, portID, channelID) if !found { - panic(fmt.Sprintf("could not find existing channel when updating channel state in successful ChanOpenAck step, channelID: %s, portID: %s", channelID, portID)) + panic(fmt.Errorf("could not find existing channel when updating channel state in successful ChanOpenAck step, channelID: %s, portID: %s", channelID, portID)) } channel.State = types.OPEN @@ -351,7 +351,7 @@ func (k Keeper) WriteOpenConfirmChannel( ) { channel, found := k.GetChannel(ctx, portID, channelID) if !found { - panic(fmt.Sprintf("could not find existing channel when updating channel state in successful ChanOpenConfirm step, channelID: %s, portID: %s", channelID, portID)) + panic(fmt.Errorf("could not find existing channel when updating channel state in successful ChanOpenConfirm step, channelID: %s, portID: %s", channelID, portID)) } channel.State = types.OPEN diff --git a/modules/core/04-channel/keeper/keeper.go b/modules/core/04-channel/keeper/keeper.go index 1373f8ce73c..f285839799a 100644 --- a/modules/core/04-channel/keeper/keeper.go +++ b/modules/core/04-channel/keeper/keeper.go @@ -1,6 +1,7 @@ package keeper import ( + "errors" "strconv" "strings" @@ -109,7 +110,7 @@ func (k Keeper) GetNextChannelSequence(ctx sdk.Context) uint64 { store := ctx.KVStore(k.storeKey) bz := store.Get([]byte(types.KeyNextChannelSequence)) if len(bz) == 0 { - panic("next channel sequence is nil") + panic(errors.New("next channel sequence is nil")) } return sdk.BigEndianToUint64(bz) diff --git a/modules/core/05-port/keeper/keeper.go b/modules/core/05-port/keeper/keeper.go index 37e357e4023..68e89ecac69 100644 --- a/modules/core/05-port/keeper/keeper.go +++ b/modules/core/05-port/keeper/keeper.go @@ -48,7 +48,7 @@ func (k *Keeper) BindPort(ctx sdk.Context, portID string) *capabilitytypes.Capab } if k.IsBound(ctx, portID) { - panic(fmt.Sprintf("port %s is already bound", portID)) + panic(fmt.Errorf("port %s is already bound", portID)) } key, err := k.scopedKeeper.NewCapability(ctx, host.PortPath(portID)) diff --git a/modules/core/05-port/types/router.go b/modules/core/05-port/types/router.go index 6bfba9076ab..b66999644f5 100644 --- a/modules/core/05-port/types/router.go +++ b/modules/core/05-port/types/router.go @@ -1,6 +1,7 @@ package types import ( + "errors" "fmt" sdk "github.com/cosmos/cosmos-sdk/types" @@ -23,7 +24,7 @@ func NewRouter() *Router { // Seal will panic if called more than once. func (rtr *Router) Seal() { if rtr.sealed { - panic("router already sealed") + panic(errors.New("router already sealed")) } rtr.sealed = true } @@ -37,13 +38,13 @@ func (rtr Router) Sealed() bool { // so AddRoute calls can be linked. It will panic if the Router is sealed. func (rtr *Router) AddRoute(module string, cbs IBCModule) *Router { if rtr.sealed { - panic(fmt.Sprintf("router sealed; cannot register %s route callbacks", module)) + panic(fmt.Errorf("router sealed; cannot register %s route callbacks", module)) } if !sdk.IsAlphaNumeric(module) { - panic("route expressions can only contain alphanumeric characters") + panic(errors.New("route expressions can only contain alphanumeric characters")) } if rtr.HasRoute(module) { - panic(fmt.Sprintf("route %s has already been registered", module)) + panic(fmt.Errorf("route %s has already been registered", module)) } rtr.routes[module] = cbs diff --git a/modules/core/05-port/types/utils.go b/modules/core/05-port/types/utils.go index a12f2ef7f52..f3c51d3bdf3 100644 --- a/modules/core/05-port/types/utils.go +++ b/modules/core/05-port/types/utils.go @@ -7,7 +7,7 @@ import "fmt" // only allow one module to be bound to a port at any given time func GetModuleOwner(modules []string) string { if len(modules) != 2 { - panic(fmt.Sprintf("capability should only be owned by port or channel owner and ibc module, multiple owners currently not supported, owners: %v", modules)) + panic(fmt.Errorf("capability should only be owned by port or channel owner and ibc module, multiple owners currently not supported, owners: %v", modules)) } if modules[0] == "ibc" { diff --git a/modules/core/keeper/keeper.go b/modules/core/keeper/keeper.go index cebfb159f54..1b9bcb14de8 100644 --- a/modules/core/keeper/keeper.go +++ b/modules/core/keeper/keeper.go @@ -1,7 +1,7 @@ package keeper import ( - "fmt" + "errors" "reflect" "strings" @@ -55,18 +55,18 @@ func NewKeeper( // panic if any of the keepers passed in is empty if isEmpty(stakingKeeper) { - panic(fmt.Errorf("cannot initialize IBC keeper: empty staking keeper")) + panic(errors.New("cannot initialize IBC keeper: empty staking keeper")) } if isEmpty(upgradeKeeper) { - panic(fmt.Errorf("cannot initialize IBC keeper: empty upgrade keeper")) + panic(errors.New("cannot initialize IBC keeper: empty upgrade keeper")) } if reflect.DeepEqual(capabilitykeeper.ScopedKeeper{}, scopedKeeper) { - panic(fmt.Errorf("cannot initialize IBC keeper: empty scoped keeper")) + panic(errors.New("cannot initialize IBC keeper: empty scoped keeper")) } if strings.TrimSpace(authority) == "" { - panic(fmt.Errorf("authority must be non-empty")) + panic(errors.New("authority must be non-empty")) } clientKeeper := clientkeeper.NewKeeper(cdc, key, paramSpace, stakingKeeper, upgradeKeeper) @@ -93,7 +93,7 @@ func (k Keeper) Codec() codec.BinaryCodec { // there is an existing router that's already sealed. func (k *Keeper) SetRouter(rtr *porttypes.Router) { if k.Router != nil && k.Router.Sealed() { - panic("cannot reset a sealed router") + panic(errors.New("cannot reset a sealed router")) } k.PortKeeper.Router = rtr diff --git a/modules/core/module.go b/modules/core/module.go index 7878e4b8fed..27edd09a143 100644 --- a/modules/core/module.go +++ b/modules/core/module.go @@ -165,7 +165,7 @@ func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, bz json.Ra var gs types.GenesisState err := cdc.UnmarshalJSON(bz, &gs) if err != nil { - panic(fmt.Sprintf("failed to unmarshal %s genesis state: %s", exported.ModuleName, err)) + panic(fmt.Errorf("failed to unmarshal %s genesis state: %s", exported.ModuleName, err)) } InitGenesis(ctx, *am.keeper, &gs) } diff --git a/modules/core/simulation/decoder.go b/modules/core/simulation/decoder.go index 4f707df0836..0f9a0c7f346 100644 --- a/modules/core/simulation/decoder.go +++ b/modules/core/simulation/decoder.go @@ -28,6 +28,6 @@ func NewDecodeStore(k keeper.Keeper) func(kvA, kvB kv.Pair) string { return res } - panic(fmt.Sprintf("invalid %s key prefix: %s", ibcexported.ModuleName, string(kvA.Key))) + panic(fmt.Errorf("invalid %s key prefix: %s", ibcexported.ModuleName, string(kvA.Key))) } } diff --git a/modules/light-clients/06-solomachine/client_state.go b/modules/light-clients/06-solomachine/client_state.go index 34e439607cd..2f5ec308b3e 100644 --- a/modules/light-clients/06-solomachine/client_state.go +++ b/modules/light-clients/06-solomachine/client_state.go @@ -1,6 +1,7 @@ package solomachine import ( + "errors" "reflect" errorsmod "cosmossdk.io/errors" @@ -76,7 +77,7 @@ func (cs ClientState) Validate() error { // ZeroCustomFields is not implemented for solo machine func (ClientState) ZeroCustomFields() exported.ClientState { - panic("ZeroCustomFields is not implemented as the solo machine implementation does not support upgrades.") + panic(errors.New("ZeroCustomFields is not implemented as the solo machine implementation does not support upgrades")) } // Initialize checks that the initial consensus state is equal to the latest consensus state of the initial client and diff --git a/testing/simapp/export.go b/testing/simapp/export.go index 4613465dc09..26438874ac8 100644 --- a/testing/simapp/export.go +++ b/testing/simapp/export.go @@ -2,6 +2,7 @@ package simapp import ( "encoding/json" + "errors" "log" storetypes "cosmossdk.io/store/types" @@ -209,7 +210,7 @@ func (app *SimApp) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs [] addr := sdk.ValAddress(stakingtypes.AddressFromValidatorsKey(iter.Key())) validator, err := app.StakingKeeper.GetValidator(ctx, addr) if err != nil { - panic("expected validator, not found") + panic(errors.New("expected validator, not found")) } validator.UnbondingHeight = 0 @@ -219,7 +220,7 @@ func (app *SimApp) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs [] err = app.StakingKeeper.SetValidator(ctx, validator) if err != nil { - panic("couldn't set validator") + panic(errors.New("couldn't set validator")) } counter++ }