Skip to content

Commit

Permalink
chore: use errors.New to replace fmt.Errorf with no parameters
Browse files Browse the repository at this point in the history
Signed-off-by: ChengenH <[email protected]>
  • Loading branch information
ChengenH committed Dec 8, 2024
1 parent b62f564 commit c670ffb
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 12 deletions.
3 changes: 2 additions & 1 deletion x/ccv/provider/ibc_module.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package provider

import (
"errors"
"fmt"
"strconv"

Expand Down Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions x/ccv/provider/types/genesis.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package types

import (
"errors"
"fmt"

host "github.com/cosmos/ibc-go/v8/modules/core/24-host"
Expand Down Expand Up @@ -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 {
Expand All @@ -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
Expand Down
11 changes: 6 additions & 5 deletions x/ccv/provider/types/msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package types

import (
"encoding/json"
"errors"
"fmt"
"strings"

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions x/ccv/types/shared_params.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package types

import (
"errors"
fmt "fmt"
"strconv"
"strings"
Expand All @@ -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
}
Expand All @@ -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
}
Expand Down
5 changes: 3 additions & 2 deletions x/ccv/types/wire.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package types

import (
"encoding/json"
"errors"
"fmt"

errorsmod "cosmossdk.io/errors"
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit c670ffb

Please sign in to comment.