Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: use errors.New to replace fmt.Errorf with no parameters #2216

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 22 additions & 21 deletions x/evm/abci.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package evm

import (
"errors"
"fmt"

sdk "github.com/cosmos/cosmos-sdk/types"
Expand All @@ -21,7 +22,7 @@
func handleTokenSent(ctx sdk.Context, event types.Event, bk types.BaseKeeper, n types.Nexus) error {
e := event.GetEvent().(*types.Event_TokenSent).TokenSent
if e == nil {
panic(fmt.Errorf("event is nil"))
panic(errors.New("event is nil"))

Check warning on line 25 in x/evm/abci.go

View check run for this annotation

Codecov / codecov/patch

x/evm/abci.go#L25

Added line #L25 was not covered by tests
}

sourceChain := funcs.MustOk(n.GetChain(ctx, event.Chain))
Expand Down Expand Up @@ -69,7 +70,7 @@
func handleContractCall(ctx sdk.Context, event types.Event, bk types.BaseKeeper, n types.Nexus, multisig types.MultisigKeeper) error {
e := event.GetContractCall()
if e == nil {
panic(fmt.Errorf("event is nil"))
panic(errors.New("event is nil"))

Check warning on line 73 in x/evm/abci.go

View check run for this annotation

Codecov / codecov/patch

x/evm/abci.go#L73

Added line #L73 was not covered by tests
}

destinationChain := funcs.MustOk(n.GetChain(ctx, e.DestinationChain))
Expand All @@ -86,7 +87,7 @@
func handleContractCallToEVM(ctx sdk.Context, bk types.BaseKeeper, multisig types.MultisigKeeper, n types.Nexus, destinationChain nexus.ChainName, event types.Event) {
e := event.GetContractCall()
if e == nil {
panic(fmt.Errorf("event is nil"))
panic(errors.New("event is nil"))

Check warning on line 90 in x/evm/abci.go

View check run for this annotation

Codecov / codecov/patch

x/evm/abci.go#L90

Added line #L90 was not covered by tests
}

destinationCk := funcs.Must(bk.ForChain(ctx, destinationChain))
Expand Down Expand Up @@ -119,7 +120,7 @@
func handleContractCallWithToken(ctx sdk.Context, event types.Event, bk types.BaseKeeper, n types.Nexus, multisig types.MultisigKeeper) error {
e := event.GetContractCallWithToken()
if e == nil {
panic(fmt.Errorf("event is nil"))
panic(errors.New("event is nil"))

Check warning on line 123 in x/evm/abci.go

View check run for this annotation

Codecov / codecov/patch

x/evm/abci.go#L123

Added line #L123 was not covered by tests
}

sourceChain := funcs.MustOk(n.GetChain(ctx, event.Chain))
Expand Down Expand Up @@ -149,7 +150,7 @@
func handleContractCallWithTokenToEVM(ctx sdk.Context, event types.Event, bk types.BaseKeeper, n types.Nexus, multisig types.MultisigKeeper, sourceChain, destinationChain nexus.ChainName, asset string) error {
e := event.GetContractCallWithToken()
if e == nil {
panic(fmt.Errorf("event is nil"))
panic(errors.New("event is nil"))

Check warning on line 153 in x/evm/abci.go

View check run for this annotation

Codecov / codecov/patch

x/evm/abci.go#L153

Added line #L153 was not covered by tests
}

destinationCk := funcs.Must(bk.ForChain(ctx, destinationChain))
Expand Down Expand Up @@ -228,7 +229,7 @@

case *types.Event_ContractCallWithToken:
if asset == nil {
return fmt.Errorf("expect asset for ContractCallWithToken")
return errors.New("expect asset for ContractCallWithToken")

Check warning on line 232 in x/evm/abci.go

View check run for this annotation

Codecov / codecov/patch

x/evm/abci.go#L232

Added line #L232 was not covered by tests
}

sender := nexus.CrossChainAddress{
Expand Down Expand Up @@ -264,7 +265,7 @@
func handleConfirmDeposit(ctx sdk.Context, event types.Event, bk types.BaseKeeper, n types.Nexus) error {
e := event.GetEvent().(*types.Event_Transfer).Transfer
if e == nil {
panic(fmt.Errorf("event is nil"))
panic(errors.New("event is nil"))

Check warning on line 268 in x/evm/abci.go

View check run for this annotation

Codecov / codecov/patch

x/evm/abci.go#L268

Added line #L268 was not covered by tests
}

chain := funcs.MustOk(n.GetChain(ctx, event.Chain))
Expand Down Expand Up @@ -336,7 +337,7 @@
func handleTokenDeployed(ctx sdk.Context, event types.Event, bk types.BaseKeeper, n types.Nexus) error {
e := event.GetEvent().(*types.Event_TokenDeployed).TokenDeployed
if e == nil {
panic(fmt.Errorf("event is nil"))
panic(errors.New("event is nil"))

Check warning on line 340 in x/evm/abci.go

View check run for this annotation

Codecov / codecov/patch

x/evm/abci.go#L340

Added line #L340 was not covered by tests
}

chain := funcs.MustOk(n.GetChain(ctx, event.Chain))
Expand Down Expand Up @@ -380,7 +381,7 @@
func handleMultisigTransferKey(ctx sdk.Context, event types.Event, bk types.BaseKeeper, n types.Nexus, multisig types.MultisigKeeper) error {
e := event.GetEvent().(*types.Event_MultisigOperatorshipTransferred).MultisigOperatorshipTransferred
if e == nil {
panic(fmt.Errorf("event is nil"))
panic(errors.New("event is nil"))

Check warning on line 384 in x/evm/abci.go

View check run for this annotation

Codecov / codecov/patch

x/evm/abci.go#L384

Added line #L384 was not covered by tests
}

chain := funcs.MustOk(n.GetChain(ctx, event.Chain))
Expand Down Expand Up @@ -409,17 +410,17 @@
for i, newAddress := range newAddresses {
newAddressHex := newAddress.Hex()
if addressSeen[newAddressHex] {
return fmt.Errorf("duplicate address in new addresses")
return errors.New("duplicate address in new addresses")

Check warning on line 413 in x/evm/abci.go

View check run for this annotation

Codecov / codecov/patch

x/evm/abci.go#L413

Added line #L413 was not covered by tests
}
addressSeen[newAddressHex] = true

expectedWeight, ok := expectedAddressWeights[newAddressHex]
if !ok {
return fmt.Errorf("new addresses do not match")
return errors.New("new addresses do not match")

Check warning on line 419 in x/evm/abci.go

View check run for this annotation

Codecov / codecov/patch

x/evm/abci.go#L419

Added line #L419 was not covered by tests
}

if !expectedWeight.Equal(newWeights[i]) {
return fmt.Errorf("new weights do not match")
return errors.New("new weights do not match")

Check warning on line 423 in x/evm/abci.go

View check run for this annotation

Codecov / codecov/patch

x/evm/abci.go#L423

Added line #L423 was not covered by tests
}
}

Expand Down Expand Up @@ -473,12 +474,12 @@
// skip if destination chain is not registered
destinationChain, ok := n.GetChain(ctx, destinationChainName)
if !ok {
return fmt.Errorf("destination chain not found")
return errors.New("destination chain not found")
}

// skip if destination chain is not activated
if !n.IsChainActivated(ctx, destinationChain) {
return fmt.Errorf("destination chain de-activated")
return errors.New("destination chain de-activated")
}

// skip further destination chain keeper checks if it is not an evm chain
Expand All @@ -487,17 +488,17 @@
}

if len(contractAddress) != 0 && !common.IsHexAddress(contractAddress) {
return fmt.Errorf("invalid contract address")
return errors.New("invalid contract address")

Check warning on line 491 in x/evm/abci.go

View check run for this annotation

Codecov / codecov/patch

x/evm/abci.go#L491

Added line #L491 was not covered by tests
}

destinationCk, err := bk.ForChain(ctx, destinationChainName)
if err != nil {
return fmt.Errorf("destination chain not EVM-compatible")
return errors.New("destination chain not EVM-compatible")

Check warning on line 496 in x/evm/abci.go

View check run for this annotation

Codecov / codecov/patch

x/evm/abci.go#L496

Added line #L496 was not covered by tests
}

// skip if destination chain has not got gateway set yet
if _, ok := destinationCk.GetGatewayAddress(ctx); !ok {
return fmt.Errorf("destination chain gateway not deployed yet")
return errors.New("destination chain gateway not deployed yet")
}

return nil
Expand Down Expand Up @@ -575,19 +576,19 @@
// TODO refactor to do these checks earlier so we don't fail in the end blocker
_, ok := m.GetCurrentKeyID(ctx, chain.Name)
if !ok {
return fmt.Errorf("current key not set")
return errors.New("current key not set")
}

if !n.IsChainActivated(ctx, chain) {
return fmt.Errorf("destination chain de-activated")
return errors.New("destination chain de-activated")
}

if _, ok := ck.GetGatewayAddress(ctx); !ok {
return fmt.Errorf("destination chain gateway not deployed yet")
return errors.New("destination chain gateway not deployed yet")
}

if !common.IsHexAddress(msg.GetDestinationAddress()) {
return fmt.Errorf("invalid contract address")
return errors.New("invalid contract address")
}

switch msg.Type() {
Expand Down
12 changes: 6 additions & 6 deletions x/evm/abci_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ func TestHandleGeneralMessage(t *testing.T) {
return func() {
destinationCk.EnqueueCommandFunc = func(ctx sdk.Context, cmd types.Command) error {
if !isSuccessful {
return fmt.Errorf("enqueue error")
return errors.New("enqueue error")
}

return nil
Expand Down Expand Up @@ -420,7 +420,7 @@ func TestHandleGeneralMessages(t *testing.T) {
When("rate limit is triggered", func() {
n.SetMessageFailedFunc = func(ctx sdk.Context, id string) error { return nil }
n.RateLimitTransferFunc = func(ctx sdk.Context, chain nexus.ChainName, asset sdk.Coin, direction nexus.TransferDirection) error {
return fmt.Errorf("rate limit triggered")
return errors.New("rate limit triggered")
}
}).
Then("should handle", func(t *testing.T) {
Expand Down Expand Up @@ -548,7 +548,7 @@ func TestHandleContractCall(t *testing.T) {
return func() {
destinationCk.EnqueueCommandFunc = func(ctx sdk.Context, cmd types.Command) error {
if !isSuccessful {
return fmt.Errorf("enqueue error")
return errors.New("enqueue error")
}

return nil
Expand All @@ -560,7 +560,7 @@ func TestHandleContractCall(t *testing.T) {
return func() {
n.SetNewMessageFunc = func(sdk.Context, nexus.GeneralMessage) error {
if !isSuccessful {
return fmt.Errorf("set general message error")
return errors.New("set general message error")
}

return nil
Expand Down Expand Up @@ -779,7 +779,7 @@ func TestHandleTokenSent(t *testing.T) {
whenTokensAreConfirmed.
When("failed to enqueue the transfer", func() {
n.EnqueueTransferFunc = func(ctx sdk.Context, senderChain nexus.Chain, recipient nexus.CrossChainAddress, asset sdk.Coin) (nexus.TransferID, error) {
return 0, fmt.Errorf("err")
return 0, errors.New("err")
}
}).
Then("should fail", assertFail).
Expand Down Expand Up @@ -1272,7 +1272,7 @@ func TestHandleConfirmDeposit(t *testing.T) {
return func() {
n.EnqueueForTransferFunc = func(sdk.Context, nexus.CrossChainAddress, sdk.Coin) (nexus.TransferID, error) {
if !succeed {
return 0, fmt.Errorf("err")
return 0, errors.New("err")
}
return 0, nil
}
Expand Down
9 changes: 5 additions & 4 deletions x/evm/types/genesis.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading