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

chore: remove redudant error pkg #115

Merged
merged 1 commit into from
Nov 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
6 changes: 4 additions & 2 deletions pkg/errors/critical.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
166 changes: 0 additions & 166 deletions pkg/errors/errors.go

This file was deleted.

5 changes: 3 additions & 2 deletions x/claim/keeper/airdrop_supply.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"

"cosmossdk.io/collections"
sdkerrors "cosmossdk.io/errors"
sdkmath "cosmossdk.io/math"
sdk "github.com/cosmos/cosmos-sdk/types"

Expand Down Expand Up @@ -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
}

Expand Down
15 changes: 8 additions & 7 deletions x/claim/keeper/mission.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package keeper
import (
"context"

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

Expand All @@ -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,
Expand Down Expand Up @@ -76,26 +77,26 @@ 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,
claimRecord.Address,
)
}
if claimRecord.IsMissionClaimed(missionID) {
return claimed, errors.Wrapf(
return claimed, sdkerrors.Wrapf(
types.ErrMissionAlreadyClaimed,
"mission %d is already claimed for address %s",
missionID,
Expand Down
8 changes: 4 additions & 4 deletions x/claim/keeper/msg_server_claim.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@ 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"
)

func (k msgServer) Claim(ctx context.Context, msg *types.MsgClaim) (*types.MsgClaimResponse, error) {
// 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,
Expand All @@ -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 {
Expand All @@ -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(),
Expand Down
4 changes: 2 additions & 2 deletions x/claim/simulation/claim.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ 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"
sdk "github.com/cosmos/cosmos-sdk/types"
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"
Expand Down Expand Up @@ -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(),
Expand Down
26 changes: 13 additions & 13 deletions x/claim/types/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
)
Loading