Skip to content

Commit

Permalink
refactor: use errors.New to replace fmt.Errorf with no parameters (#2142
Browse files Browse the repository at this point in the history
)

Co-authored-by: Christian Gorenflo <[email protected]>
  • Loading branch information
ChengenH and cgorenflo authored Jul 30, 2024
1 parent b44175d commit 0ececf3
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 13 deletions.
10 changes: 5 additions & 5 deletions x/evm/types/msg_confirm_gateway_txs.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package types

import (
"fmt"
"errors"

sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
Expand Down Expand Up @@ -42,19 +42,19 @@ func (m ConfirmGatewayTxsRequest) ValidateBasic() error {
}

if len(m.TxIDs) == 0 {
return fmt.Errorf("tx ids cannot be empty")
return errors.New("tx ids cannot be empty")
}

if len(m.TxIDs) > TxLimit {
return fmt.Errorf("tx ids limit exceeded")
return errors.New("tx ids limit exceeded")
}

if slices.Any(m.TxIDs, Hash.IsZero) {
return fmt.Errorf("invalid tx id")
return errors.New("invalid tx id")
}

if slices.HasDuplicates(m.TxIDs) {
return fmt.Errorf("duplicate tx ids")
return errors.New("duplicate tx ids")
}

return nil
Expand Down
15 changes: 8 additions & 7 deletions x/evm/types/params.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package types

import (
"errors"
"fmt"

sdk "github.com/cosmos/cosmos-sdk/types"
Expand Down Expand Up @@ -153,7 +154,7 @@ func validateBytes(bytes interface{}) error {
}

if len(b) == 0 {
return fmt.Errorf("byte slice cannot be empty")
return errors.New("byte slice cannot be empty")
}

return nil
Expand Down Expand Up @@ -196,7 +197,7 @@ func validateNetworks(network interface{}) error {
}

if !n.Id.IsPositive() {
return fmt.Errorf("network chain id must be positive")
return errors.New("network chain id must be positive")
}
}

Expand All @@ -223,7 +224,7 @@ func validateMinVoterCount(minVoterCount interface{}) error {
}

if val < 1 {
return fmt.Errorf("min voter count must be >=1")
return errors.New("min voter count must be >=1")
}

return nil
Expand All @@ -236,7 +237,7 @@ func validateCommandsGasLimit(commandsGasLimit interface{}) error {
}

if val <= 0 {
return fmt.Errorf("commands gas limit must be >0")
return errors.New("commands gas limit must be >0")
}

return nil
Expand All @@ -260,7 +261,7 @@ func validateEndBlockerLimit(limit interface{}) error {
return fmt.Errorf("invalid parameter type for end blocker limit: %T", limit)
}
if h <= 0 {
return fmt.Errorf("end blocker limit must be >0")
return errors.New("end blocker limit must be >0")
}

return nil
Expand All @@ -272,7 +273,7 @@ func validateTransferLimit(limit interface{}) error {
return fmt.Errorf("invalid parameter type for transfer limit: %T", limit)
}
if h == 0 {
return fmt.Errorf("transfer limit must be >0")
return errors.New("transfer limit must be >0")
}

return nil
Expand All @@ -297,7 +298,7 @@ func (m Params) Validate() error {
}

if m.VotingGracePeriod >= m.RevoteLockingPeriod {
return fmt.Errorf("voting grace period must be < revote locking period")
return errors.New("voting grace period must be < revote locking period")
}

if err := validateVotingThreshold(m.VotingThreshold); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion x/evm/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ type Signature [crypto.SignatureLength]byte
// NewSignature is the constructor of Signature
func NewSignature(bz []byte) (sig Signature, err error) {
if len(bz) != crypto.SignatureLength {
return Signature{}, fmt.Errorf("invalid signature length")
return Signature{}, errors.New("invalid signature length")
}

copy(sig[:], bz)
Expand Down

0 comments on commit 0ececf3

Please sign in to comment.