From 9f3cf19a02b4c9c344e6687c074ff54b557d981a Mon Sep 17 00:00:00 2001 From: yukionfire Date: Thu, 18 Jul 2024 11:12:11 +0800 Subject: [PATCH] all: use `errors.New` to replace `fmt.Errorf` with no parameters --- cmd/chains.go | 6 ++--- cmd/config.go | 4 ++-- cmd/paths.go | 6 ++--- cregistry/chain_info.go | 4 ++-- cregistry/chain_info_test.go | 4 ++-- interchaintest/relayer.go | 3 ++- relayer/chains/cosmos/feegrant.go | 2 +- relayer/chains/cosmos/grpc_query.go | 4 ++-- relayer/chains/cosmos/provider.go | 3 ++- relayer/chains/cosmos/query.go | 2 +- relayer/chains/cosmos/tx.go | 14 ++++++------ relayer/chains/cosmos/tx_test.go | 6 ++--- relayer/chains/penumbra/grpc_query.go | 4 ++-- relayer/chains/penumbra/provider.go | 3 ++- relayer/chains/penumbra/query.go | 2 +- relayer/chains/penumbra/tx.go | 33 +++++++++++++-------------- relayer/client.go | 3 ++- relayer/events.go | 8 +++---- relayer/relaymsgs_test.go | 14 ++++++------ relayer/strategies.go | 2 +- 20 files changed, 65 insertions(+), 62 deletions(-) diff --git a/cmd/chains.go b/cmd/chains.go index aeba7323a..bcb1abcc2 100644 --- a/cmd/chains.go +++ b/cmd/chains.go @@ -238,7 +238,7 @@ func chainsRegistryList(a *appState) *cobra.Command { switch { case yml && jsn: - return fmt.Errorf("can't pass both --json and --yaml, must pick one") + return errors.New("can't pass both --json and --yaml, must pick one") case yml: out, err := yaml.Marshal(chains) if err != nil { @@ -291,7 +291,7 @@ $ %s ch l`, appName, appName)), switch { case yml && jsn: - return fmt.Errorf("can't pass both --json and --yaml, must pick one") + return errors.New("can't pass both --json and --yaml, must pick one") case yml: out, err := yaml.Marshal(configs) if err != nil { @@ -358,7 +358,7 @@ func chainsAddCmd(a *appState) *cobra.Command { } if ok := a.config; ok == nil { - return fmt.Errorf("config not initialized, consider running `rly config init`") + return errors.New("config not initialized, consider running `rly config init`") } return a.performConfigLockingOperation(cmd.Context(), func() error { diff --git a/cmd/config.go b/cmd/config.go index 2b8bde934..253580507 100644 --- a/cmd/config.go +++ b/cmd/config.go @@ -87,7 +87,7 @@ $ %s cfg list`, appName, defaultHome, appName)), } switch { case yml && jsn: - return fmt.Errorf("can't pass both --json and --yaml, must pick one") + return errors.New("can't pass both --json and --yaml, must pick one") case jsn: out, err := json.Marshal(a.config.Wrapped()) if err != nil { @@ -513,7 +513,7 @@ func newDefaultGlobalConfig(memo string) GlobalConfig { func (c *Config) AddChain(chain *relayer.Chain) (err error) { chainId := chain.ChainProvider.ChainId() if chainId == "" { - return fmt.Errorf("chain ID cannot be empty") + return errors.New("chain ID cannot be empty") } chn, err := c.Chains.Get(chainId) if chn != nil || err == nil { diff --git a/cmd/paths.go b/cmd/paths.go index b5583fb69..afcb4b924 100644 --- a/cmd/paths.go +++ b/cmd/paths.go @@ -76,7 +76,7 @@ $ %s pth l`, appName, appName, appName)), yml, _ := cmd.Flags().GetBool(flagYAML) switch { case yml && jsn: - return fmt.Errorf("can't pass both --json and --yaml, must pick one") + return errors.New("can't pass both --json and --yaml, must pick one") case yml: out, err := yaml.Marshal(a.config.Paths) if err != nil { @@ -148,7 +148,7 @@ $ %s pth s path-name`, appName, appName, appName)), pathWithStatus := p.QueryPathStatus(cmd.Context(), chains[p.Src.ChainID], chains[p.Dst.ChainID]) switch { case yml && jsn: - return fmt.Errorf("can't pass both --json and --yaml, must pick one") + return errors.New("can't pass both --json and --yaml, must pick one") case yml: out, err := yaml.Marshal(pathWithStatus) if err != nil { @@ -348,7 +348,7 @@ $ %s paths update demo-path --src-connection-id connection-02 --dst-connection-i } if !actionTaken { - return fmt.Errorf("at least one flag must be provided") + return errors.New("at least one flag must be provided") } return nil diff --git a/cregistry/chain_info.go b/cregistry/chain_info.go index 3ab8bb210..7edf02ce7 100644 --- a/cregistry/chain_info.go +++ b/cregistry/chain_info.go @@ -194,7 +194,7 @@ func (c ChainInfo) GetRandomRPCEndpoint(ctx context.Context, forceAdd bool) (str if len(rpcs) == 0 { if !forceAdd { - return "", fmt.Errorf("no working RPCs found, consider using --force-add") + return "", errors.New("no working RPCs found, consider using --force-add") } else { return "", nil } @@ -227,7 +227,7 @@ func (c ChainInfo) GetBackupRPCEndpoints(ctx context.Context, forceAdd bool, pri // if no rpcs, return error if len(rpcs) == 0 { if !forceAdd { - return nil, fmt.Errorf("no working RPCs found, consider using --force-add") + return nil, errors.New("no working RPCs found, consider using --force-add") } else { return nil, nil } diff --git a/cregistry/chain_info_test.go b/cregistry/chain_info_test.go index eb54a11c4..29a17691c 100644 --- a/cregistry/chain_info_test.go +++ b/cregistry/chain_info_test.go @@ -1,7 +1,7 @@ package cregistry import ( - "fmt" + "errors" "testing" "github.com/stretchr/testify/require" @@ -51,7 +51,7 @@ func TestGetAllRPCEndpoints(t *testing.T) { "unsupported or invalid url scheme error": { chainInfo: ChainInfoWithRPCEndpoint("ftp://test.com/rpc"), expectedEndpoints: nil, - expectedError: fmt.Errorf("invalid or unsupported url scheme: ftp"), + expectedError: errors.New("invalid or unsupported url scheme: ftp"), }, } diff --git a/interchaintest/relayer.go b/interchaintest/relayer.go index 025221516..0aa4b1945 100644 --- a/interchaintest/relayer.go +++ b/interchaintest/relayer.go @@ -3,6 +3,7 @@ package interchaintest import ( "context" "encoding/json" + "errors" "fmt" "strconv" "strings" @@ -254,7 +255,7 @@ func (r *Relayer) UpdateClients(ctx context.Context, _ ibc.RelayerExecReporter, func (r *Relayer) StartRelayer(ctx context.Context, _ ibc.RelayerExecReporter, pathNames ...string) error { if r.errCh != nil || r.cancel != nil { - panic(fmt.Errorf("StartRelayer called multiple times without being stopped")) + panic(errors.New("StartRelayer called multiple times without being stopped")) } r.errCh = make(chan error, 1) diff --git a/relayer/chains/cosmos/feegrant.go b/relayer/chains/cosmos/feegrant.go index 0d1ef1f4e..f74027290 100644 --- a/relayer/chains/cosmos/feegrant.go +++ b/relayer/chains/cosmos/feegrant.go @@ -182,7 +182,7 @@ func (cc *CosmosProvider) ConfigureWithExternalGranter(grantees []string, grante for _, grantee := range grantees { k, err := cc.KeyFromKeyOrAddress(grantee) if k == "" { - return fmt.Errorf("invalid empty grantee name") + return errors.New("invalid empty grantee name") } else if err != nil { return err } diff --git a/relayer/chains/cosmos/grpc_query.go b/relayer/chains/cosmos/grpc_query.go index 1582b96ee..5c35b334b 100644 --- a/relayer/chains/cosmos/grpc_query.go +++ b/relayer/chains/cosmos/grpc_query.go @@ -2,7 +2,7 @@ package cosmos import ( "context" - "fmt" + "errors" "reflect" "strconv" "sync" @@ -87,7 +87,7 @@ func (cc *CosmosProvider) Invoke(ctx context.Context, method string, req, reply // NewStream implements the grpc ClientConn.NewStream method func (cc *CosmosProvider) NewStream(context.Context, *grpc.StreamDesc, string, ...grpc.CallOption) (grpc.ClientStream, error) { - return nil, fmt.Errorf("streaming rpc not supported") + return nil, errors.New("streaming rpc not supported") } // RunGRPCQuery runs a gRPC query from the clientCtx, given all necessary diff --git a/relayer/chains/cosmos/provider.go b/relayer/chains/cosmos/provider.go index 2f88097d6..61d9a7a86 100644 --- a/relayer/chains/cosmos/provider.go +++ b/relayer/chains/cosmos/provider.go @@ -2,6 +2,7 @@ package cosmos import ( "context" + "errors" "fmt" "io" "os" @@ -433,7 +434,7 @@ func (cc *CosmosProvider) WaitForNBlocks(ctx context.Context, n int64) error { return err } if h.SyncInfo.CatchingUp { - return fmt.Errorf("chain catching up") + return errors.New("chain catching up") } initial = h.SyncInfo.LatestBlockHeight for { diff --git a/relayer/chains/cosmos/query.go b/relayer/chains/cosmos/query.go index 23aa38093..188635934 100644 --- a/relayer/chains/cosmos/query.go +++ b/relayer/chains/cosmos/query.go @@ -394,7 +394,7 @@ func (cc *CosmosProvider) QueryTendermintProof(ctx context.Context, height int64 // Therefore, a query at height 2 would be equivalent to a query at height 3. // A height of 0 will query with the latest state. if height != 0 && height <= 2 { - return nil, nil, clienttypes.Height{}, fmt.Errorf("proof queries at height <= 2 are not supported") + return nil, nil, clienttypes.Height{}, errors.New("proof queries at height <= 2 are not supported") } // Use the IAVL height if a valid tendermint height is passed in. diff --git a/relayer/chains/cosmos/tx.go b/relayer/chains/cosmos/tx.go index 03cf830f3..bf5750969 100644 --- a/relayer/chains/cosmos/tx.go +++ b/relayer/chains/cosmos/tx.go @@ -502,7 +502,7 @@ func (cc *CosmosProvider) waitForBlockInclusion( return cc.mkTxResult(res) } if strings.Contains(err.Error(), "transaction indexing is disabled") { - return nil, fmt.Errorf("cannot determine success/failure of tx because transaction indexing is disabled on rpc url") + return nil, errors.New("cannot determine success/failure of tx because transaction indexing is disabled on rpc url") } case <-ctx.Done(): return nil, ctx.Err() @@ -1038,7 +1038,7 @@ func (cc *CosmosProvider) ConnectionHandshakeProof( // If the connection state proof is empty, there is no point in returning the next message. // We are not using (*conntypes.MsgConnectionOpenTry).ValidateBasic here because // that chokes on cross-chain bech32 details in ibc-go. - return provider.ConnectionProof{}, fmt.Errorf("received invalid zero-length connection state proof") + return provider.ConnectionProof{}, errors.New("received invalid zero-length connection state proof") } return provider.ConnectionProof{ @@ -1474,7 +1474,7 @@ func (cc *CosmosProvider) AcknowledgementFromSequence(ctx context.Context, dst p // QueryIBCHeader returns the IBC compatible block header (TendermintIBCHeader) at a specific height. func (cc *CosmosProvider) QueryIBCHeader(ctx context.Context, h int64) (provider.IBCHeader, error) { if h == 0 { - return nil, fmt.Errorf("height cannot be 0") + return nil, errors.New("height cannot be 0") } lightBlock, err := cc.LightProvider.LightBlock(ctx, h) @@ -1498,7 +1498,7 @@ func (cc *CosmosProvider) InjectTrustedFields(ctx context.Context, header ibcexp // make copy of header stored in mop h, ok := header.(*tmclient.Header) if !ok { - return nil, fmt.Errorf("trying to inject fields into non-tendermint headers") + return nil, errors.New("trying to inject fields into non-tendermint headers") } // retrieve dst client from src chain @@ -1729,7 +1729,7 @@ func (cc *CosmosProvider) AdjustEstimatedGas(gasUsed uint64) (uint64, error) { } gas := cc.PCfg.GasAdjustment * float64(gasUsed) if math.IsInf(gas, 1) { - return 0, fmt.Errorf("infinite gas used") + return 0, errors.New("infinite gas used") } return uint64(gas), nil } @@ -1746,7 +1746,7 @@ func (cc *CosmosProvider) SetWithExtensionOptions(txf tx.Factory) (tx.Factory, e for _, opt := range cc.PCfg.ExtensionOptions { max, ok := sdkmath.NewIntFromString(opt.Value) if !ok { - return txf, fmt.Errorf("invalid opt value") + return txf,errors.New("invalid opt value") } extensionOption := ethermint.ExtensionOptionDynamicFeeTx{ MaxPriorityPrice: max, @@ -1926,7 +1926,7 @@ func BuildSimTx(info *keyring.Record, txf tx.Factory, msgs ...sdk.Msg) ([]byte, protoProvider, ok := txb.(protoTxProvider) if !ok { - return nil, fmt.Errorf("cannot simulate amino tx") + return nil, errors.New("cannot simulate amino tx") } simReq := txtypes.SimulateRequest{Tx: protoProvider.GetProtoTx()} diff --git a/relayer/chains/cosmos/tx_test.go b/relayer/chains/cosmos/tx_test.go index 4e9bdcb11..4bdb53031 100644 --- a/relayer/chains/cosmos/tx_test.go +++ b/relayer/chains/cosmos/tx_test.go @@ -1,7 +1,7 @@ package cosmos import ( - "fmt" + "errors" "math" "testing" @@ -48,7 +48,7 @@ func TestCosmosProvider_AdjustEstimatedGas(t *testing.T) { gasAdjustment: math.Inf(1), maxGasAmount: 0, expectedGas: 0, - expectedErr: fmt.Errorf("infinite gas used"), + expectedErr: errors.New("infinite gas used"), }, { name: "gas used is non-zero with zero max gas amount as default", @@ -64,7 +64,7 @@ func TestCosmosProvider_AdjustEstimatedGas(t *testing.T) { gasAdjustment: 1.5, maxGasAmount: 70000, expectedGas: 75000, - expectedErr: fmt.Errorf("estimated gas 75000 is higher than max gas 70000"), + expectedErr: errors.New("estimated gas 75000 is higher than max gas 70000"), }, } diff --git a/relayer/chains/penumbra/grpc_query.go b/relayer/chains/penumbra/grpc_query.go index 9a3de2229..a66951248 100644 --- a/relayer/chains/penumbra/grpc_query.go +++ b/relayer/chains/penumbra/grpc_query.go @@ -2,7 +2,7 @@ package penumbra import ( "context" - "fmt" + "errors" "reflect" "strconv" "sync" @@ -87,7 +87,7 @@ func (cc *PenumbraProvider) Invoke(ctx context.Context, method string, req, repl // NewStream implements the grpc ClientConn.NewStream method func (cc *PenumbraProvider) NewStream(context.Context, *grpc.StreamDesc, string, ...grpc.CallOption) (grpc.ClientStream, error) { - return nil, fmt.Errorf("streaming rpc not supported") + return nil, errors.New("streaming rpc not supported") } // RunGRPCQuery runs a gRPC query from the clientCtx, given all necessary diff --git a/relayer/chains/penumbra/provider.go b/relayer/chains/penumbra/provider.go index 603a2a4fc..9145302af 100644 --- a/relayer/chains/penumbra/provider.go +++ b/relayer/chains/penumbra/provider.go @@ -2,6 +2,7 @@ package penumbra import ( "context" + "errors" "fmt" "io" "os" @@ -386,7 +387,7 @@ func (cc *PenumbraProvider) WaitForNBlocks(ctx context.Context, n int64) error { return err } if h.SyncInfo.CatchingUp { - return fmt.Errorf("chain catching up") + return errors.New("chain catching up") } initial = h.SyncInfo.LatestBlockHeight for { diff --git a/relayer/chains/penumbra/query.go b/relayer/chains/penumbra/query.go index 20c64dde5..615428799 100644 --- a/relayer/chains/penumbra/query.go +++ b/relayer/chains/penumbra/query.go @@ -168,7 +168,7 @@ func (cc *PenumbraProvider) QueryTendermintProof(ctx context.Context, height int // Therefore, a query at height 2 would be equivalent to a query at height 3. // A height of 0 will query with the latest state. if height != 0 && height <= 2 { - return nil, nil, clienttypes.Height{}, fmt.Errorf("proof queries at height <= 2 are not supported") + return nil, nil, clienttypes.Height{}, errors.New("proof queries at height <= 2 are not supported") } if height != 0 { diff --git a/relayer/chains/penumbra/tx.go b/relayer/chains/penumbra/tx.go index 8262891be..dbf8a2547 100644 --- a/relayer/chains/penumbra/tx.go +++ b/relayer/chains/penumbra/tx.go @@ -565,7 +565,7 @@ func (cc *PenumbraProvider) ConnectionOpenTry(ctx context.Context, dstQueryProvi // If the connection state proof is empty, there is no point in returning the MsgConnectionOpenTry. // We are not using (*conntypes.MsgConnectionOpenTry).ValidateBasic here because // that chokes on cross-chain bech32 details in ibc-go. - return nil, fmt.Errorf("received invalid zero-length connection state proof") + return nil, errors.New("received invalid zero-length connection state proof") } if acc, err = cc.Address(); err != nil { @@ -752,7 +752,7 @@ func (cc *PenumbraProvider) ChannelOpenTry(ctx context.Context, dstQueryProvider // If the connection state proof is empty, there is no point in returning the MsgChannelOpenTry. // We are not using (*conntypes.MsgChannelOpenTry).ValidateBasic here because // that chokes on cross-chain bech32 details in ibc-go. - return nil, fmt.Errorf("received invalid zero-length channel state proof") + return nil, errors.New("received invalid zero-length channel state proof") } if acc, err = cc.Address(); err != nil { @@ -1355,7 +1355,7 @@ func (cc *PenumbraProvider) ConnectionHandshakeProof(ctx context.Context, msgOpe // If the connection state proof is empty, there is no point in returning the next message. // We are not using (*conntypes.MsgConnectionOpenTry).ValidateBasic here because // that chokes on cross-chain bech32 details in ibc-go. - return provider.ConnectionProof{}, fmt.Errorf("received invalid zero-length connection state proof") + return provider.ConnectionProof{}, errors.New("received invalid zero-length connection state proof") } return provider.ConnectionProof{ @@ -1737,9 +1737,9 @@ func (cc *PenumbraProvider) AcknowledgementFromSequence(ctx context.Context, dst case err != nil: return nil, err case len(txs) == 0: - return nil, fmt.Errorf("no transactions returned with query") + return nil, errors.New("no transactions returned with query") case len(txs) > 1: - return nil, fmt.Errorf("more than one transaction returned with query") + return nil, errors.New("more than one transaction returned with query") } acks, err := cc.acknowledgementsFromResultTx(dstChanId, dstPortId, srcChanId, srcPortId, txs[0]) @@ -1747,7 +1747,7 @@ func (cc *PenumbraProvider) AcknowledgementFromSequence(ctx context.Context, dst case err != nil: return nil, err case len(acks) == 0: - return nil, fmt.Errorf("no ack msgs created from query response") + return nil, errors.New("no ack msgs created from query response") } var out provider.RelayerMessage @@ -1860,7 +1860,7 @@ EventLoop: return ackPackets, nil } - return nil, fmt.Errorf("no packet data found") + return nil, errors.New("no packet data found") } // GetIBCUpdateHeader updates the off chain tendermint light client and @@ -1880,7 +1880,7 @@ func (cc *PenumbraProvider) GetIBCUpdateHeader(ctx context.Context, srch int64, func (cc *PenumbraProvider) IBCHeaderAtHeight(ctx context.Context, h int64) (provider.IBCHeader, error) { if h == 0 { - return nil, fmt.Errorf("height cannot be 0") + return nil, errors.New("height cannot be 0") } lightBlock, err := cc.LightProvider.LightBlock(ctx, h) @@ -1896,7 +1896,7 @@ func (cc *PenumbraProvider) IBCHeaderAtHeight(ctx context.Context, h int64) (pro func (cc *PenumbraProvider) GetLightSignedHeaderAtHeight(ctx context.Context, h int64) (ibcexported.ClientMessage, error) { if h == 0 { - return nil, fmt.Errorf("height cannot be 0") + return nil, errors.New("height cannot be 0") } lightBlock, err := cc.LightProvider.LightBlock(ctx, h) @@ -1925,7 +1925,7 @@ func (cc *PenumbraProvider) InjectTrustedFields(ctx context.Context, header ibce // make copy of header stored in mop h, ok := header.(*tmclient.Header) if !ok { - return nil, fmt.Errorf("trying to inject fields into non-tendermint headers") + return nil, errors.New("trying to inject fields into non-tendermint headers") } // retrieve dst client from src chain @@ -1953,7 +1953,7 @@ func (cc *PenumbraProvider) InjectTrustedFields(ctx context.Context, header ibce th, ok := tmpHeader.(*tmclient.Header) if !ok { - err = fmt.Errorf("non-tm client header") + err = errors.New("non-tm client header") } trustedHeader = th @@ -1991,8 +1991,7 @@ func castClientStateToTMType(cs *codectypes.Any) (*tmclient.ClientState, error) // cast from interface to concrete type clientState, ok := clientStateExported.(*tmclient.ClientState) if !ok { - return &tmclient.ClientState{}, - fmt.Errorf("error when casting exported clientstate to tendermint type") + return &tmclient.ClientState{}, errors.New("error when casting exported clientstate to tendermint type") } return clientState, nil @@ -2058,7 +2057,7 @@ func (cc *PenumbraProvider) NewClientState( // QueryIBCHeader returns the IBC compatible block header (CosmosIBCHeader) at a specific height. func (cc *PenumbraProvider) QueryIBCHeader(ctx context.Context, h int64) (provider.IBCHeader, error) { if h == 0 { - return nil, fmt.Errorf("height cannot be 0") + return nil, errors.New("height cannot be 0") } lightBlock, err := cc.LightProvider.LightBlock(ctx, h) @@ -2172,7 +2171,7 @@ func (cc *PenumbraProvider) broadcastTx( if isFailed { err = cc.sdkError(res.Codespace, res.Code) if err == nil { - err = fmt.Errorf("transaction failed to execute") + err = errors.New("transaction failed to execute") } } cc.LogFailedTx(rlyResp, err, msgs) @@ -2222,7 +2221,7 @@ func (cc *PenumbraProvider) waitForTx( // Check for any registered SDK errors err := cc.sdkError(res.Codespace, res.Code) if err == nil { - err = fmt.Errorf("transaction failed to execute") + err = errors.New("transaction failed to execute") } if callback != nil { callback(nil, err) @@ -2255,7 +2254,7 @@ func (cc *PenumbraProvider) waitForBlockInclusion( return cc.mkTxResult(res) } if strings.Contains(err.Error(), "transaction indexing is disabled") { - return nil, fmt.Errorf("cannot determine success/failure of tx because transaction indexing is disabled on rpc url") + return nil,errors.New("cannot determine success/failure of tx because transaction indexing is disabled on rpc url") } case <-ctx.Done(): return nil, ctx.Err() diff --git a/relayer/client.go b/relayer/client.go index 0ad34b1bc..061d71580 100644 --- a/relayer/client.go +++ b/relayer/client.go @@ -2,6 +2,7 @@ package relayer import ( "context" + "errors" "fmt" "time" @@ -564,7 +565,7 @@ func parseClientIDFromEvents(events []provider.RelayerEvent) (string, error) { } } - return "", fmt.Errorf("client identifier event attribute not found") + return "", errors.New("client identifier event attribute not found") } type ClientStateInfo struct { diff --git a/relayer/events.go b/relayer/events.go index b997d6b63..38078c471 100644 --- a/relayer/events.go +++ b/relayer/events.go @@ -1,7 +1,7 @@ package relayer import ( - "fmt" + "errors" clienttypes "github.com/cosmos/ibc-go/v8/modules/core/02-client/types" connectiontypes "github.com/cosmos/ibc-go/v8/modules/core/03-connection/types" @@ -21,7 +21,7 @@ func ParseClientIDFromEvents(events []provider.RelayerEvent) (string, error) { } } } - return "", fmt.Errorf("client identifier event attribute not found") + return "", errors.New("client identifier event attribute not found") } // ParseConnectionIDFromEvents parses events emitted from a MsgConnectionOpenInit or @@ -36,7 +36,7 @@ func ParseConnectionIDFromEvents(events []provider.RelayerEvent) (string, error) } } } - return "", fmt.Errorf("connection identifier event attribute not found") + return "", errors.New("connection identifier event attribute not found") } // ParseChannelIDFromEvents parses events emitted from a MsgChannelOpenInit or @@ -51,5 +51,5 @@ func ParseChannelIDFromEvents(events []provider.RelayerEvent) (string, error) { } } } - return "", fmt.Errorf("channel identifier event attribute not found") + return "", errors.New("channel identifier event attribute not found") } diff --git a/relayer/relaymsgs_test.go b/relayer/relaymsgs_test.go index dab099072..02f997492 100644 --- a/relayer/relaymsgs_test.go +++ b/relayer/relaymsgs_test.go @@ -2,7 +2,7 @@ package relayer_test import ( "context" - "fmt" + "errors" "testing" "github.com/cosmos/relayer/v2/relayer" @@ -147,7 +147,7 @@ func TestRelayMsgs_Send_Success(t *testing.T) { func TestRelayMsgs_Send_Errors(t *testing.T) { t.Run("one batch and one error", func(t *testing.T) { - srcErr := fmt.Errorf("source error") + srcErr := errors.New("source error") src := relayer.RelayMsgSender{ ChainID: "src", SendMessages: func(ctx context.Context, msgs []provider.RelayerMessage, memo string) (*provider.RelayerTxResponse, bool, error) { @@ -155,7 +155,7 @@ func TestRelayMsgs_Send_Errors(t *testing.T) { }, } - dstErr := fmt.Errorf("dest error") + dstErr := errors.New("dest error") dst := relayer.RelayMsgSender{ ChainID: "dst", SendMessages: func(ctx context.Context, msgs []provider.RelayerMessage, memo string) (*provider.RelayerTxResponse, bool, error) { @@ -179,7 +179,7 @@ func TestRelayMsgs_Send_Errors(t *testing.T) { }) t.Run("multiple batches and all errors", func(t *testing.T) { - srcErr1, srcErr2 := fmt.Errorf("source error 1"), fmt.Errorf("source error 2") + srcErr1, srcErr2 := errors.New("source error 1"), errors.New("source error 2") var srcCalls int src := relayer.RelayMsgSender{ ChainID: "src", @@ -196,7 +196,7 @@ func TestRelayMsgs_Send_Errors(t *testing.T) { }, } - dstErr1, dstErr2 := fmt.Errorf("dest error 1"), fmt.Errorf("dest error 2") + dstErr1, dstErr2 := errors.New("dest error 1"), errors.New("dest error 2") var dstCalls int dst := relayer.RelayMsgSender{ ChainID: "dst", @@ -233,7 +233,7 @@ func TestRelayMsgs_Send_Errors(t *testing.T) { }) t.Run("two batches with success then error", func(t *testing.T) { - srcErr := fmt.Errorf("source error") + srcErr := errors.New("source error") var srcCalls int src := relayer.RelayMsgSender{ ChainID: "src", @@ -250,7 +250,7 @@ func TestRelayMsgs_Send_Errors(t *testing.T) { }, } - dstErr := fmt.Errorf("dest error") + dstErr := errors.New("dest error") var dstCalls int dst := relayer.RelayMsgSender{ ChainID: "dst", diff --git a/relayer/strategies.go b/relayer/strategies.go index 274e38a2b..8779408a0 100644 --- a/relayer/strategies.go +++ b/relayer/strategies.go @@ -245,7 +245,7 @@ func relayerStartLegacy( // at startup but after some time has passed a channel needs opened and relayed on. At this point we // could choose to loop here until some action is needed. if len(srcOpenChannels) == 0 { - errCh <- fmt.Errorf("there are no open channels to relay on") + errCh <- errors.New("there are no open channels to relay on") return }