Skip to content

Commit b21ba66

Browse files
authored
internal,tests: replace noarg fmt.Errorf with errors.New (ethereum#27335)
* internal: replace noarg fmt.Errorf with errors.New Signed-off-by: jsvisa <delweng@gmail.com> * tests: replace noarg fmt.Errorf with errors.New Signed-off-by: jsvisa <delweng@gmail.com> * tests: go autoimport Signed-off-by: jsvisa <delweng@gmail.com> * tests: go autoimport Signed-off-by: jsvisa <delweng@gmail.com> --------- Signed-off-by: jsvisa <delweng@gmail.com>
1 parent dd25a4f commit b21ba66

File tree

8 files changed

+32
-28
lines changed

8 files changed

+32
-28
lines changed

internal/build/archive.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"archive/tar"
2121
"archive/zip"
2222
"compress/gzip"
23+
"errors"
2324
"fmt"
2425
"io"
2526
"os"
@@ -90,7 +91,7 @@ func WriteArchive(name string, files []string) (err error) {
9091
}()
9192
archive, basename := NewArchive(archfd)
9293
if archive == nil {
93-
return fmt.Errorf("unknown archive extension")
94+
return errors.New("unknown archive extension")
9495
}
9596
fmt.Println(name)
9697
if err := archive.Directory(basename); err != nil {

internal/ethapi/api.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -478,16 +478,16 @@ func (s *PersonalAccountAPI) SignTransaction(ctx context.Context, args Transacti
478478
// No need to obtain the noncelock mutex, since we won't be sending this
479479
// tx into the transaction pool, but right back to the user
480480
if args.From == nil {
481-
return nil, fmt.Errorf("sender not specified")
481+
return nil, errors.New("sender not specified")
482482
}
483483
if args.Gas == nil {
484-
return nil, fmt.Errorf("gas not specified")
484+
return nil, errors.New("gas not specified")
485485
}
486486
if args.GasPrice == nil && (args.MaxFeePerGas == nil || args.MaxPriorityFeePerGas == nil) {
487-
return nil, fmt.Errorf("missing gasPrice or maxFeePerGas/maxPriorityFeePerGas")
487+
return nil, errors.New("missing gasPrice or maxFeePerGas/maxPriorityFeePerGas")
488488
}
489489
if args.Nonce == nil {
490-
return nil, fmt.Errorf("nonce not specified")
490+
return nil, errors.New("nonce not specified")
491491
}
492492
// Before actually signing the transaction, ensure the transaction fee is reasonable.
493493
tx := args.toTransaction()
@@ -548,7 +548,7 @@ func (s *PersonalAccountAPI) EcRecover(ctx context.Context, data, sig hexutil.By
548548
return common.Address{}, fmt.Errorf("signature must be %d bytes long", crypto.SignatureLength)
549549
}
550550
if sig[crypto.RecoveryIDOffset] != 27 && sig[crypto.RecoveryIDOffset] != 28 {
551-
return common.Address{}, fmt.Errorf("invalid Ethereum signature (V is not 27 or 28)")
551+
return common.Address{}, errors.New("invalid Ethereum signature (V is not 27 or 28)")
552552
}
553553
sig[crypto.RecoveryIDOffset] -= 27 // Transform yellow paper V from 27/28 to 0/1
554554

@@ -582,7 +582,7 @@ func (s *PersonalAccountAPI) InitializeWallet(ctx context.Context, url string) (
582582
case *scwallet.Wallet:
583583
return mnemonic, wallet.Initialize(seed)
584584
default:
585-
return "", fmt.Errorf("specified wallet does not support initialization")
585+
return "", errors.New("specified wallet does not support initialization")
586586
}
587587
}
588588

@@ -597,7 +597,7 @@ func (s *PersonalAccountAPI) Unpair(ctx context.Context, url string, pin string)
597597
case *scwallet.Wallet:
598598
return wallet.Unpair([]byte(pin))
599599
default:
600-
return fmt.Errorf("specified wallet does not support pairing")
600+
return errors.New("specified wallet does not support pairing")
601601
}
602602
}
603603

