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
+2 -1
View File
@@ -2,6 +2,7 @@ package types
import (
"encoding/binary"
"errors"
"fmt"
"time"
@@ -255,7 +256,7 @@ var timeSize = len(FormatTimeBytes(time.Time{}))
func (timeKeyCodec) Decode(buffer []byte) (int, time.Time, error) {
if len(buffer) != timeSize {
return 0, time.Time{}, fmt.Errorf("invalid time buffer size")
return 0, time.Time{}, errors.New("invalid time buffer size")
}
t, err := ParseTimeBytes(buffer)
if err != nil {
+2 -1
View File
@@ -1,6 +1,7 @@
package mempool_test
import (
"errors"
"fmt"
"math/rand"
"testing"
@@ -217,7 +218,7 @@ func (s *MempoolTestSuite) TestDefaultMempool() {
// a tx which does not implement SigVerifiableTx should not be inserted
tx := &sigErrTx{getSigs: func() ([]txsigning.SignatureV2, error) {
return nil, fmt.Errorf("error")
return nil, errors.New("error")
}}
require.Error(t, s.mempool.Insert(ctx, tx))
require.Error(t, s.mempool.Remove(tx))
+4 -3
View File
@@ -2,6 +2,7 @@ package mempool
import (
"context"
"errors"
"fmt"
"math"
"sync"
@@ -215,7 +216,7 @@ func (mp *PriorityNonceMempool[C]) Insert(ctx context.Context, tx sdk.Tx) error
return err
}
if len(sigs) == 0 {
return fmt.Errorf("tx must have at least one signer")
return errors.New("tx must have at least one signer")
}
sig := sigs[0]
@@ -436,7 +437,7 @@ func (mp *PriorityNonceMempool[C]) Remove(tx sdk.Tx) error {
return err
}
if len(sigs) == 0 {
return fmt.Errorf("attempted to remove a tx with no signatures")
return errors.New("attempted to remove a tx with no signatures")
}
sig := sigs[0]
@@ -466,7 +467,7 @@ func (mp *PriorityNonceMempool[C]) Remove(tx sdk.Tx) error {
func IsEmpty[C comparable](mempool Mempool) error {
mp := mempool.(*PriorityNonceMempool[C])
if mp.priorityIndex.Len() != 0 {
return fmt.Errorf("priorityIndex not empty")
return errors.New("priorityIndex not empty")
}
countKeys := make([]C, 0, len(mp.priorityCounts))
+3 -3
View File
@@ -4,7 +4,7 @@ import (
"context"
crand "crypto/rand" // #nosec // crypto/rand is used for seed generation
"encoding/binary"
"fmt"
"errors"
"math/rand" // #nosec // math/rand is used for random selection and seeded from crypto/rand
"sync"
@@ -133,7 +133,7 @@ func (snm *SenderNonceMempool) Insert(_ context.Context, tx sdk.Tx) error {
return err
}
if len(sigs) == 0 {
return fmt.Errorf("tx must have at least one signer")
return errors.New("tx must have at least one signer")
}
sig := sigs[0]
@@ -206,7 +206,7 @@ func (snm *SenderNonceMempool) Remove(tx sdk.Tx) error {
return err
}
if len(sigs) == 0 {
return fmt.Errorf("tx must have at least one signer")
return errors.New("tx must have at least one signer")
}
sig := sigs[0]
@@ -1,6 +1,7 @@
package mempool_test
import (
"errors"
"fmt"
"math/rand"
"testing"
@@ -52,7 +53,7 @@ func TestDefaultSignerExtractor(t *testing.T) {
ext := mempool.NewDefaultSignerExtractionAdapter()
goodTx := testTx{id: 0, priority: 0, nonce: 0, address: sa}
badTx := &sigErrTx{getSigs: func() ([]txsigning.SignatureV2, error) {
return nil, fmt.Errorf("error")
return nil, errors.New("error")
}}
nonSigVerify := nonVerifiableTx{}
@@ -63,7 +64,7 @@ func TestDefaultSignerExtractor(t *testing.T) {
err error
}{
{name: "valid tx extracts sigs", tx: goodTx, sea: ext, err: nil},
{name: "invalid tx fails on sig", tx: badTx, sea: ext, err: fmt.Errorf("err")},
{name: "invalid tx fails on sig", tx: badTx, sea: ext, err: errors.New("err")},
{name: "non-verifiable tx fails on conversion", tx: nonSigVerify, sea: ext, err: fmt.Errorf("tx of type %T does not implement SigVerifiableTx", nonSigVerify)},
}
for _, test := range tests {
+1 -2
View File
@@ -3,7 +3,6 @@ package query
import (
"context"
"errors"
"fmt"
"cosmossdk.io/collections"
collcodec "cosmossdk.io/collections/codec"
@@ -87,7 +86,7 @@ func CollectionFilteredPaginate[K, V any, C Collection[K, V], T any](
reverse := pageReq.Reverse
if offset > 0 && key != nil {
return nil, nil, fmt.Errorf("invalid request, either offset or key is expected, got both")
return nil, nil, errors.New("invalid request, either offset or key is expected, got both")
}
opt := new(CollectionsPaginateOptions[K])
+3 -3
View File
@@ -1,7 +1,7 @@
package query
import (
"fmt"
"errors"
"github.com/cosmos/gogoproto/proto"
@@ -26,7 +26,7 @@ func FilteredPaginate(
pageRequest = initPageRequestDefaults(pageRequest)
if pageRequest.Offset > 0 && pageRequest.Key != nil {
return nil, fmt.Errorf("invalid request, either offset or key is expected, got both")
return nil, errors.New("invalid request, either offset or key is expected, got both")
}
var (
@@ -151,7 +151,7 @@ func GenericFilteredPaginate[T, F proto.Message](
results := []F{}
if pageRequest.Offset > 0 && pageRequest.Key != nil {
return results, nil, fmt.Errorf("invalid request, either offset or key is expected, got both")
return results, nil, errors.New("invalid request, either offset or key is expected, got both")
}
var (
+2 -2
View File
@@ -1,7 +1,7 @@
package query
import (
"fmt"
"errors"
"math"
db "github.com/cosmos/cosmos-db"
@@ -62,7 +62,7 @@ func Paginate(
pageRequest = initPageRequestDefaults(pageRequest)
if pageRequest.Offset > 0 && pageRequest.Key != nil {
return nil, fmt.Errorf("invalid request, either offset or key is expected, got both")
return nil, errors.New("invalid request, either offset or key is expected, got both")
}
iterator := getIterator(prefixStore, pageRequest.Key, pageRequest.Reverse)
+2 -2
View File
@@ -1,7 +1,7 @@
package simulation
import (
"fmt"
"errors"
"math/rand"
"github.com/cosmos/cosmos-sdk/crypto/keys/ed25519"
@@ -90,7 +90,7 @@ func RandomFees(r *rand.Rand, spendableCoins sdk.Coins) (sdk.Coins, error) {
}
if randCoin.Amount.IsZero() {
return nil, fmt.Errorf("no coins found for random fees")
return nil, errors.New("no coins found for random fees")
}
amt, err := RandPositiveInt(r, randCoin.Amount)