Skip to content

Commit

Permalink
refactor(all): refactor errors import to use cosmossdk.io pkg (#1080)
Browse files Browse the repository at this point in the history
refactor (errors) refactor errors import to use cosmossdk.io instead of cosmos-sdk/types/errors
  • Loading branch information
GAtom22 committed Nov 14, 2022
1 parent c01357c commit 31fd2a8
Show file tree
Hide file tree
Showing 40 changed files with 227 additions and 227 deletions.
6 changes: 3 additions & 3 deletions app/ante/ante.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package ante

import (
sdkerrors "cosmossdk.io/errors"
errorsmod "cosmossdk.io/errors"
sdk "github.com/cosmos/cosmos-sdk/types"
errortypes "github.com/cosmos/cosmos-sdk/types/errors"
authante "github.com/cosmos/cosmos-sdk/x/auth/ante"
Expand Down Expand Up @@ -33,7 +33,7 @@ func NewAnteHandler(options HandlerOptions) sdk.AnteHandler {
// handle as normal Cosmos SDK tx, except signature is checked for EIP712 representation
anteHandler = newCosmosAnteHandlerEip712(options)
default:
return ctx, sdkerrors.Wrapf(
return ctx, errorsmod.Wrapf(
errortypes.ErrUnknownExtensionOptions,
"rejecting tx with unsupported extension option: %s", typeURL,
)
Expand All @@ -48,7 +48,7 @@ func NewAnteHandler(options HandlerOptions) sdk.AnteHandler {
case sdk.Tx:
anteHandler = newCosmosAnteHandler(options)
default:
return ctx, sdkerrors.Wrapf(errortypes.ErrUnknownRequest, "invalid transaction type: %T", tx)
return ctx, errorsmod.Wrapf(errortypes.ErrUnknownRequest, "invalid transaction type: %T", tx)
}

return anteHandler(ctx, tx, sim)
Expand Down
14 changes: 7 additions & 7 deletions app/ante/handler_options.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package ante

import (
sdkerrors "cosmossdk.io/errors"
errorsmod "cosmossdk.io/errors"
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
errortypes "github.com/cosmos/cosmos-sdk/types/errors"
Expand Down Expand Up @@ -39,22 +39,22 @@ type HandlerOptions struct {
// Validate checks if the keepers are defined
func (options HandlerOptions) Validate() error {
if options.AccountKeeper == nil {
return sdkerrors.Wrap(errortypes.ErrLogic, "account keeper is required for AnteHandler")
return errorsmod.Wrap(errortypes.ErrLogic, "account keeper is required for AnteHandler")
}
if options.BankKeeper == nil {
return sdkerrors.Wrap(errortypes.ErrLogic, "bank keeper is required for AnteHandler")
return errorsmod.Wrap(errortypes.ErrLogic, "bank keeper is required for AnteHandler")
}
if options.StakingKeeper == nil {
return sdkerrors.Wrap(errortypes.ErrLogic, "staking keeper is required for AnteHandler")
return errorsmod.Wrap(errortypes.ErrLogic, "staking keeper is required for AnteHandler")
}
if options.SignModeHandler == nil {
return sdkerrors.Wrap(errortypes.ErrLogic, "sign mode handler is required for ante builder")
return errorsmod.Wrap(errortypes.ErrLogic, "sign mode handler is required for ante builder")
}
if options.FeeMarketKeeper == nil {
return sdkerrors.Wrap(errortypes.ErrLogic, "fee market keeper is required for AnteHandler")
return errorsmod.Wrap(errortypes.ErrLogic, "fee market keeper is required for AnteHandler")
}
if options.EvmKeeper == nil {
return sdkerrors.Wrap(errortypes.ErrLogic, "evm keeper is required for AnteHandler")
return errorsmod.Wrap(errortypes.ErrLogic, "evm keeper is required for AnteHandler")
}
return nil
}
Expand Down
18 changes: 9 additions & 9 deletions app/ante/vesting.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"

sdkerrors "cosmossdk.io/errors"
errorsmod "cosmossdk.io/errors"
errortypes "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/cosmos/cosmos-sdk/x/authz"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
Expand Down Expand Up @@ -37,14 +37,14 @@ func (vtd EthVestingTransactionDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx,
for _, msg := range tx.GetMsgs() {
msgEthTx, ok := msg.(*evmtypes.MsgEthereumTx)
if !ok {
return ctx, sdkerrors.Wrapf(errortypes.ErrUnknownRequest,
return ctx, errorsmod.Wrapf(errortypes.ErrUnknownRequest,
"invalid message type %T, expected %T", msg, (*evmtypes.MsgEthereumTx)(nil),
)
}

acc := vtd.ak.GetAccount(ctx, msgEthTx.GetFrom())
if acc == nil {
return ctx, sdkerrors.Wrapf(errortypes.ErrUnknownAddress,
return ctx, errorsmod.Wrapf(errortypes.ErrUnknownAddress,
"account %s does not exist", acc)
}

Expand All @@ -59,15 +59,15 @@ func (vtd EthVestingTransactionDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx,
// grant while there are already vested coins on the account.
vested := clawbackAccount.GetVestedCoins(ctx.BlockTime())
if len(vested) == 0 {
return ctx, sdkerrors.Wrapf(vestingtypes.ErrInsufficientVestedCoins,
return ctx, errorsmod.Wrapf(vestingtypes.ErrInsufficientVestedCoins,
"cannot perform Ethereum tx with clawback vesting account, that has no vested coins: %s", vested,
)
}

// Error if account has locked coins (before surpassing all lockup periods)
islocked := clawbackAccount.HasLockedCoins(ctx.BlockTime())
if islocked {
return ctx, sdkerrors.Wrapf(vestingtypes.ErrVestingLockup,
return ctx, errorsmod.Wrapf(vestingtypes.ErrVestingLockup,
"cannot perform Ethereum tx with clawback vesting account, that has locked coins: %s", vested,
)
}
Expand Down Expand Up @@ -120,7 +120,7 @@ func (vdd VestingDelegationDecorator) validateAuthz(ctx sdk.Context, execMsg *au
for _, v := range execMsg.Msgs {
var innerMsg sdk.Msg
if err := vdd.cdc.UnpackAny(v, &innerMsg); err != nil {
return sdkerrors.Wrap(err, "cannot unmarshal authz exec msgs")
return errorsmod.Wrap(err, "cannot unmarshal authz exec msgs")
}

if err := vdd.validateMsg(ctx, innerMsg); err != nil {
Expand All @@ -141,7 +141,7 @@ func (vdd VestingDelegationDecorator) validateMsg(ctx sdk.Context, msg sdk.Msg)
for _, addr := range msg.GetSigners() {
acc := vdd.ak.GetAccount(ctx, addr)
if acc == nil {
return sdkerrors.Wrapf(
return errorsmod.Wrapf(
errortypes.ErrUnknownAddress,
"account %s does not exist", addr,
)
Expand All @@ -157,15 +157,15 @@ func (vdd VestingDelegationDecorator) validateMsg(ctx sdk.Context, msg sdk.Msg)
bondDenom := vdd.sk.BondDenom(ctx)
coins := clawbackAccount.GetVestedOnly(ctx.BlockTime())
if coins == nil || coins.Empty() {
return sdkerrors.Wrap(
return errorsmod.Wrap(
vestingtypes.ErrInsufficientVestedCoins,
"account has no vested coins",
)
}

vested := coins.AmountOf(bondDenom)
if vested.LT(delegateMsg.Amount.Amount) {
return sdkerrors.Wrapf(
return errorsmod.Wrapf(
vestingtypes.ErrInsufficientVestedCoins,
"cannot delegate unvested coins. coins vested < delegation amount (%s < %s)",
vested, delegateMsg.Amount.Amount,
Expand Down
6 changes: 3 additions & 3 deletions app/sigverify.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package app
import (
"fmt"

sdkerrors "cosmossdk.io/errors"
errorsmod "cosmossdk.io/errors"
"github.com/cosmos/cosmos-sdk/crypto/keys/ed25519"
"github.com/cosmos/cosmos-sdk/crypto/types/multisig"
sdk "github.com/cosmos/cosmos-sdk/types"
Expand Down Expand Up @@ -44,7 +44,7 @@ func SigVerificationGasConsumer(
case *ed25519.PubKey:
// Validator keys
meter.ConsumeGas(params.SigVerifyCostED25519, "ante verify: ed25519")
return sdkerrors.Wrap(errortypes.ErrInvalidPubKey, "ED25519 public keys are unsupported")
return errorsmod.Wrap(errortypes.ErrInvalidPubKey, "ED25519 public keys are unsupported")

case multisig.PubKey:
// Multisig keys
Expand All @@ -55,7 +55,7 @@ func SigVerificationGasConsumer(
return ConsumeMultisignatureVerificationGas(meter, multisignature, pubkey, params, sig.Sequence)

default:
return sdkerrors.Wrapf(errortypes.ErrInvalidPubKey, "unrecognized/unsupported public key type: %T", pubkey)
return errorsmod.Wrapf(errortypes.ErrInvalidPubKey, "unrecognized/unsupported public key type: %T", pubkey)
}
}

Expand Down
14 changes: 7 additions & 7 deletions ibc/utils.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package ibc

import (
sdkerrors "cosmossdk.io/errors"
errorsmod "cosmossdk.io/errors"
sdk "github.com/cosmos/cosmos-sdk/types"
errortypes "github.com/cosmos/cosmos-sdk/types/errors"

Expand All @@ -25,21 +25,21 @@ func GetTransferSenderRecipient(packet channeltypes.Packet) (
// unmarshal packet data to obtain the sender and recipient
var data transfertypes.FungibleTokenPacketData
if err := transfertypes.ModuleCdc.UnmarshalJSON(packet.GetData(), &data); err != nil {
return nil, nil, "", "", sdkerrors.Wrapf(errortypes.ErrUnknownRequest, "cannot unmarshal ICS-20 transfer packet data")
return nil, nil, "", "", errorsmod.Wrapf(errortypes.ErrUnknownRequest, "cannot unmarshal ICS-20 transfer packet data")
}

// validate the sender bech32 address from the counterparty chain
// and change the bech32 human readable prefix (HRP) of the sender to `evmos`
sender, err = evmos.GetEvmosAddressFromBech32(data.Sender)
if err != nil {
return nil, nil, "", "", sdkerrors.Wrap(err, "invalid sender")
return nil, nil, "", "", errorsmod.Wrap(err, "invalid sender")
}

// validate the recipient bech32 address from the counterparty chain
// and change the bech32 human readable prefix (HRP) of the recipient to `evmos`
recipient, err = evmos.GetEvmosAddressFromBech32(data.Receiver)
if err != nil {
return nil, nil, "", "", sdkerrors.Wrap(err, "invalid recipient")
return nil, nil, "", "", errorsmod.Wrap(err, "invalid recipient")
}

return sender, recipient, data.Sender, data.Receiver, nil
Expand All @@ -50,15 +50,15 @@ func GetTransferAmount(packet channeltypes.Packet) (string, error) {
// unmarshal packet data to obtain the sender and recipient
var data transfertypes.FungibleTokenPacketData
if err := transfertypes.ModuleCdc.UnmarshalJSON(packet.GetData(), &data); err != nil {
return "", sdkerrors.Wrapf(errortypes.ErrUnknownRequest, "cannot unmarshal ICS-20 transfer packet data")
return "", errorsmod.Wrapf(errortypes.ErrUnknownRequest, "cannot unmarshal ICS-20 transfer packet data")
}

if data.Amount == "" {
return "", sdkerrors.Wrapf(errortypes.ErrInvalidCoins, "empty amount")
return "", errorsmod.Wrapf(errortypes.ErrInvalidCoins, "empty amount")
}

if _, ok := sdk.NewIntFromString(data.Amount); !ok {
return "", sdkerrors.Wrapf(errortypes.ErrInvalidCoins, "invalid amount")
return "", errorsmod.Wrapf(errortypes.ErrInvalidCoins, "invalid amount")
}

return data.Amount, nil
Expand Down
6 changes: 3 additions & 3 deletions testutil/integration.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package testutil
import (
"strconv"

sdkerrors "cosmossdk.io/errors"
errorsmod "cosmossdk.io/errors"
"github.com/cosmos/cosmos-sdk/client/tx"
sdk "github.com/cosmos/cosmos-sdk/types"
errortypes "github.com/cosmos/cosmos-sdk/types/errors"
Expand Down Expand Up @@ -45,7 +45,7 @@ func SubmitProposal(

submitEvent := res.GetEvents()[eventNum]
if submitEvent.Type != "submit_proposal" || string(submitEvent.Attributes[0].Key) != "proposal_id" {
return id, sdkerrors.Wrapf(sdkerrors.Error{}, "eventNumber %d in SubmitProposal calls %s instead of submit_proposal", eventNum, submitEvent.Type)
return id, errorsmod.Wrapf(errorsmod.Error{}, "eventNumber %d in SubmitProposal calls %s instead of submit_proposal", eventNum, submitEvent.Type)
}

return strconv.ParseUint(string(submitEvent.Attributes[0].Value), 10, 64)
Expand Down Expand Up @@ -155,7 +155,7 @@ func DeliverTx(
req := abci.RequestDeliverTx{Tx: bz}
res := appEvmos.BaseApp.DeliverTx(req)
if res.Code != 0 {
return abci.ResponseDeliverTx{}, sdkerrors.Wrapf(errortypes.ErrInvalidRequest, res.Log)
return abci.ResponseDeliverTx{}, errorsmod.Wrapf(errortypes.ErrInvalidRequest, res.Log)
}

return res, nil
Expand Down
4 changes: 2 additions & 2 deletions types/errors.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package types

import (
sdkerrors "cosmossdk.io/errors"
errorsmod "cosmossdk.io/errors"
)

// RootCodespace is the codespace for all errors defined in this package
Expand All @@ -14,5 +14,5 @@ const (

// errors
var (
ErrKeyTypeNotSupported = sdkerrors.Register(RootCodespace, codeKeyTypeNotSupported, "key type 'secp256k1' not supported")
ErrKeyTypeNotSupported = errorsmod.Register(RootCodespace, codeKeyTypeNotSupported, "key type 'secp256k1' not supported")
)
6 changes: 3 additions & 3 deletions types/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (

"github.com/evmos/ethermint/crypto/ethsecp256k1"

sdkerrors "cosmossdk.io/errors"
errorsmod "cosmossdk.io/errors"
"github.com/cosmos/cosmos-sdk/crypto/keys/ed25519"
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
"github.com/cosmos/cosmos-sdk/crypto/types/multisig"
Expand Down Expand Up @@ -65,12 +65,12 @@ func IsSupportedKey(pubkey cryptotypes.PubKey) bool {
func GetEvmosAddressFromBech32(address string) (sdk.AccAddress, error) {
bech32Prefix := strings.SplitN(address, "1", 2)[0]
if bech32Prefix == address {
return nil, sdkerrors.Wrapf(errortypes.ErrInvalidAddress, "invalid bech32 address: %s", address)
return nil, errorsmod.Wrapf(errortypes.ErrInvalidAddress, "invalid bech32 address: %s", address)
}

addressBz, err := sdk.GetFromBech32(address, bech32Prefix)
if err != nil {
return nil, sdkerrors.Wrapf(errortypes.ErrInvalidAddress, "invalid address %s, %s", address, err.Error())
return nil, errorsmod.Wrapf(errortypes.ErrInvalidAddress, "invalid address %s, %s", address, err.Error())
}

// safety check: shouldn't happen
Expand Down
4 changes: 2 additions & 2 deletions x/claims/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package claims
import (
"fmt"

sdkerrors "cosmossdk.io/errors"
errorsmod "cosmossdk.io/errors"
sdk "github.com/cosmos/cosmos-sdk/types"
errortypes "github.com/cosmos/cosmos-sdk/types/errors"

Expand All @@ -15,6 +15,6 @@ import (
func NewHandler(k keeper.Keeper) sdk.Handler {
return func(_ sdk.Context, msg sdk.Msg) (*sdk.Result, error) {
errMsg := fmt.Sprintf("unrecognized %s message type: %T", types.ModuleName, msg)
return nil, sdkerrors.Wrap(errortypes.ErrUnknownRequest, errMsg)
return nil, errorsmod.Wrap(errortypes.ErrUnknownRequest, errMsg)
}
}
4 changes: 2 additions & 2 deletions x/claims/keeper/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package keeper
import (
"strconv"

sdkerrors "cosmossdk.io/errors"
errorsmod "cosmossdk.io/errors"
sdk "github.com/cosmos/cosmos-sdk/types"
vestexported "github.com/cosmos/cosmos-sdk/x/auth/vesting/exported"
ethermint "github.com/evmos/ethermint/types"
Expand Down Expand Up @@ -68,7 +68,7 @@ func (k Keeper) ClawbackEscrowedTokens(ctx sdk.Context) error {
}

if err := k.distrKeeper.FundCommunityPool(ctx, balances, moduleAccAddr); err != nil {
return sdkerrors.Wrap(err, "failed to transfer escrowed airdrop tokens")
return errorsmod.Wrap(err, "failed to transfer escrowed airdrop tokens")
}

logger.Info(
Expand Down
6 changes: 3 additions & 3 deletions x/claims/keeper/claim.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package keeper

import (
sdkerrors "cosmossdk.io/errors"
errorsmod "cosmossdk.io/errors"
"cosmossdk.io/math"
sdk "github.com/cosmos/cosmos-sdk/types"
errortypes "github.com/cosmos/cosmos-sdk/types/errors"
Expand All @@ -19,7 +19,7 @@ func (k Keeper) ClaimCoinsForAction(
params types.Params,
) (math.Int, error) {
if action == types.ActionUnspecified || action > types.ActionIBCTransfer {
return sdk.ZeroInt(), sdkerrors.Wrapf(types.ErrInvalidAction, "%d", action)
return sdk.ZeroInt(), errorsmod.Wrapf(types.ErrInvalidAction, "%d", action)
}

// If we are before the start time, after end time, or claims are disabled, do nothing.
Expand Down Expand Up @@ -106,7 +106,7 @@ func (k Keeper) MergeClaimsRecords(
// - the sender is not an evmos address and can't claim vote, delegation or evm actions
// - the first attempt to perform an ibc callback from the senders account will merge/migrate the entire claims record
if senderClaimsRecord.HasClaimedAction(action) {
return types.ClaimsRecord{}, sdkerrors.Wrapf(errortypes.ErrNotSupported, "non-evmos sender must not have claimed action: %v", action)
return types.ClaimsRecord{}, errorsmod.Wrapf(errortypes.ErrNotSupported, "non-evmos sender must not have claimed action: %v", action)
}

recipientCompleted := recipientClaimsRecord.HasClaimedAction(action)
Expand Down
8 changes: 4 additions & 4 deletions x/claims/keeper/ibc_callbacks.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package keeper

import (
sdkerrors "cosmossdk.io/errors"
errorsmod "cosmossdk.io/errors"
sdk "github.com/cosmos/cosmos-sdk/types"
errortypes "github.com/cosmos/cosmos-sdk/types/errors"
transfertypes "github.com/cosmos/ibc-go/v5/modules/apps/transfer/types"
Expand Down Expand Up @@ -34,7 +34,7 @@ func (k Keeper) OnAcknowledgementPacket(

var ack channeltypes.Acknowledgement
if err := transfertypes.ModuleCdc.UnmarshalJSON(acknowledgement, &ack); err != nil {
return sdkerrors.Wrapf(errortypes.ErrUnknownRequest, "cannot unmarshal ICS-20 transfer packet acknowledgement: %v", err)
return errorsmod.Wrapf(errortypes.ErrUnknownRequest, "cannot unmarshal ICS-20 transfer packet acknowledgement: %v", err)
}

// no-op if the acknowledgement is an error ACK
Expand Down Expand Up @@ -94,7 +94,7 @@ func (k Keeper) OnRecvPacket(
// return error ACK for blocked sender and recipient addresses
if k.bankKeeper.BlockedAddr(sender) || k.bankKeeper.BlockedAddr(recipient) {
return channeltypes.NewErrorAcknowledgement(
sdkerrors.Wrapf(
errorsmod.Wrapf(
errortypes.ErrUnauthorized,
"sender (%s) or recipient (%s) address are in the deny list for sending and receiving transfers",
senderBech32, recipientBech32,
Expand Down Expand Up @@ -124,7 +124,7 @@ func (k Keeper) OnRecvPacket(
// secp256k1 key from sender/recipient has no claimed actions
// -> return error acknowledgement to prevent funds from getting stuck
return channeltypes.NewErrorAcknowledgement(
sdkerrors.Wrapf(
errorsmod.Wrapf(
evmos.ErrKeyTypeNotSupported, "receiver address %s is not a valid ethereum address", recipientBech32,
),
)
Expand Down
Loading

0 comments on commit 31fd2a8

Please sign in to comment.