chore(x/staking,x/upgrade): replace fmt.Errorf without parameters with errors.New (#21004)

This commit is contained in:
yukionfire
2024-07-21 09:53:48 +00:00
committed by GitHub
parent 748352ef93
commit e22890b11f
10 changed files with 25 additions and 22 deletions
+11 -11
View File
@@ -1,9 +1,9 @@
package types
import (
"fmt"
"errors"
"cosmossdk.io/errors"
errorsmod "cosmossdk.io/errors"
"cosmossdk.io/math"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
@@ -40,41 +40,41 @@ func ValidateGenesis(gs *GenesisState) error {
func validateBudget(bp Budget) error {
if bp.RecipientAddress == "" {
return fmt.Errorf("recipient cannot be empty")
return errors.New("recipient cannot be empty")
}
// Validate BudgetPerTranche
if bp.BudgetPerTranche == nil || bp.BudgetPerTranche.IsZero() {
return fmt.Errorf("budget per tranche cannot be zero")
return errors.New("budget per tranche cannot be zero")
}
if err := bp.BudgetPerTranche.Validate(); err != nil {
return errors.Wrap(sdkerrors.ErrInvalidCoins, bp.BudgetPerTranche.String())
return errorsmod.Wrap(sdkerrors.ErrInvalidCoins, bp.BudgetPerTranche.String())
}
if bp.TranchesLeft == 0 {
return fmt.Errorf("invalid budget proposal: tranches must be greater than zero")
return errors.New("invalid budget proposal: tranches must be greater than zero")
}
if bp.Period == nil || *bp.Period == 0 {
return fmt.Errorf("invalid budget proposal: period length should be greater than zero")
return errors.New("invalid budget proposal: period length should be greater than zero")
}
return nil
}
func validateContinuousFund(cf ContinuousFund) error {
if cf.Recipient == "" {
return fmt.Errorf("recipient cannot be empty")
return errors.New("recipient cannot be empty")
}
// Validate percentage
if cf.Percentage.IsNil() || cf.Percentage.IsZero() {
return fmt.Errorf("percentage cannot be zero or empty")
return errors.New("percentage cannot be zero or empty")
}
if cf.Percentage.IsNegative() {
return fmt.Errorf("percentage cannot be negative")
return errors.New("percentage cannot be negative")
}
if cf.Percentage.GT(math.LegacyOneDec()) {
return fmt.Errorf("percentage cannot be greater than one")
return errors.New("percentage cannot be greater than one")
}
return nil
}