Skip to content

Commit f2301d9

Browse files
authored
chore: use errors.New to replace fmt.Errorf with no parameters (#2421)
Signed-off-by: ChengenH <[email protected]>
1 parent cabebfa commit f2301d9

File tree

5 files changed

+17
-12
lines changed

5 files changed

+17
-12
lines changed

x/ccv/provider/ibc_module.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package provider
22

33
import (
4+
"errors"
45
"fmt"
56
"strconv"
67

@@ -252,7 +253,7 @@ func UnmarshalConsumerPacketData(packetData []byte) (consumerPacket ccv.Consumer
252253

253254
// VSC matured packets should not be unmarshaled as v1 packets
254255
if v1Packet.Type == ccv.VscMaturedPacket {
255-
return ccv.ConsumerPacketData{}, fmt.Errorf("VSC matured packets should be correctly unmarshaled")
256+
return ccv.ConsumerPacketData{}, errors.New("VSC matured packets should be correctly unmarshaled")
256257
}
257258

258259
// Convert from v1 packet type

x/ccv/provider/types/genesis.go

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

33
import (
4+
"errors"
45
"fmt"
56

67
host "github.com/cosmos/ibc-go/v8/modules/core/24-host"
@@ -83,7 +84,7 @@ func (cs ConsumerState) Validate() error {
8384
}
8485
// consumer genesis should be for a new chain only
8586
if !cs.ConsumerGenesis.NewChain {
86-
return fmt.Errorf("consumer genesis must be for a new chain")
87+
return errors.New("consumer genesis must be for a new chain")
8788
}
8889
// validate a new chain genesis
8990
if err := cs.ConsumerGenesis.Validate(); err != nil {
@@ -98,7 +99,7 @@ func (cs ConsumerState) Validate() error {
9899

99100
for _, pVSC := range cs.PendingValsetChanges {
100101
if pVSC.ValsetUpdateId == 0 {
101-
return fmt.Errorf("valset update ID cannot be equal to zero")
102+
return errors.New("valset update ID cannot be equal to zero")
102103
}
103104
if err := validateSlashAcksAddress(pVSC.SlashAcks); err != nil {
104105
return err

x/ccv/provider/types/msg.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package types
22

33
import (
44
"encoding/json"
5+
"errors"
56
"fmt"
67
"strings"
78

@@ -339,7 +340,7 @@ func (msg MsgCreateConsumer) ValidateBasic() error {
339340

340341
if msg.PowerShapingParameters != nil {
341342
if msg.PowerShapingParameters.Top_N != 0 {
342-
return fmt.Errorf("cannot create a Top N chain through `MsgCreateConsumer`; " +
343+
return errors.New("cannot create a Top N chain through `MsgCreateConsumer`; " +
343344
"first create the chain and then use `MsgUpdateConsumer` to make the chain Top N")
344345
}
345346
if err := ValidatePowerShapingParameters(*msg.PowerShapingParameters); err != nil {
@@ -462,19 +463,19 @@ func ParseConsumerKeyFromJson(jsonStr string) (pkType, key string, err error) {
462463
// TODO create unit test
463464
func ValidateHeaderForConsumerDoubleVoting(header *ibctmtypes.Header) error {
464465
if header == nil {
465-
return fmt.Errorf("infraction block header cannot be nil")
466+
return errors.New("infraction block header cannot be nil")
466467
}
467468

468469
if header.SignedHeader == nil {
469-
return fmt.Errorf("signed header in infraction block header cannot be nil")
470+
return errors.New("signed header in infraction block header cannot be nil")
470471
}
471472

472473
if header.SignedHeader.Header == nil {
473-
return fmt.Errorf("invalid signed header in infraction block header, 'SignedHeader.Header' is nil")
474+
return errors.New("invalid signed header in infraction block header, 'SignedHeader.Header' is nil")
474475
}
475476

476477
if header.ValidatorSet == nil {
477-
return fmt.Errorf("invalid infraction block header, validator set is nil")
478+
return errors.New("invalid infraction block header, validator set is nil")
478479
}
479480

480481
return nil

x/ccv/types/shared_params.go

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

33
import (
4+
"errors"
45
fmt "fmt"
56
"strconv"
67
"strings"
@@ -27,7 +28,7 @@ func ValidateDuration(i interface{}) error {
2728
return fmt.Errorf("invalid parameter type: %T", i)
2829
}
2930
if period <= time.Duration(0) {
30-
return fmt.Errorf("duration must be positive")
31+
return errors.New("duration must be positive")
3132
}
3233
return nil
3334
}
@@ -51,7 +52,7 @@ func ValidatePositiveInt64(i interface{}) error {
5152
return err
5253
}
5354
if i.(int64) <= int64(0) {
54-
return fmt.Errorf("int must be positive")
55+
return errors.New("int must be positive")
5556
}
5657
return nil
5758
}

x/ccv/types/wire.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package types
22

33
import (
44
"encoding/json"
5+
"errors"
56
"fmt"
67

78
errorsmod "cosmossdk.io/errors"
@@ -109,14 +110,14 @@ func (cp ConsumerPacketData) Validate() (err error) {
109110
// validate VSCMaturedPacket
110111
vscMaturedPacket := cp.GetVscMaturedPacketData()
111112
if vscMaturedPacket == nil {
112-
return fmt.Errorf("invalid consumer packet data: VscMaturePacketData data cannot be empty")
113+
return errors.New("invalid consumer packet data: VscMaturePacketData data cannot be empty")
113114
}
114115
err = vscMaturedPacket.Validate()
115116
case SlashPacket:
116117
// validate SlashPacket
117118
slashPacket := cp.GetSlashPacketData()
118119
if slashPacket == nil {
119-
return fmt.Errorf("invalid consumer packet data: SlashPacketData data cannot be empty")
120+
return errors.New("invalid consumer packet data: SlashPacketData data cannot be empty")
120121
}
121122
err = slashPacket.Validate()
122123
default:

0 commit comments

Comments
 (0)