From 10208caeff51e3cf74afe04c47cf505e85b252fe Mon Sep 17 00:00:00 2001 From: devopsbo3 <69951731+devopsbo3@users.noreply.github.com> Date: Fri, 10 Nov 2023 12:27:53 -0600 Subject: [PATCH] Revert "internal,tests: replace noarg fmt.Errorf with errors.New (#27335)" This reverts commit 7db2b7162b8b80febf67dc7d959a40abc3940e19. --- internal/build/archive.go | 3 +-- internal/ethapi/api.go | 26 ++++++++++++------------ internal/ethapi/transaction_args.go | 2 +- internal/ethapi/transaction_args_test.go | 16 +++++++-------- tests/fuzzers/trie/trie-fuzzer.go | 3 +-- tests/init_test.go | 3 +-- tests/rlp_test_util.go | 4 ++-- tests/state_test_util.go | 3 +-- 8 files changed, 28 insertions(+), 32 deletions(-) diff --git a/internal/build/archive.go b/internal/build/archive.go index 5b37c0edfa..c16246070e 100644 --- a/internal/build/archive.go +++ b/internal/build/archive.go @@ -20,7 +20,6 @@ import ( "archive/tar" "archive/zip" "compress/gzip" - "errors" "fmt" "io" "os" @@ -91,7 +90,7 @@ func WriteArchive(name string, files []string) (err error) { }() archive, basename := NewArchive(archfd) if archive == nil { - return errors.New("unknown archive extension") + return fmt.Errorf("unknown archive extension") } fmt.Println(name) if err := archive.Directory(basename); err != nil { diff --git a/internal/ethapi/api.go b/internal/ethapi/api.go index 69b5bf1304..9a821be0c1 100644 --- a/internal/ethapi/api.go +++ b/internal/ethapi/api.go @@ -478,16 +478,16 @@ func (s *PersonalAccountAPI) SignTransaction(ctx context.Context, args Transacti // No need to obtain the noncelock mutex, since we won't be sending this // tx into the transaction pool, but right back to the user if args.From == nil { - return nil, errors.New("sender not specified") + return nil, fmt.Errorf("sender not specified") } if args.Gas == nil { - return nil, errors.New("gas not specified") + return nil, fmt.Errorf("gas not specified") } if args.GasPrice == nil && (args.MaxFeePerGas == nil || args.MaxPriorityFeePerGas == nil) { - return nil, errors.New("missing gasPrice or maxFeePerGas/maxPriorityFeePerGas") + return nil, fmt.Errorf("missing gasPrice or maxFeePerGas/maxPriorityFeePerGas") } if args.Nonce == nil { - return nil, errors.New("nonce not specified") + return nil, fmt.Errorf("nonce not specified") } // Before actually signing the transaction, ensure the transaction fee is reasonable. tx := args.toTransaction() @@ -548,7 +548,7 @@ func (s *PersonalAccountAPI) EcRecover(ctx context.Context, data, sig hexutil.By return common.Address{}, fmt.Errorf("signature must be %d bytes long", crypto.SignatureLength) } if sig[crypto.RecoveryIDOffset] != 27 && sig[crypto.RecoveryIDOffset] != 28 { - return common.Address{}, errors.New("invalid Ethereum signature (V is not 27 or 28)") + return common.Address{}, fmt.Errorf("invalid Ethereum signature (V is not 27 or 28)") } sig[crypto.RecoveryIDOffset] -= 27 // Transform yellow paper V from 27/28 to 0/1 @@ -582,7 +582,7 @@ func (s *PersonalAccountAPI) InitializeWallet(ctx context.Context, url string) ( case *scwallet.Wallet: return mnemonic, wallet.Initialize(seed) default: - return "", errors.New("specified wallet does not support initialization") + return "", fmt.Errorf("specified wallet does not support initialization") } } @@ -597,7 +597,7 @@ func (s *PersonalAccountAPI) Unpair(ctx context.Context, url string, pin string) case *scwallet.Wallet: return wallet.Unpair([]byte(pin)) default: - return errors.New("specified wallet does not support pairing") + return fmt.Errorf("specified wallet does not support pairing") } } @@ -722,10 +722,10 @@ func decodeHash(s string) (common.Hash, error) { } b, err := hex.DecodeString(s) if err != nil { - return common.Hash{}, errors.New("hex string invalid") + return common.Hash{}, fmt.Errorf("hex string invalid") } if len(b) > 32 { - return common.Hash{}, errors.New("hex string too long, want at most 32 bytes") + return common.Hash{}, fmt.Errorf("hex string too long, want at most 32 bytes") } return common.BytesToHash(b), nil } @@ -1833,13 +1833,13 @@ type SignTransactionResult struct { // the given from address and it needs to be unlocked. func (s *TransactionAPI) SignTransaction(ctx context.Context, args TransactionArgs) (*SignTransactionResult, error) { if args.Gas == nil { - return nil, errors.New("gas not specified") + return nil, fmt.Errorf("gas not specified") } if args.GasPrice == nil && (args.MaxPriorityFeePerGas == nil || args.MaxFeePerGas == nil) { - return nil, errors.New("missing gasPrice or maxFeePerGas/maxPriorityFeePerGas") + return nil, fmt.Errorf("missing gasPrice or maxFeePerGas/maxPriorityFeePerGas") } if args.Nonce == nil { - return nil, errors.New("nonce not specified") + return nil, fmt.Errorf("nonce not specified") } if err := args.setDefaults(ctx, s.b); err != nil { return nil, err @@ -1888,7 +1888,7 @@ func (s *TransactionAPI) PendingTransactions() ([]*RPCTransaction, error) { // the given transaction from the pool and reinsert it with the new gas price and limit. func (s *TransactionAPI) Resend(ctx context.Context, sendArgs TransactionArgs, gasPrice *hexutil.Big, gasLimit *hexutil.Uint64) (common.Hash, error) { if sendArgs.Nonce == nil { - return common.Hash{}, errors.New("missing transaction nonce in transaction spec") + return common.Hash{}, fmt.Errorf("missing transaction nonce in transaction spec") } if err := sendArgs.setDefaults(ctx, s.b); err != nil { return common.Hash{}, err diff --git a/internal/ethapi/transaction_args.go b/internal/ethapi/transaction_args.go index 6e2690e095..c74f540b76 100644 --- a/internal/ethapi/transaction_args.go +++ b/internal/ethapi/transaction_args.go @@ -157,7 +157,7 @@ func (args *TransactionArgs) setFeeDefaults(ctx context.Context, b Backend) erro } } else { if args.MaxFeePerGas != nil || args.MaxPriorityFeePerGas != nil { - return errors.New("maxFeePerGas and maxPriorityFeePerGas are not valid before London is active") + return fmt.Errorf("maxFeePerGas and maxPriorityFeePerGas are not valid before London is active") } // London not active, set gas price. price, err := b.SuggestGasTipCap(ctx) diff --git a/internal/ethapi/transaction_args_test.go b/internal/ethapi/transaction_args_test.go index 0868f8762c..4da98718b5 100644 --- a/internal/ethapi/transaction_args_test.go +++ b/internal/ethapi/transaction_args_test.go @@ -18,7 +18,7 @@ package ethapi import ( "context" - "errors" + "fmt" "math/big" "reflect" "testing" @@ -138,28 +138,28 @@ func TestSetFeeDefaults(t *testing.T) { false, &TransactionArgs{MaxFeePerGas: maxFee}, nil, - errors.New("maxFeePerGas and maxPriorityFeePerGas are not valid before London is active"), + fmt.Errorf("maxFeePerGas and maxPriorityFeePerGas are not valid before London is active"), }, { "dynamic fee tx pre-London, priorityFee set", false, &TransactionArgs{MaxPriorityFeePerGas: fortytwo}, nil, - errors.New("maxFeePerGas and maxPriorityFeePerGas are not valid before London is active"), + fmt.Errorf("maxFeePerGas and maxPriorityFeePerGas are not valid before London is active"), }, { "dynamic fee tx, maxFee < priorityFee", true, &TransactionArgs{MaxFeePerGas: maxFee, MaxPriorityFeePerGas: (*hexutil.Big)(big.NewInt(1000))}, nil, - errors.New("maxFeePerGas (0x3e) < maxPriorityFeePerGas (0x3e8)"), + fmt.Errorf("maxFeePerGas (0x3e) < maxPriorityFeePerGas (0x3e8)"), }, { "dynamic fee tx, maxFee < priorityFee while setting default", true, &TransactionArgs{MaxFeePerGas: (*hexutil.Big)(big.NewInt(7))}, nil, - errors.New("maxFeePerGas (0x7) < maxPriorityFeePerGas (0x2a)"), + fmt.Errorf("maxFeePerGas (0x7) < maxPriorityFeePerGas (0x2a)"), }, // Misc @@ -168,21 +168,21 @@ func TestSetFeeDefaults(t *testing.T) { false, &TransactionArgs{GasPrice: fortytwo, MaxFeePerGas: maxFee, MaxPriorityFeePerGas: fortytwo}, nil, - errors.New("both gasPrice and (maxFeePerGas or maxPriorityFeePerGas) specified"), + fmt.Errorf("both gasPrice and (maxFeePerGas or maxPriorityFeePerGas) specified"), }, { "set gas price and maxPriorityFee", false, &TransactionArgs{GasPrice: fortytwo, MaxPriorityFeePerGas: fortytwo}, nil, - errors.New("both gasPrice and (maxFeePerGas or maxPriorityFeePerGas) specified"), + fmt.Errorf("both gasPrice and (maxFeePerGas or maxPriorityFeePerGas) specified"), }, { "set gas price and maxFee", true, &TransactionArgs{GasPrice: fortytwo, MaxFeePerGas: maxFee}, nil, - errors.New("both gasPrice and (maxFeePerGas or maxPriorityFeePerGas) specified"), + fmt.Errorf("both gasPrice and (maxFeePerGas or maxPriorityFeePerGas) specified"), }, } diff --git a/tests/fuzzers/trie/trie-fuzzer.go b/tests/fuzzers/trie/trie-fuzzer.go index 7be41b57cb..41baf67ec6 100644 --- a/tests/fuzzers/trie/trie-fuzzer.go +++ b/tests/fuzzers/trie/trie-fuzzer.go @@ -19,7 +19,6 @@ package trie import ( "bytes" "encoding/binary" - "errors" "fmt" "github.com/ethereum/go-ethereum/core/rawdb" @@ -184,7 +183,7 @@ func runRandTest(rt randTest) error { checktr.MustUpdate(it.Key, it.Value) } if tr.Hash() != checktr.Hash() { - return errors.New("hash mismatch in opItercheckhash") + return fmt.Errorf("hash mismatch in opItercheckhash") } case opProve: rt[i].err = tr.Prove(step.key, 0, proofDb{}) diff --git a/tests/init_test.go b/tests/init_test.go index 7d8743efcc..9d315f9511 100644 --- a/tests/init_test.go +++ b/tests/init_test.go @@ -18,7 +18,6 @@ package tests import ( "encoding/json" - "errors" "fmt" "io" "os" @@ -181,7 +180,7 @@ func (tm *testMatcher) checkFailure(t *testing.T, err error) error { t.Logf("error: %v", err) return nil } - return errors.New("test succeeded unexpectedly") + return fmt.Errorf("test succeeded unexpectedly") } return err } diff --git a/tests/rlp_test_util.go b/tests/rlp_test_util.go index e4bd5450a8..15acb3a244 100644 --- a/tests/rlp_test_util.go +++ b/tests/rlp_test_util.go @@ -59,7 +59,7 @@ func FromHex(s string) ([]byte, error) { func (t *RLPTest) Run() error { outb, err := FromHex(t.Out) if err != nil { - return errors.New("invalid hex in Out") + return fmt.Errorf("invalid hex in Out") } // Handle simple decoding tests with no actual In value. @@ -87,7 +87,7 @@ func checkDecodeInterface(b []byte, isValid bool) error { case isValid && err != nil: return fmt.Errorf("decoding failed: %v", err) case !isValid && err == nil: - return errors.New("decoding of invalid value succeeded") + return fmt.Errorf("decoding of invalid value succeeded") } return nil } diff --git a/tests/state_test_util.go b/tests/state_test_util.go index eec91b67a7..d9b646918d 100644 --- a/tests/state_test_util.go +++ b/tests/state_test_util.go @@ -19,7 +19,6 @@ package tests import ( "encoding/hex" "encoding/json" - "errors" "fmt" "math/big" "strconv" @@ -396,7 +395,7 @@ func (tx *stTransaction) toMessage(ps stPostState, baseFee *big.Int) (*core.Mess tx.MaxFeePerGas) } if gasPrice == nil { - return nil, errors.New("no gas price provided") + return nil, fmt.Errorf("no gas price provided") } msg := &core.Message{