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

nit: panic with error #4741

Merged
merged 12 commits into from
Sep 22, 2023
2 changes: 1 addition & 1 deletion e2e/relayer/relayer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
}

Expand Down
2 changes: 1 addition & 1 deletion e2e/testsuite/testsuite.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,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(fmt.Errorf("cannot start relayer before it is created!"))
}

s.startRelayerFn(ibcrelayer)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package controller

import (
"fmt"

errorsmod "cosmossdk.io/errors"

sdk "github.com/cosmos/cosmos-sdk/types"
Expand Down Expand Up @@ -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(fmt.Errorf("SendPacket not supported for ICA controller module. Please use SendTx"))
}

// WriteAcknowledgement implements the ICS4 Wrapper interface
Expand All @@ -249,7 +251,7 @@ func (IBCMiddleware) WriteAcknowledgement(
packet ibcexported.PacketI,
ack ibcexported.Acknowledgement,
) error {
panic("WriteAcknowledgement not supported for ICA controller module")
panic(fmt.Errorf("WriteAcknowledgement not supported for ICA controller module"))
}

// GetAppVersion returns the interchain accounts metadata.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,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(fmt.Errorf("ica/controller params are not set in store"))
}

var params types.Params
Expand Down
4 changes: 2 additions & 2 deletions modules/apps/27-interchain-accounts/host/keeper/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
}

Expand All @@ -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)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions modules/apps/27-interchain-accounts/host/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,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(fmt.Errorf("the Interchain Accounts module account has not been set"))
}

// set KeyTable if it has not already been set
Expand Down Expand Up @@ -243,7 +243,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(fmt.Errorf("ica/host params are not set in store"))
}

var params types.Params
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions modules/apps/27-interchain-accounts/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -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)
Expand All @@ -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))
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
}
}
4 changes: 2 additions & 2 deletions modules/apps/29-fee/keeper/escrow.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion modules/apps/callbacks/callbacks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,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(fmt.Errorf("chain is not a simapp.SimApp"))
}
return app
}
Expand Down
4 changes: 2 additions & 2 deletions modules/apps/callbacks/ibc_middleware_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -826,7 +826,7 @@ func (s *CallbacksTestSuite) TestProcessCallback() {
func() {
callbackExecutor = func(cachedCtx sdk.Context) error {
cachedCtx.GasMeter().ConsumeGas(expGasConsumed, "callbackExecutor gas consumption")
panic("callbackExecutor panic")
panic(fmt.Errorf("callbackExecutor panic"))
}
},
false,
Expand Down Expand Up @@ -862,7 +862,7 @@ func (s *CallbacksTestSuite) TestProcessCallback() {
callbackType = types.CallbackTypeSendPacket
callbackExecutor = func(cachedCtx sdk.Context) error {
cachedCtx.GasMeter().ConsumeGas(expGasConsumed, "callbackExecutor gas consumption")
panic("callbackExecutor panic")
panic(fmt.Errorf("callbackExecutor panic"))
}
},
true,
Expand Down
5 changes: 3 additions & 2 deletions modules/apps/callbacks/testing/simapp/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package simapp

import (
"encoding/json"
"fmt"
"log"

storetypes "cosmossdk.io/store/types"
Expand Down Expand Up @@ -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(fmt.Errorf("expected validator, not found"))
}

validator.UnbondingHeight = 0
Expand All @@ -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(fmt.Errorf("couldn't set validator"))
}
counter++
}
Expand Down
2 changes: 1 addition & 1 deletion modules/apps/transfer/keeper/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
}

Expand Down
6 changes: 3 additions & 3 deletions modules/apps/transfer/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,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(fmt.Errorf("the IBC transfer module account has not been set"))
}
// set KeyTable if it has not already been set
if !legacySubspace.HasKeyTable() {
Expand Down Expand Up @@ -128,7 +128,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(fmt.Errorf("transfer params are not set in store"))
}

var params types.Params
Expand Down Expand Up @@ -239,7 +239,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)
Expand Down
8 changes: 4 additions & 4 deletions modules/apps/transfer/keeper/mbt_relay_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,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(fmt.Errorf("failed to convert from TLA+ address: wrong number of address components"))
}
s := ""
if len(addr[0]) == 0 && len(addr[1]) == 0 { //nolint:gocritic
Expand All @@ -109,7 +109,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(fmt.Errorf("failed to convert from TLA+ address: neither simple nor escrow address"))
}
return s
}
Expand Down Expand Up @@ -333,7 +333,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(fmt.Errorf("MBT failed to convert sender address"))
}
registerDenomFn()
denomTrace := types.ParseDenomTrace(tc.packet.Data.Denom)
Expand All @@ -342,7 +342,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(fmt.Errorf("MBT failed to parse amount from string"))
}
msg := types.NewMsgTransfer(
tc.packet.SourcePort,
Expand Down
2 changes: 1 addition & 1 deletion modules/apps/transfer/keeper/migrations.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions modules/apps/transfer/keeper/relay.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
}

Expand Down Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions modules/apps/transfer/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
}

Expand Down
2 changes: 1 addition & 1 deletion modules/apps/transfer/simulation/decoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -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]))
}
}
}
Loading
Loading