Skip to content

Commit db4cf69

Browse files
yzbyzb@example.cn
andauthored
all: replace fmt.Errorf() with errors.New() if no param required (ethereum#29126)
replace-fmt-errorf Co-authored-by: yzb@example.cn <yzb@example.cn>
1 parent 28d5521 commit db4cf69

23 files changed

Lines changed: 45 additions & 35 deletions

File tree

cmd/era/main.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package main
1818

1919
import (
2020
"encoding/json"
21+
"errors"
2122
"fmt"
2223
"math/big"
2324
"os"
@@ -182,7 +183,7 @@ func open(ctx *cli.Context, epoch uint64) (*era.Era, error) {
182183
// that the accumulator matches the expected value.
183184
func verify(ctx *cli.Context) error {
184185
if ctx.Args().Len() != 1 {
185-
return fmt.Errorf("missing accumulators file")
186+
return errors.New("missing accumulators file")
186187
}
187188

188189
roots, err := readHashes(ctx.Args().First())
@@ -203,7 +204,7 @@ func verify(ctx *cli.Context) error {
203204
}
204205

205206
if len(entries) != len(roots) {
206-
return fmt.Errorf("number of era1 files should match the number of accumulator hashes")
207+
return errors.New("number of era1 files should match the number of accumulator hashes")
207208
}
208209

209210
// Verify each epoch matches the expected root.
@@ -308,7 +309,7 @@ func checkAccumulator(e *era.Era) error {
308309
func readHashes(f string) ([]common.Hash, error) {
309310
b, err := os.ReadFile(f)
310311
if err != nil {
311-
return nil, fmt.Errorf("unable to open accumulators file")
312+
return nil, errors.New("unable to open accumulators file")
312313
}
313314
s := strings.Split(string(b), "\n")
314315
// Remove empty last element, if present.

cmd/geth/chaincmd.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,7 @@ func importHistory(ctx *cli.Context) error {
444444
return fmt.Errorf("no era1 files found in %s", dir)
445445
}
446446
if len(networks) > 1 {
447-
return fmt.Errorf("multiple networks found, use a network flag to specify desired network")
447+
return errors.New("multiple networks found, use a network flag to specify desired network")
448448
}
449449
network = networks[0]
450450
}

cmd/utils/cmd.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ func readList(filename string) ([]string, error) {
245245
// starting from genesis.
246246
func ImportHistory(chain *core.BlockChain, db ethdb.Database, dir string, network string) error {
247247
if chain.CurrentSnapBlock().Number.BitLen() != 0 {
248-
return fmt.Errorf("history import only supported when starting from genesis")
248+
return errors.New("history import only supported when starting from genesis")
249249
}
250250
entries, err := era.ReadDir(dir, network)
251251
if err != nil {

core/txpool/validation.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package txpool
1818

1919
import (
2020
"crypto/sha256"
21+
"errors"
2122
"fmt"
2223
"math/big"
2324

@@ -120,13 +121,13 @@ func ValidateTransaction(tx *types.Transaction, head *types.Header, signer types
120121
}
121122
sidecar := tx.BlobTxSidecar()
122123
if sidecar == nil {
123-
return fmt.Errorf("missing sidecar in blob transaction")
124+
return errors.New("missing sidecar in blob transaction")
124125
}
125126
// Ensure the number of items in the blob transaction and various side
126127
// data match up before doing any expensive validations
127128
hashes := tx.BlobHashes()
128129
if len(hashes) == 0 {
129-
return fmt.Errorf("blobless blob transaction")
130+
return errors.New("blobless blob transaction")
130131
}
131132
if len(hashes) > params.MaxBlobGasPerBlock/params.BlobTxBlobGasPerBlob {
132133
return fmt.Errorf("too many blobs in transaction: have %d, permitted %d", len(hashes), params.MaxBlobGasPerBlock/params.BlobTxBlobGasPerBlob)

internal/era/accumulator.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package era
1818

1919
import (
20+
"errors"
2021
"fmt"
2122
"math/big"
2223

@@ -28,7 +29,7 @@ import (
2829
// accumulator of header records.
2930
func ComputeAccumulator(hashes []common.Hash, tds []*big.Int) (common.Hash, error) {
3031
if len(hashes) != len(tds) {
31-
return common.Hash{}, fmt.Errorf("must have equal number hashes as td values")
32+
return common.Hash{}, errors.New("must have equal number hashes as td values")
3233
}
3334
if len(hashes) > MaxEra1Size {
3435
return common.Hash{}, fmt.Errorf("too many records: have %d, max %d", len(hashes), MaxEra1Size)

internal/era/builder.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package era
1818
import (
1919
"bytes"
2020
"encoding/binary"
21+
"errors"
2122
"fmt"
2223
"io"
2324
"math/big"
@@ -158,7 +159,7 @@ func (b *Builder) AddRLP(header, body, receipts []byte, number uint64, hash comm
158159
// corresponding e2store entries.
159160
func (b *Builder) Finalize() (common.Hash, error) {
160161
if b.startNum == nil {
161-
return common.Hash{}, fmt.Errorf("finalize called on empty builder")
162+
return common.Hash{}, errors.New("finalize called on empty builder")
162163
}
163164
// Compute accumulator root and write entry.
164165
root, err := ComputeAccumulator(b.hashes, b.tds)

internal/era/e2store/e2store.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package e2store
1818

1919
import (
2020
"encoding/binary"
21+
"errors"
2122
"fmt"
2223
"io"
2324
)
@@ -160,7 +161,7 @@ func (r *Reader) ReadMetadataAt(off int64) (typ uint16, length uint32, err error
160161

161162
// Check reserved bytes of header.
162163
if b[6] != 0 || b[7] != 0 {
163-
return 0, 0, fmt.Errorf("reserved bytes are non-zero")
164+
return 0, 0, errors.New("reserved bytes are non-zero")
164165
}
165166

166167
return typ, length, nil

internal/era/e2store/e2store_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ package e2store
1818

1919
import (
2020
"bytes"
21-
"fmt"
21+
"errors"
2222
"io"
2323
"testing"
2424

@@ -92,7 +92,7 @@ func TestDecode(t *testing.T) {
9292
},
9393
{ // basic invalid decoding
9494
have: "ffff000000000001",
95-
err: fmt.Errorf("reserved bytes are non-zero"),
95+
err: errors.New("reserved bytes are non-zero"),
9696
},
9797
{ // no more entries to read, returns EOF
9898
have: "",

internal/era/era.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package era
1818

1919
import (
2020
"encoding/binary"
21+
"errors"
2122
"fmt"
2223
"io"
2324
"math/big"
@@ -127,7 +128,7 @@ func (e *Era) Close() error {
127128

128129
func (e *Era) GetBlockByNumber(num uint64) (*types.Block, error) {
129130
if e.m.start > num || e.m.start+e.m.count <= num {
130-
return nil, fmt.Errorf("out-of-bounds")
131+
return nil, errors.New("out-of-bounds")
131132
}
132133
off, err := e.readOffset(num)
133134
if err != nil {

internal/era/iterator.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package era
1818

1919
import (
20+
"errors"
2021
"fmt"
2122
"io"
2223
"math/big"
@@ -61,7 +62,7 @@ func (it *Iterator) Error() error {
6162
// Block returns the block for the iterator's current position.
6263
func (it *Iterator) Block() (*types.Block, error) {
6364
if it.inner.Header == nil || it.inner.Body == nil {
64-
return nil, fmt.Errorf("header and body must be non-nil")
65+
return nil, errors.New("header and body must be non-nil")
6566
}
6667
var (
6768
header types.Header

0 commit comments

Comments
 (0)