Skip to content

Commit

Permalink
all: use errors.New to replace fmt.Errorf with no parameters (cos…
Browse files Browse the repository at this point in the history
  • Loading branch information
yukionfire authored Jul 24, 2024
1 parent c5dd657 commit 4ed2615
Show file tree
Hide file tree
Showing 20 changed files with 65 additions and 62 deletions.
6 changes: 3 additions & 3 deletions cmd/chains.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions cmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
6 changes: 3 additions & 3 deletions cmd/paths.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions cregistry/chain_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down
4 changes: 2 additions & 2 deletions cregistry/chain_info_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package cregistry

import (
"fmt"
"errors"
"testing"

"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -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"),
},
}

Expand Down
3 changes: 2 additions & 1 deletion interchaintest/relayer.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package interchaintest
import (
"context"
"encoding/json"
"errors"
"fmt"
"strconv"
"strings"
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion relayer/chains/cosmos/feegrant.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
4 changes: 2 additions & 2 deletions relayer/chains/cosmos/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package cosmos

import (
"context"
"fmt"
"errors"
"reflect"
"strconv"
"sync"
Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion relayer/chains/cosmos/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cosmos

import (
"context"
"errors"
"fmt"
"io"
"os"
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion relayer/chains/cosmos/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
14 changes: 7 additions & 7 deletions relayer/chains/cosmos/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -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
}
Expand All @@ -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,
Expand Down Expand Up @@ -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()}
Expand Down
6 changes: 3 additions & 3 deletions relayer/chains/cosmos/tx_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package cosmos

import (
"fmt"
"errors"
"math"
"testing"

Expand Down Expand Up @@ -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",
Expand All @@ -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"),
},
}

Expand Down
4 changes: 2 additions & 2 deletions relayer/chains/penumbra/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package penumbra

import (
"context"
"fmt"
"errors"
"reflect"
"strconv"
"sync"
Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion relayer/chains/penumbra/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package penumbra

import (
"context"
"errors"
"fmt"
"io"
"os"
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion relayer/chains/penumbra/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Loading

0 comments on commit 4ed2615

Please sign in to comment.