chore(all): replace all fmt.Errorf without paramters with errors.New (#21068)

This commit is contained in:
yukionfire
2024-07-25 14:54:49 +02:00
committed by GitHub
parent 6a2d039e12
commit d6ad92db0f
57 changed files with 127 additions and 103 deletions
+3 -2
View File
@@ -3,6 +3,7 @@ package server
import (
"context"
"encoding/json"
"errors"
"fmt"
"strconv"
"strings"
@@ -239,7 +240,7 @@ $ %s query block --%s=%s <hash>
case auth.TypeHeight:
if args[0] == "" {
return fmt.Errorf("argument should be a block height")
return errors.New("argument should be a block height")
}
// optional height
@@ -265,7 +266,7 @@ $ %s query block --%s=%s <hash>
case auth.TypeHash:
if args[0] == "" {
return fmt.Errorf("argument should be a tx hash")
return errors.New("argument should be a tx hash")
}
// If hash is given, then query the tx by hash.
@@ -162,7 +162,7 @@ func newTxDescriptor(ir codectypes.InterfaceRegistry) (*TxDescriptor, error) {
// get base tx type name
txPbName := proto.MessageName(&tx.Tx{})
if txPbName == "" {
return nil, fmt.Errorf("unable to get *tx.Tx protobuf name")
return nil, errors.New("unable to get *tx.Tx protobuf name")
}
// get msgs
sdkMsgImplementers := ir.ListImplementations(sdk.MsgInterfaceProtoName)
+3 -2
View File
@@ -3,6 +3,7 @@ package telemetry
import (
"bytes"
"encoding/json"
"errors"
"fmt"
"net/http"
"time"
@@ -145,7 +146,7 @@ func (m *Metrics) Gather(format string) (GatherResponse, error) {
// If Prometheus metrics are not enabled, it returns an error.
func (m *Metrics) gatherPrometheus() (GatherResponse, error) {
if !m.prometheusEnabled {
return GatherResponse{}, fmt.Errorf("prometheus metrics are not enabled")
return GatherResponse{}, errors.New("prometheus metrics are not enabled")
}
metricsFamilies, err := prometheus.DefaultGatherer.Gather()
@@ -171,7 +172,7 @@ func (m *Metrics) gatherPrometheus() (GatherResponse, error) {
func (m *Metrics) gatherGeneric() (GatherResponse, error) {
gm, ok := m.sink.(DisplayableSink)
if !ok {
return GatherResponse{}, fmt.Errorf("non in-memory metrics sink does not support generic format")
return GatherResponse{}, errors.New("non in-memory metrics sink does not support generic format")
}
summary, err := gm.DisplayMetrics(nil, nil)
+2 -1
View File
@@ -4,6 +4,7 @@ import (
"bytes"
"context"
"encoding/json"
"errors"
"fmt"
appmanager "cosmossdk.io/core/app"
@@ -46,7 +47,7 @@ func (a AppManager[T]) InitGenesis(
return nil, nil, fmt.Errorf("unable to get latest state: %w", err)
}
if v != 0 { // TODO: genesis state may be > 0, we need to set version on store
return nil, nil, fmt.Errorf("cannot init genesis on non-zero state")
return nil, nil, errors.New("cannot init genesis on non-zero state")
}
var genTxs []T
+2 -2
View File
@@ -543,7 +543,7 @@ func (c *Consensus[T]) VerifyVoteExtension(
}
if c.verifyVoteExt == nil {
return nil, fmt.Errorf("vote extensions are enabled but no verify function was set")
return nil, errors.New("vote extensions are enabled but no verify function was set")
}
_, latestStore, err := c.store.StateLatest()
@@ -579,7 +579,7 @@ func (c *Consensus[T]) ExtendVote(ctx context.Context, req *abciproto.ExtendVote
}
if c.verifyVoteExt == nil {
return nil, fmt.Errorf("vote extensions are enabled but no verify function was set")
return nil, errors.New("vote extensions are enabled but no verify function was set")
}
_, latestStore, err := c.store.StateLatest()
+3 -2
View File
@@ -2,6 +2,7 @@ package cometbft
import (
"encoding/json"
"errors"
"fmt"
"strconv"
"strings"
@@ -253,7 +254,7 @@ $ %s query block --%s=%s <hash>
switch typ {
case TypeHeight:
if args[0] == "" {
return fmt.Errorf("argument should be a block height")
return errors.New("argument should be a block height")
}
// optional height
@@ -284,7 +285,7 @@ $ %s query block --%s=%s <hash>
case TypeHash:
if args[0] == "" {
return fmt.Errorf("argument should be a tx hash")
return errors.New("argument should be a tx hash")
}
// If hash is given, then query the tx by hash.
+1 -1
View File
@@ -140,7 +140,7 @@ func (h *DefaultProposalHandler[T]) ProcessHandler() ProcessHandler[T] {
if maxBlockGas > 0 {
gaslimit, err := tx.GetGasLimit()
if err != nil {
return fmt.Errorf("failed to get gas limit")
return errors.New("failed to get gas limit")
}
totalTxGas += gaslimit
if totalTxGas > maxBlockGas {
+2 -1
View File
@@ -2,6 +2,7 @@ package cometbft
import (
"context"
"errors"
"fmt"
"math"
"strings"
@@ -296,7 +297,7 @@ func (c *Consensus[T]) GetConsensusParams(ctx context.Context) (*cmtproto.Consen
}
if r, ok := res.(*consensus.QueryParamsResponse); !ok {
return nil, fmt.Errorf("failed to query consensus params")
return nil, errors.New("failed to query consensus params")
} else {
// convert our params to cometbft params
evidenceMaxDuration := r.Params.Evidence.MaxAgeDuration
+2 -2
View File
@@ -2,7 +2,7 @@ package stf
import (
"context"
"fmt"
"errors"
"testing"
gogotypes "github.com/cosmos/gogoproto/types"
@@ -70,7 +70,7 @@ func TestBranchService(t *testing.T) {
stfCtx := makeContext()
gasUsed, err := branchService.ExecuteWithGasLimit(stfCtx, 10000, func(ctx context.Context) error {
kvSet(t, ctx, "cookies")
return fmt.Errorf("fail")
return errors.New("fail")
})
require.Error(t, err)
require.NotZero(t, gasUsed)
+6 -6
View File
@@ -3,7 +3,7 @@ package stf
import (
"context"
"crypto/sha256"
"fmt"
"errors"
"testing"
"time"
@@ -158,7 +158,7 @@ func TestSTF(t *testing.T) {
// update the stf to fail on the handler
s := s.clone()
addMsgHandlerToSTF(t, &s, func(ctx context.Context, msg *gogotypes.BoolValue) (*gogotypes.BoolValue, error) {
return nil, fmt.Errorf("failure")
return nil, errors.New("failure")
})
blockResult, newState, err := s.DeliverBlock(context.Background(), &appmanager.BlockRequest[mock.Tx]{
@@ -180,7 +180,7 @@ func TestSTF(t *testing.T) {
t.Run("tx is success but post tx failed", func(t *testing.T) {
s := s.clone()
s.postTxExec = func(ctx context.Context, tx mock.Tx, success bool) error {
return fmt.Errorf("post tx failure")
return errors.New("post tx failure")
}
blockResult, newState, err := s.DeliverBlock(context.Background(), &appmanager.BlockRequest[mock.Tx]{
Height: uint64(1),
@@ -201,9 +201,9 @@ func TestSTF(t *testing.T) {
t.Run("tx failed and post tx failed", func(t *testing.T) {
s := s.clone()
addMsgHandlerToSTF(t, &s, func(ctx context.Context, msg *gogotypes.BoolValue) (*gogotypes.BoolValue, error) {
return nil, fmt.Errorf("exec failure")
return nil, errors.New("exec failure")
})
s.postTxExec = func(ctx context.Context, tx mock.Tx, success bool) error { return fmt.Errorf("post tx failure") }
s.postTxExec = func(ctx context.Context, tx mock.Tx, success bool) error { return errors.New("post tx failure") }
blockResult, newState, err := s.DeliverBlock(context.Background(), &appmanager.BlockRequest[mock.Tx]{
Height: uint64(1),
Time: time.Date(2024, 2, 3, 18, 23, 0, 0, time.UTC),
@@ -223,7 +223,7 @@ func TestSTF(t *testing.T) {
t.Run("fail validate tx", func(t *testing.T) {
// update stf to fail on the validation step
s := s.clone()
s.doTxValidation = func(ctx context.Context, tx mock.Tx) error { return fmt.Errorf("failure") }
s.doTxValidation = func(ctx context.Context, tx mock.Tx) error { return errors.New("failure") }
blockResult, newState, err := s.DeliverBlock(context.Background(), &appmanager.BlockRequest[mock.Tx]{
Height: uint64(1),
Time: time.Date(2024, 2, 3, 18, 23, 0, 0, time.UTC),