From f2301d9ed937d67c775154b6c7c6897633d7d101 Mon Sep 17 00:00:00 2001 From: Andi <36215014+ChengenH@users.noreply.github.com> Date: Mon, 9 Dec 2024 22:24:55 +0800 Subject: [PATCH] chore: use errors.New to replace fmt.Errorf with no parameters (#2421) Signed-off-by: ChengenH --- x/ccv/provider/ibc_module.go | 3 ++- x/ccv/provider/types/genesis.go | 5 +++-- x/ccv/provider/types/msg.go | 11 ++++++----- x/ccv/types/shared_params.go | 5 +++-- x/ccv/types/wire.go | 5 +++-- 5 files changed, 17 insertions(+), 12 deletions(-) diff --git a/x/ccv/provider/ibc_module.go b/x/ccv/provider/ibc_module.go index a1d812ff5f..1e6ba6c8db 100644 --- a/x/ccv/provider/ibc_module.go +++ b/x/ccv/provider/ibc_module.go @@ -1,6 +1,7 @@ package provider import ( + "errors" "fmt" "strconv" @@ -252,7 +253,7 @@ func UnmarshalConsumerPacketData(packetData []byte) (consumerPacket ccv.Consumer // VSC matured packets should not be unmarshaled as v1 packets if v1Packet.Type == ccv.VscMaturedPacket { - return ccv.ConsumerPacketData{}, fmt.Errorf("VSC matured packets should be correctly unmarshaled") + return ccv.ConsumerPacketData{}, errors.New("VSC matured packets should be correctly unmarshaled") } // Convert from v1 packet type diff --git a/x/ccv/provider/types/genesis.go b/x/ccv/provider/types/genesis.go index e3cc478e2e..daefd8785e 100644 --- a/x/ccv/provider/types/genesis.go +++ b/x/ccv/provider/types/genesis.go @@ -1,6 +1,7 @@ package types import ( + "errors" "fmt" host "github.com/cosmos/ibc-go/v8/modules/core/24-host" @@ -83,7 +84,7 @@ func (cs ConsumerState) Validate() error { } // consumer genesis should be for a new chain only if !cs.ConsumerGenesis.NewChain { - return fmt.Errorf("consumer genesis must be for a new chain") + return errors.New("consumer genesis must be for a new chain") } // validate a new chain genesis if err := cs.ConsumerGenesis.Validate(); err != nil { @@ -98,7 +99,7 @@ func (cs ConsumerState) Validate() error { for _, pVSC := range cs.PendingValsetChanges { if pVSC.ValsetUpdateId == 0 { - return fmt.Errorf("valset update ID cannot be equal to zero") + return errors.New("valset update ID cannot be equal to zero") } if err := validateSlashAcksAddress(pVSC.SlashAcks); err != nil { return err diff --git a/x/ccv/provider/types/msg.go b/x/ccv/provider/types/msg.go index ae6b16e477..0264236c66 100644 --- a/x/ccv/provider/types/msg.go +++ b/x/ccv/provider/types/msg.go @@ -2,6 +2,7 @@ package types import ( "encoding/json" + "errors" "fmt" "strings" @@ -339,7 +340,7 @@ func (msg MsgCreateConsumer) ValidateBasic() error { if msg.PowerShapingParameters != nil { if msg.PowerShapingParameters.Top_N != 0 { - return fmt.Errorf("cannot create a Top N chain through `MsgCreateConsumer`; " + + return errors.New("cannot create a Top N chain through `MsgCreateConsumer`; " + "first create the chain and then use `MsgUpdateConsumer` to make the chain Top N") } if err := ValidatePowerShapingParameters(*msg.PowerShapingParameters); err != nil { @@ -462,19 +463,19 @@ func ParseConsumerKeyFromJson(jsonStr string) (pkType, key string, err error) { // TODO create unit test func ValidateHeaderForConsumerDoubleVoting(header *ibctmtypes.Header) error { if header == nil { - return fmt.Errorf("infraction block header cannot be nil") + return errors.New("infraction block header cannot be nil") } if header.SignedHeader == nil { - return fmt.Errorf("signed header in infraction block header cannot be nil") + return errors.New("signed header in infraction block header cannot be nil") } if header.SignedHeader.Header == nil { - return fmt.Errorf("invalid signed header in infraction block header, 'SignedHeader.Header' is nil") + return errors.New("invalid signed header in infraction block header, 'SignedHeader.Header' is nil") } if header.ValidatorSet == nil { - return fmt.Errorf("invalid infraction block header, validator set is nil") + return errors.New("invalid infraction block header, validator set is nil") } return nil diff --git a/x/ccv/types/shared_params.go b/x/ccv/types/shared_params.go index b2fd60db4b..32b7019e23 100644 --- a/x/ccv/types/shared_params.go +++ b/x/ccv/types/shared_params.go @@ -1,6 +1,7 @@ package types import ( + "errors" fmt "fmt" "strconv" "strings" @@ -27,7 +28,7 @@ func ValidateDuration(i interface{}) error { return fmt.Errorf("invalid parameter type: %T", i) } if period <= time.Duration(0) { - return fmt.Errorf("duration must be positive") + return errors.New("duration must be positive") } return nil } @@ -51,7 +52,7 @@ func ValidatePositiveInt64(i interface{}) error { return err } if i.(int64) <= int64(0) { - return fmt.Errorf("int must be positive") + return errors.New("int must be positive") } return nil } diff --git a/x/ccv/types/wire.go b/x/ccv/types/wire.go index ec04399380..9e49d546da 100644 --- a/x/ccv/types/wire.go +++ b/x/ccv/types/wire.go @@ -2,6 +2,7 @@ package types import ( "encoding/json" + "errors" "fmt" errorsmod "cosmossdk.io/errors" @@ -109,14 +110,14 @@ func (cp ConsumerPacketData) Validate() (err error) { // validate VSCMaturedPacket vscMaturedPacket := cp.GetVscMaturedPacketData() if vscMaturedPacket == nil { - return fmt.Errorf("invalid consumer packet data: VscMaturePacketData data cannot be empty") + return errors.New("invalid consumer packet data: VscMaturePacketData data cannot be empty") } err = vscMaturedPacket.Validate() case SlashPacket: // validate SlashPacket slashPacket := cp.GetSlashPacketData() if slashPacket == nil { - return fmt.Errorf("invalid consumer packet data: SlashPacketData data cannot be empty") + return errors.New("invalid consumer packet data: SlashPacketData data cannot be empty") } err = slashPacket.Validate() default: