Skip to content

Commit e22890b

Browse files
authored
chore(x/staking,x/upgrade): replace fmt.Errorf without parameters with errors.New (#21004)
1 parent 748352e commit e22890b

10 files changed

Lines changed: 25 additions & 22 deletions

File tree

x/params/types/common_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ func validateUnbondingTime(i interface{}) error {
3939
}
4040

4141
if v < (24 * time.Hour) {
42-
return fmt.Errorf("unbonding time must be at least one day")
42+
return errors.New("unbonding time must be at least one day")
4343
}
4444

4545
return nil

x/protocolpool/types/genesis.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
package types
22

33
import (
4-
"fmt"
4+
"errors"
55

6-
"cosmossdk.io/errors"
6+
errorsmod "cosmossdk.io/errors"
77
"cosmossdk.io/math"
88

99
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
@@ -40,41 +40,41 @@ func ValidateGenesis(gs *GenesisState) error {
4040

4141
func validateBudget(bp Budget) error {
4242
if bp.RecipientAddress == "" {
43-
return fmt.Errorf("recipient cannot be empty")
43+
return errors.New("recipient cannot be empty")
4444
}
4545

4646
// Validate BudgetPerTranche
4747
if bp.BudgetPerTranche == nil || bp.BudgetPerTranche.IsZero() {
48-
return fmt.Errorf("budget per tranche cannot be zero")
48+
return errors.New("budget per tranche cannot be zero")
4949
}
5050
if err := bp.BudgetPerTranche.Validate(); err != nil {
51-
return errors.Wrap(sdkerrors.ErrInvalidCoins, bp.BudgetPerTranche.String())
51+
return errorsmod.Wrap(sdkerrors.ErrInvalidCoins, bp.BudgetPerTranche.String())
5252
}
5353

5454
if bp.TranchesLeft == 0 {
55-
return fmt.Errorf("invalid budget proposal: tranches must be greater than zero")
55+
return errors.New("invalid budget proposal: tranches must be greater than zero")
5656
}
5757

5858
if bp.Period == nil || *bp.Period == 0 {
59-
return fmt.Errorf("invalid budget proposal: period length should be greater than zero")
59+
return errors.New("invalid budget proposal: period length should be greater than zero")
6060
}
6161
return nil
6262
}
6363

6464
func validateContinuousFund(cf ContinuousFund) error {
6565
if cf.Recipient == "" {
66-
return fmt.Errorf("recipient cannot be empty")
66+
return errors.New("recipient cannot be empty")
6767
}
6868

6969
// Validate percentage
7070
if cf.Percentage.IsNil() || cf.Percentage.IsZero() {
71-
return fmt.Errorf("percentage cannot be zero or empty")
71+
return errors.New("percentage cannot be zero or empty")
7272
}
7373
if cf.Percentage.IsNegative() {
74-
return fmt.Errorf("percentage cannot be negative")
74+
return errors.New("percentage cannot be negative")
7575
}
7676
if cf.Percentage.GT(math.LegacyOneDec()) {
77-
return fmt.Errorf("percentage cannot be greater than one")
77+
return errors.New("percentage cannot be greater than one")
7878
}
7979
return nil
8080
}

x/simulation/simulate.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"bytes"
55
"encoding/binary"
66
"encoding/hex"
7+
"errors"
78
"fmt"
89
"io"
910
"math/rand"
@@ -113,7 +114,7 @@ func SimulateFromSeedX(
113114
// At least 2 accounts must be added here, otherwise when executing SimulateMsgSend
114115
// two accounts will be selected to meet the conditions from != to and it will fall into an infinite loop.
115116
if len(accs) <= 1 {
116-
return params, fmt.Errorf("at least two genesis accounts are required")
117+
return params, errors.New("at least two genesis accounts are required")
117118
}
118119

119120
config.ChainID = chainID

x/staking/keeper/delegation.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -719,7 +719,7 @@ func (k Keeper) Delegate(
719719
// all non bonded
720720
if subtractAccount {
721721
if tokenSrc == types.Bonded {
722-
return math.LegacyZeroDec(), fmt.Errorf("delegation token source cannot be bonded; expected Unbonded or Unbonding, got Bonded")
722+
return math.LegacyZeroDec(), errors.New("delegation token source cannot be bonded; expected Unbonded or Unbonding, got Bonded")
723723
}
724724

725725
var sendName string

x/staking/keeper/slash.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ func (k Keeper) Slash(ctx context.Context, consAddr sdk.ConsAddress, infractionH
190190
return math.NewInt(0), err
191191
}
192192
default:
193-
return math.NewInt(0), fmt.Errorf("invalid validator status")
193+
return math.NewInt(0), errors.New("invalid validator status")
194194
}
195195

196196
k.Logger.Info(
@@ -415,7 +415,7 @@ func (k Keeper) SlashRedelegation(ctx context.Context, srcValidator types.Valida
415415
case dstValidator.IsUnbonded() || dstValidator.IsUnbonding():
416416
notBondedBurnedAmount = notBondedBurnedAmount.Add(tokensToBurn)
417417
default:
418-
return math.ZeroInt(), fmt.Errorf("unknown validator status")
418+
return math.ZeroInt(), errors.New("unknown validator status")
419419
}
420420
}
421421

x/staking/keeper/val_state_change.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package keeper
33
import (
44
"bytes"
55
"context"
6+
"errors"
67
"fmt"
78
"sort"
89

@@ -172,7 +173,7 @@ func (k Keeper) ApplyAndReturnValidatorSetUpdates(ctx context.Context) ([]appmod
172173
}
173174

174175
if validator.Jailed {
175-
return nil, fmt.Errorf("should never retrieve a jailed validator from the power store")
176+
return nil, errors.New("should never retrieve a jailed validator from the power store")
176177
}
177178

178179
// if we get to a zero-power validator (which we don't bond),
@@ -198,7 +199,7 @@ func (k Keeper) ApplyAndReturnValidatorSetUpdates(ctx context.Context) ([]appmod
198199
case validator.IsBonded():
199200
// no state change
200201
default:
201-
return nil, fmt.Errorf("unexpected validator status")
202+
return nil, errors.New("unexpected validator status")
202203
}
203204

204205
// fetch the old power bytes

x/staking/keeper/validator.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -542,7 +542,7 @@ func (k Keeper) unbondMatureValidators(
542542
}
543543

544544
if !val.IsUnbonding() {
545-
return fmt.Errorf("unexpected validator in unbonding queue; status was not unbonding")
545+
return errors.New("unexpected validator in unbonding queue; status was not unbonding")
546546
}
547547

548548
// if the ref count is not zero, early exit.

x/staking/types/params.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ func ValidatePowerReduction(i interface{}) error {
188188
}
189189

190190
if v.LT(math.NewInt(1)) {
191-
return fmt.Errorf("power reduction cannot be lower than 1")
191+
return errors.New("power reduction cannot be lower than 1")
192192
}
193193

194194
return nil

x/upgrade/keeper/keeper.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,7 @@ func (k Keeper) HasHandler(name string) bool {
415415
func (k Keeper) ApplyUpgrade(ctx context.Context, plan types.Plan) error {
416416
handler := k.upgradeHandlers[plan.Name]
417417
if handler == nil {
418-
return fmt.Errorf("ApplyUpgrade should never be called without first checking HasHandler")
418+
return errors.New("ApplyUpgrade should never be called without first checking HasHandler")
419419
}
420420

421421
vm, err := k.GetModuleVersionMap(ctx)

x/upgrade/keeper/migrations.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package keeper
33
import (
44
"context"
55
"encoding/binary"
6+
"errors"
67
"fmt"
78

89
storetypes "cosmossdk.io/core/store"
@@ -63,7 +64,7 @@ func (m Migrator) Migrate2to3(ctx context.Context) error {
6364

6465
func migrateAppVersion(ctx context.Context, keeper *Keeper) error {
6566
if keeper.versionModifier == nil {
66-
return fmt.Errorf("version modifier is not set")
67+
return errors.New("version modifier is not set")
6768
}
6869

6970
store := keeper.KVStoreService.OpenKVStore(ctx)

0 commit comments

Comments
 (0)