diff --git a/Makefile b/Makefile index 3acaf68..0eca284 100644 --- a/Makefile +++ b/Makefile @@ -77,7 +77,7 @@ all: tools install lint ## govet: Run go vet. govet: @echo Running go vet... - @go vet ./... + @go vet $(shell go list ./... | grep -v '/api') ## govulncheck: Run govulncheck govulncheck: diff --git a/pkg/errors/critical.go b/pkg/errors/critical.go index 3e56266..6283125 100644 --- a/pkg/errors/critical.go +++ b/pkg/errors/critical.go @@ -3,17 +3,19 @@ package errors import ( "fmt" + + sdkerrors "cosmossdk.io/errors" ) const codespace = "MODULES-CRITICAL" -var ErrCritical = Register(codespace, 4, "the state of the blockchain is inconsistent or an invariant is broken") +var ErrCritical = sdkerrors.Register(codespace, 4, "the state of the blockchain is inconsistent or an invariant is broken") // Critical handles and/or returns an error in case a critical error has been encountered: // - Inconsistent state // - Broken invariant func Critical(description string) error { - return Wrap(ErrCritical, description) + return sdkerrors.Wrap(ErrCritical, description) } // Criticalf extends a critical error with additional information. diff --git a/pkg/errors/errors.go b/pkg/errors/errors.go deleted file mode 100644 index c5449b9..0000000 --- a/pkg/errors/errors.go +++ /dev/null @@ -1,166 +0,0 @@ -// Package errors aliases both the `cosmos-sdk/types/errors.go` and `cosmossdk.io/errors` packages -// to give access to cosmos-sdk error definitions and functions with a single import path. -package errors - -import ( - sdkerrors "cosmossdk.io/errors" -) - -// Type Aliases to sdk errors module -var ( - SuccessABCICode = sdkerrors.SuccessABCICode - ABCIInfo = sdkerrors.ABCIInfo - UndefinedCodespace = sdkerrors.UndefinedCodespace - Register = sdkerrors.Register - ABCIError = sdkerrors.ABCIError - New = sdkerrors.New - Wrap = sdkerrors.Wrap - Wrapf = sdkerrors.Wrapf - Recover = sdkerrors.Recover - WithType = sdkerrors.WithType - IsOf = sdkerrors.IsOf - AssertNil = sdkerrors.AssertNil -) - -// Error type alias for errorsmod.Error -type Error = sdkerrors.Error - -// Codespace is the codespace for all errors defined in this package -const Codespace = "ignite-modules" - -var ( - // ErrTxDecode is returned if we cannot parse a transaction - ErrTxDecode = Register(Codespace, 2, "tx parse error") - - // ErrInvalidSequence is used the sequence number (nonce) is incorrect - // for the signature - ErrInvalidSequence = Register(Codespace, 3, "invalid sequence") - - // ErrUnauthorized is used whenever a request without sufficient - // authorization is handled. - ErrUnauthorized = Register(Codespace, 4, "unauthorized") - - // ErrInsufficientFunds is used when the account cannot pay requested amount. - ErrInsufficientFunds = Register(Codespace, 5, "insufficient funds") - - // ErrUnknownRequest to doc - ErrUnknownRequest = Register(Codespace, 6, "unknown request") - - // ErrInvalidAddress to doc - ErrInvalidAddress = Register(Codespace, 7, "invalid address") - - // ErrInvalidPubKey to doc - ErrInvalidPubKey = Register(Codespace, 8, "invalid pubkey") - - // ErrUnknownAddress to doc - ErrUnknownAddress = Register(Codespace, 9, "unknown address") - - // ErrInvalidCoins to doc - ErrInvalidCoins = Register(Codespace, 10, "invalid coins") - - // ErrOutOfGas to doc - ErrOutOfGas = Register(Codespace, 11, "out of gas") - - // ErrMemoTooLarge to doc - ErrMemoTooLarge = Register(Codespace, 12, "memo too large") - - // ErrInsufficientFee to doc - ErrInsufficientFee = Register(Codespace, 13, "insufficient fee") - - // ErrTooManySignatures to doc - ErrTooManySignatures = Register(Codespace, 14, "maximum number of signatures exceeded") - - // ErrNoSignatures to doc - ErrNoSignatures = Register(Codespace, 15, "no signatures supplied") - - // ErrJSONMarshal defines an ABCI typed JSON marshalling error - ErrJSONMarshal = Register(Codespace, 16, "failed to marshal JSON bytes") - - // ErrJSONUnmarshal defines an ABCI typed JSON unmarshalling error - ErrJSONUnmarshal = Register(Codespace, 17, "failed to unmarshal JSON bytes") - - // ErrInvalidRequest defines an ABCI typed error where the request contains - // invalid data. - ErrInvalidRequest = Register(Codespace, 18, "invalid request") - - // ErrTxInMempoolCache defines an ABCI typed error where a tx already exists - // in the mempool. - ErrTxInMempoolCache = Register(Codespace, 19, "tx already in mempool") - - // ErrMempoolIsFull defines an ABCI typed error where the mempool is full. - ErrMempoolIsFull = Register(Codespace, 20, "mempool is full") - - // ErrTxTooLarge defines an ABCI typed error where tx is too large. - ErrTxTooLarge = Register(Codespace, 21, "tx too large") - - // ErrKeyNotFound defines an error when the key doesn't exist - ErrKeyNotFound = Register(Codespace, 22, "key not found") - - // ErrWrongPassword defines an error when the key password is invalid. - ErrWrongPassword = Register(Codespace, 23, "invalid account password") - - // ErrorInvalidSigner defines an error when the tx intended signer does not match the given signer. - ErrorInvalidSigner = Register(Codespace, 24, "tx intended signer does not match the given signer") - - // ErrorInvalidGasAdjustment defines an error for an invalid gas adjustment - ErrorInvalidGasAdjustment = Register(Codespace, 25, "invalid gas adjustment") - - // ErrInvalidHeight defines an error for an invalid height - ErrInvalidHeight = Register(Codespace, 26, "invalid height") - - // ErrInvalidVersion defines a general error for an invalid version - ErrInvalidVersion = Register(Codespace, 27, "invalid version") - - // ErrInvalidChainID defines an error when the chain-id is invalid. - ErrInvalidChainID = Register(Codespace, 28, "invalid chain-id") - - // ErrInvalidType defines an error an invalid type. - ErrInvalidType = Register(Codespace, 29, "invalid type") - - // ErrTxTimeoutHeight defines an error for when a tx is rejected out due to an - // explicitly set timeout height. - ErrTxTimeoutHeight = Register(Codespace, 30, "tx timeout height") - - // ErrUnknownExtensionOptions defines an error for unknown extension options. - ErrUnknownExtensionOptions = Register(Codespace, 31, "unknown extension options") - - // ErrWrongSequence defines an error where the account sequence defined in - // the signer info doesn't match the account's actual sequence number. - ErrWrongSequence = Register(Codespace, 32, "incorrect account sequence") - - // ErrPackAny defines an error when packing a protobuf message to Any fails. - ErrPackAny = Register(Codespace, 33, "failed packing protobuf message to Any") - - // ErrUnpackAny defines an error when unpacking a protobuf message from Any fails. - ErrUnpackAny = Register(Codespace, 34, "failed unpacking protobuf message from Any") - - // ErrLogic defines an internal logic error, e.g. an invariant or assertion - // that is violated. It is a programmer error, not a user-facing error. - ErrLogic = Register(Codespace, 35, "internal logic error") - - // ErrConflict defines a conflict error, e.g. when two goroutines try to access - // the same resource and one of them fails. - ErrConflict = Register(Codespace, 36, "conflict") - - // ErrNotSupported is returned when we call a branch of a code which is currently not - // supported. - ErrNotSupported = Register(Codespace, 37, "feature not supported") - - // ErrNotFound defines an error when requested entity doesn't exist in the state. - ErrNotFound = Register(Codespace, 38, "not found") - - // ErrIO should be used to wrap internal errors caused by external operation. - // Examples: not DB domain error, file writing etc... - ErrIO = Register(Codespace, 39, "Internal IO error") - - // ErrAppConfig defines an error occurred if min-gas-prices field in BaseConfig is empty. - ErrAppConfig = Register(Codespace, 40, "error in app.toml") - - // ErrInvalidGasLimit defines an error when an invalid GasWanted value is - // supplied. - ErrInvalidGasLimit = Register(Codespace, 41, "invalid gas limit") - - // ErrPanic is only set when we recover from a panic, so we know to - // redact potentially sensitive system info - ErrPanic = sdkerrors.ErrPanic -) diff --git a/x/claim/keeper/airdrop_supply.go b/x/claim/keeper/airdrop_supply.go index 241f6dc..5715b7c 100644 --- a/x/claim/keeper/airdrop_supply.go +++ b/x/claim/keeper/airdrop_supply.go @@ -4,6 +4,7 @@ import ( "context" "cosmossdk.io/collections" + sdkerrors "cosmossdk.io/errors" sdkmath "cosmossdk.io/math" sdk "github.com/cosmos/cosmos-sdk/types" @@ -37,10 +38,10 @@ func (k Keeper) InitializeAirdropSupply(ctx context.Context, airdropSupply sdk.C func (k Keeper) EndAirdrop(ctx context.Context) error { airdropSupply, err := k.AirdropSupply.Get(ctx) - if err != nil && !errors.IsOf(err, collections.ErrNotFound) { + if err != nil && !sdkerrors.IsOf(err, collections.ErrNotFound) { return err } - if errors.IsOf(err, collections.ErrNotFound) || !airdropSupply.Supply.IsPositive() { + if sdkerrors.IsOf(err, collections.ErrNotFound) || !airdropSupply.Supply.IsPositive() { return nil } diff --git a/x/claim/keeper/mission.go b/x/claim/keeper/mission.go index 89d362c..55c137e 100644 --- a/x/claim/keeper/mission.go +++ b/x/claim/keeper/mission.go @@ -3,6 +3,7 @@ package keeper import ( "context" + sdkerrors "cosmossdk.io/errors" "cosmossdk.io/math" sdk "github.com/cosmos/cosmos-sdk/types" @@ -20,18 +21,18 @@ func (k Keeper) CompleteMission( ) (claimed math.Int, err error) { // retrieve mission if _, err := k.Mission.Get(ctx, missionID); err != nil { - return claimed, errors.Wrapf(types.ErrMissionNotFound, "mission %d not found: %s", missionID, err.Error()) + return claimed, sdkerrors.Wrapf(types.ErrMissionNotFound, "mission %d not found: %s", missionID, err.Error()) } // retrieve claim record of the user claimRecord, err := k.ClaimRecord.Get(ctx, address) if err != nil { - return claimed, errors.Wrapf(types.ErrClaimRecordNotFound, "claim record not found for address %s: %s", address, err.Error()) + return claimed, sdkerrors.Wrapf(types.ErrClaimRecordNotFound, "claim record not found for address %s: %s", address, err.Error()) } // check if the mission is already completed for the claim record if claimRecord.IsMissionCompleted(missionID) { - return claimed, errors.Wrapf( + return claimed, sdkerrors.Wrapf( types.ErrMissionCompleted, "mission %d completed for address %s", missionID, @@ -76,18 +77,18 @@ func (k Keeper) ClaimMission( ) (claimed math.Int, err error) { airdropSupply, err := k.AirdropSupply.Get(ctx) if err != nil { - return claimed, errors.Wrapf(types.ErrAirdropSupplyNotFound, "airdrop supply is not defined: %s", err.Error()) + return claimed, sdkerrors.Wrapf(types.ErrAirdropSupplyNotFound, "airdrop supply is not defined: %s", err.Error()) } // retrieve mission mission, err := k.Mission.Get(ctx, missionID) if err != nil { - return claimed, errors.Wrapf(types.ErrMissionNotFound, "mission %d not found: %s", missionID, err.Error()) + return claimed, sdkerrors.Wrapf(types.ErrMissionNotFound, "mission %d not found: %s", missionID, err.Error()) } // check if the mission is not completed for the claim record if !claimRecord.IsMissionCompleted(missionID) { - return claimed, errors.Wrapf( + return claimed, sdkerrors.Wrapf( types.ErrMissionNotCompleted, "mission %d is not completed for address %s", missionID, @@ -95,7 +96,7 @@ func (k Keeper) ClaimMission( ) } if claimRecord.IsMissionClaimed(missionID) { - return claimed, errors.Wrapf( + return claimed, sdkerrors.Wrapf( types.ErrMissionAlreadyClaimed, "mission %d is already claimed for address %s", missionID, diff --git a/x/claim/keeper/msg_server_claim.go b/x/claim/keeper/msg_server_claim.go index d3f853f..1219e9a 100644 --- a/x/claim/keeper/msg_server_claim.go +++ b/x/claim/keeper/msg_server_claim.go @@ -4,9 +4,9 @@ import ( "context" "cosmossdk.io/collections" + sdkerrors "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/ignite/modules/pkg/errors" "github.com/ignite/modules/x/claim/types" ) @@ -14,7 +14,7 @@ func (k msgServer) Claim(ctx context.Context, msg *types.MsgClaim) (*types.MsgCl // retrieve claim record of the user claimRecord, err := k.ClaimRecord.Get(ctx, msg.Claimer) if err != nil { - return &types.MsgClaimResponse{}, errors.Wrapf( + return &types.MsgClaimResponse{}, sdkerrors.Wrapf( types.ErrClaimRecordNotFound, "claim record not found for address %s: %s", msg.Claimer, @@ -24,7 +24,7 @@ func (k msgServer) Claim(ctx context.Context, msg *types.MsgClaim) (*types.MsgCl // check if the claim is an initial claim initialClaim, err := k.InitialClaim.Get(ctx) - if err != nil && errors.IsOf(err, collections.ErrNotFound) { + if err != nil && sdkerrors.IsOf(err, collections.ErrNotFound) { return nil, err } else if err == nil { if initialClaim.MissionId == msg.MissionId { @@ -46,7 +46,7 @@ func (k msgServer) Claim(ctx context.Context, msg *types.MsgClaim) (*types.MsgCl airdropStart := params.AirdropStart blockTime := sdk.UnwrapSDKContext(ctx).BlockTime() if blockTime.Before(airdropStart) { - return &types.MsgClaimResponse{}, errors.Wrapf( + return &types.MsgClaimResponse{}, sdkerrors.Wrapf( types.ErrAirdropStartNotReached, "airdrop start not reached: %s", airdropStart.String(), diff --git a/x/claim/simulation/claim.go b/x/claim/simulation/claim.go index ac19dfb..9f746c8 100644 --- a/x/claim/simulation/claim.go +++ b/x/claim/simulation/claim.go @@ -5,6 +5,7 @@ import ( "math/rand" "cosmossdk.io/collections" + sdkerrors "cosmossdk.io/errors" "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/client" simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims" @@ -12,7 +13,6 @@ import ( simtypes "github.com/cosmos/cosmos-sdk/types/simulation" sdksimulation "github.com/cosmos/cosmos-sdk/x/simulation" - "github.com/ignite/modules/pkg/errors" "github.com/ignite/modules/testutil/simulation" "github.com/ignite/modules/x/claim/keeper" "github.com/ignite/modules/x/claim/types" @@ -72,7 +72,7 @@ func SimulateMsgClaim( // verify that there is claimable amount airdropSupply, err := k.AirdropSupply.Get(ctx) - if err != nil && !errors.IsOf(err, collections.ErrNotFound) { + if err != nil && !sdkerrors.IsOf(err, collections.ErrNotFound) { return simtypes.NoOpMsg( types.ModuleName, msg.Type(), diff --git a/x/claim/types/errors.go b/x/claim/types/errors.go index b775fa4..0e61c44 100644 --- a/x/claim/types/errors.go +++ b/x/claim/types/errors.go @@ -3,21 +3,21 @@ package types // DONTCOVER import ( - "github.com/ignite/modules/pkg/errors" + sdkerrors "cosmossdk.io/errors" ) // x/claim module sentinel errors var ( - ErrInvalidSigner = errors.Register(ModuleName, 1101, "expected gov account as only signer for proposal message") - ErrMissionNotFound = errors.Register(ModuleName, 1102, "mission not found") - ErrClaimRecordNotFound = errors.Register(ModuleName, 1103, "claim record not found") - ErrMissionCompleted = errors.Register(ModuleName, 1104, "mission already completed") - ErrAirdropSupplyNotFound = errors.Register(ModuleName, 1105, "airdrop supply not found") - ErrInitialClaimNotFound = errors.Register(ModuleName, 1106, "initial claim information not found") - ErrInitialClaimNotEnabled = errors.Register(ModuleName, 1107, "initial claim not enabled") - ErrMissionCompleteFailure = errors.Register(ModuleName, 1108, "mission failed to complete") - ErrNoClaimable = errors.Register(ModuleName, 1109, "no amount to be claimed") - ErrMissionNotCompleted = errors.Register(ModuleName, 1110, "mission not completed yet") - ErrMissionAlreadyClaimed = errors.Register(ModuleName, 1111, "mission already claimed") - ErrAirdropStartNotReached = errors.Register(ModuleName, 1112, "airdrop start has not been reached yet") + ErrInvalidSigner = sdkerrors.Register(ModuleName, 1101, "expected gov account as only signer for proposal message") + ErrMissionNotFound = sdkerrors.Register(ModuleName, 1102, "mission not found") + ErrClaimRecordNotFound = sdkerrors.Register(ModuleName, 1103, "claim record not found") + ErrMissionCompleted = sdkerrors.Register(ModuleName, 1104, "mission already completed") + ErrAirdropSupplyNotFound = sdkerrors.Register(ModuleName, 1105, "airdrop supply not found") + ErrInitialClaimNotFound = sdkerrors.Register(ModuleName, 1106, "initial claim information not found") + ErrInitialClaimNotEnabled = sdkerrors.Register(ModuleName, 1107, "initial claim not enabled") + ErrMissionCompleteFailure = sdkerrors.Register(ModuleName, 1108, "mission failed to complete") + ErrNoClaimable = sdkerrors.Register(ModuleName, 1109, "no amount to be claimed") + ErrMissionNotCompleted = sdkerrors.Register(ModuleName, 1110, "mission not completed yet") + ErrMissionAlreadyClaimed = sdkerrors.Register(ModuleName, 1111, "mission already claimed") + ErrAirdropStartNotReached = sdkerrors.Register(ModuleName, 1112, "airdrop start has not been reached yet") )