@@ -722,10 +722,10 @@ func decodeHash(s string) (common.Hash, error) {
722722
}
723723
b, err := hex.DecodeString(s)
724724
if err != nil {
725-
return common.Hash{}, fmt.Errorf("hex string invalid")
725+
return common.Hash{}, errors.New("hex string invalid")
726726
}
727727
if len(b) > 32 {
728-
return common.Hash{}, fmt.Errorf("hex string too long, want at most 32 bytes")
728+
return common.Hash{}, errors.New("hex string too long, want at most 32 bytes")
729729
}
730730
return common.BytesToHash(b), nil
731731
}
@@ -1833,13 +1833,13 @@ type SignTransactionResult struct {
18331833
// the given from address and it needs to be unlocked.
18341834
func (s *TransactionAPI) SignTransaction(ctx context.Context, args TransactionArgs) (*SignTransactionResult, error) {
18351835
if args.Gas == nil {
1836-
return nil, fmt.Errorf("gas not specified")
1836+
return nil, errors.New("gas not specified")
18371837
}
18381838
if args.GasPrice == nil && (args.MaxPriorityFeePerGas == nil || args.MaxFeePerGas == nil) {
1839-
return nil, fmt.Errorf("missing gasPrice or maxFeePerGas/maxPriorityFeePerGas")
1839+
return nil, errors.New("missing gasPrice or maxFeePerGas/maxPriorityFeePerGas")
18401840
}
18411841
if args.Nonce == nil {
1842-
return nil, fmt.Errorf("nonce not specified")
1842+
return nil, errors.New("nonce not specified")
18431843
}
18441844
if err := args.setDefaults(ctx, s.b); err != nil {
18451845
return nil, err
@@ -1888,7 +1888,7 @@ func (s *TransactionAPI) PendingTransactions() ([]*RPCTransaction, error) {
18881888
// the given transaction from the pool and reinsert it with the new gas price and limit.
18891889
func (s *TransactionAPI) Resend(ctx context.Context, sendArgs TransactionArgs, gasPrice *hexutil.Big, gasLimit *hexutil.Uint64) (common.Hash, error) {
18901890
if sendArgs.Nonce == nil {
1891-
return common.Hash{}, fmt.Errorf("missing transaction nonce in transaction spec")
1891+
return common.Hash{}, errors.New("missing transaction nonce in transaction spec")
18921892
}
18931893
if err := sendArgs.setDefaults(ctx, s.b); err != nil {
18941894
return common.Hash{}, err

internal/ethapi/transaction_args.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ func (args *TransactionArgs) setFeeDefaults(ctx context.Context, b Backend) erro
157157
}
158158
} else {
159159
if args.MaxFeePerGas != nil || args.MaxPriorityFeePerGas != nil {
160-
return fmt.Errorf("maxFeePerGas and maxPriorityFeePerGas are not valid before London is active")
160+
return errors.New("maxFeePerGas and maxPriorityFeePerGas are not valid before London is active")
161161
}
162162
// London not active, set gas price.
163163
price, err := b.SuggestGasTipCap(ctx)

internal/ethapi/transaction_args_test.go

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

1919
import (
2020
"context"
21-
"fmt"
21+
"errors"
2222
"math/big"
2323
"reflect"
2424
"testing"
@@ -138,28 +138,28 @@ func TestSetFeeDefaults(t *testing.T) {
138138
false,
139139
&TransactionArgs{MaxFeePerGas: maxFee},
140140
nil,
141-
fmt.Errorf("maxFeePerGas and maxPriorityFeePerGas are not valid before London is active"),
141+
errors.New("maxFeePerGas and maxPriorityFeePerGas are not valid before London is active"),
142142
},
143143
{
144144
"dynamic fee tx pre-London, priorityFee set",
145145
false,
146146
&TransactionArgs{MaxPriorityFeePerGas: fortytwo},
147147
nil,
148-
fmt.Errorf("maxFeePerGas and maxPriorityFeePerGas are not valid before London is active"),
148+
errors.New("maxFeePerGas and maxPriorityFeePerGas are not valid before London is active"),
149149
},
150150
{
151151
"dynamic fee tx, maxFee < priorityFee",
152152
true,
153153
&TransactionArgs{MaxFeePerGas: maxFee, MaxPriorityFeePerGas: (*hexutil.Big)(big.NewInt(1000))},
154154
nil,
155-
fmt.Errorf("maxFeePerGas (0x3e) < maxPriorityFeePerGas (0x3e8)"),
155+
errors.New("maxFeePerGas (0x3e) < maxPriorityFeePerGas (0x3e8)"),
156156
},
157157
{
158158
"dynamic fee tx, maxFee < priorityFee while setting default",
159159
true,
160160
&TransactionArgs{MaxFeePerGas: (*hexutil.Big)(big.NewInt(7))},
161161
nil,
162-
fmt.Errorf("maxFeePerGas (0x7) < maxPriorityFeePerGas (0x2a)"),
162+
errors.New("maxFeePerGas (0x7) < maxPriorityFeePerGas (0x2a)"),
163163
},
164164

165165
// Misc
@@ -168,21 +168,21 @@ func TestSetFeeDefaults(t *testing.T) {
168168
false,
169169
&TransactionArgs{GasPrice: fortytwo, MaxFeePerGas: maxFee, MaxPriorityFeePerGas: fortytwo},
170170
nil,
171-
fmt.Errorf("both gasPrice and (maxFeePerGas or maxPriorityFeePerGas) specified"),
171+
errors.New("both gasPrice and (maxFeePerGas or maxPriorityFeePerGas) specified"),
172172
},
173173
{
174174
"set gas price and maxPriorityFee",
175175
false,
176176
&TransactionArgs{GasPrice: fortytwo, MaxPriorityFeePerGas: fortytwo},
177177
nil,
178-
fmt.Errorf("both gasPrice and (maxFeePerGas or maxPriorityFeePerGas) specified"),
178+
errors.New("both gasPrice and (maxFeePerGas or maxPriorityFeePerGas) specified"),
179179
},
180180
{
181181
"set gas price and maxFee",
182182
true,
183183
&TransactionArgs{GasPrice: fortytwo, MaxFeePerGas: maxFee},
184184
nil,
185-
fmt.Errorf("both gasPrice and (maxFeePerGas or maxPriorityFeePerGas) specified"),
185+
errors.New("both gasPrice and (maxFeePerGas or maxPriorityFeePerGas) specified"),
186186
},
187187
}
188188

tests/fuzzers/trie/trie-fuzzer.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package trie
1919
import (
2020
"bytes"
2121
"encoding/binary"
22+
"errors"
2223
"fmt"
2324

2425
"github.com/ethereum/go-ethereum/core/rawdb"
@@ -183,7 +184,7 @@ func runRandTest(rt randTest) error {
183184
checktr.MustUpdate(it.Key, it.Value)
184185
}
185186
if tr.Hash() != checktr.Hash() {
186-
return fmt.Errorf("hash mismatch in opItercheckhash")
187+
return errors.New("hash mismatch in opItercheckhash")
187188
}
188189
case opProve:
189190
rt[i].err = tr.Prove(step.key, 0, proofDb{})

tests/init_test.go

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

1919
import (
2020
"encoding/json"
21+
"errors"
2122
"fmt"
2223
"io"
2324
"os"
@@ -180,7 +181,7 @@ func (tm *testMatcher) checkFailure(t *testing.T, err error) error {
180181
t.Logf("error: %v", err)
181182
return nil
182183
}
183-
return fmt.Errorf("test succeeded unexpectedly")
184+
return errors.New("test succeeded unexpectedly")
184185
}
185186
return err
186187
}

tests/rlp_test_util.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ func FromHex(s string) ([]byte, error) {
5959
func (t *RLPTest) Run() error {
6060
outb, err := FromHex(t.Out)
6161
if err != nil {
62-
return fmt.Errorf("invalid hex in Out")
62+
return errors.New("invalid hex in Out")
6363
}
6464

6565
// Handle simple decoding tests with no actual In value.
@@ -87,7 +87,7 @@ func checkDecodeInterface(b []byte, isValid bool) error {
8787
case isValid && err != nil:
8888
return fmt.Errorf("decoding failed: %v", err)
8989
case !isValid && err == nil:
90-
return fmt.Errorf("decoding of invalid value succeeded")
90+
return errors.New("decoding of invalid value succeeded")
9191
}
9292
return nil
9393
}

tests/state_test_util.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package tests
1919
import (
2020
"encoding/hex"
2121
"encoding/json"
22+
"errors"
2223
"fmt"
2324
"math/big"
2425
"strconv"
@@ -395,7 +396,7 @@ func (tx *stTransaction) toMessage(ps stPostState, baseFee *big.Int) (*core.Mess
395396
tx.MaxFeePerGas)
396397
}
397398
if gasPrice == nil {
398-
return nil, fmt.Errorf("no gas price provided")
399+
return nil, errors.New("no gas price provided")
399400
}
400401

401402
msg := &core.Message{

0 commit comments

Comments
 (0)