From cb886eb636ce765cd3de666d3cdd8969b750fd51 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 "accounts: replace noarg fmt.Errorf with errors.New (#27331)" This reverts commit f090ea82ada986cbd5c7c25f5380751fa3f42a1f. --- accounts/abi/bind/backends/simulated.go | 4 ++-- accounts/abi/reflect.go | 2 +- accounts/abi/selector_parser.go | 5 ++--- accounts/abi/type.go | 4 ++-- accounts/abi/unpack.go | 7 +++---- accounts/external/backend.go | 13 ++++++------- accounts/keystore/account_cache_test.go | 3 +-- accounts/scwallet/securechannel.go | 11 +++++------ accounts/scwallet/wallet.go | 6 +++--- 9 files changed, 25 insertions(+), 30 deletions(-) diff --git a/accounts/abi/bind/backends/simulated.go b/accounts/abi/bind/backends/simulated.go index 83b91f7f8d..0af520b5d9 100644 --- a/accounts/abi/bind/backends/simulated.go +++ b/accounts/abi/bind/backends/simulated.go @@ -681,7 +681,7 @@ func (b *SimulatedBackend) SendTransaction(ctx context.Context, tx *types.Transa // Get the last block block, err := b.blockByHash(ctx, b.pendingBlock.ParentHash()) if err != nil { - return errors.New("could not fetch parent") + return fmt.Errorf("could not fetch parent") } // Check transaction validity signer := types.MakeSigner(b.blockchain.Config(), block.Number(), block.Time()) @@ -815,7 +815,7 @@ func (b *SimulatedBackend) AdjustTime(adjustment time.Duration) error { // Get the last block block := b.blockchain.GetBlockByHash(b.pendingBlock.ParentHash()) if block == nil { - return errors.New("could not find parent") + return fmt.Errorf("could not find parent") } blocks, _ := core.GenerateChain(b.config, block, ethash.NewFaker(), b.database, 1, func(number int, block *core.BlockGen) { diff --git a/accounts/abi/reflect.go b/accounts/abi/reflect.go index 48d2ef41ec..1f84b111a3 100644 --- a/accounts/abi/reflect.go +++ b/accounts/abi/reflect.go @@ -228,7 +228,7 @@ func mapArgNamesToStructFields(argNames []string, value reflect.Value) (map[stri structFieldName := ToCamelCase(argName) if structFieldName == "" { - return nil, errors.New("abi: purely underscored output cannot unpack to struct") + return nil, fmt.Errorf("abi: purely underscored output cannot unpack to struct") } // this abi has already been paired, skip it... unless there exists another, yet unassigned diff --git a/accounts/abi/selector_parser.go b/accounts/abi/selector_parser.go index b8ddd7d656..d5472e374f 100644 --- a/accounts/abi/selector_parser.go +++ b/accounts/abi/selector_parser.go @@ -17,7 +17,6 @@ package abi import ( - "errors" "fmt" ) @@ -41,7 +40,7 @@ func isIdentifierSymbol(c byte) bool { func parseToken(unescapedSelector string, isIdent bool) (string, string, error) { if len(unescapedSelector) == 0 { - return "", "", errors.New("empty token") + return "", "", fmt.Errorf("empty token") } firstChar := unescapedSelector[0] position := 1 @@ -111,7 +110,7 @@ func parseCompositeType(unescapedSelector string) ([]interface{}, string, error) func parseType(unescapedSelector string) (interface{}, string, error) { if len(unescapedSelector) == 0 { - return nil, "", errors.New("empty type") + return nil, "", fmt.Errorf("empty type") } if unescapedSelector[0] == '(' { return parseCompositeType(unescapedSelector) diff --git a/accounts/abi/type.go b/accounts/abi/type.go index 3c05d774a6..7f74907a84 100644 --- a/accounts/abi/type.go +++ b/accounts/abi/type.go @@ -70,7 +70,7 @@ var ( func NewType(t string, internalType string, components []ArgumentMarshaling) (typ Type, err error) { // check that array brackets are equal if they exist if strings.Count(t, "[") != strings.Count(t, "]") { - return Type{}, errors.New("invalid arg type in abi") + return Type{}, fmt.Errorf("invalid arg type in abi") } typ.stringKind = t @@ -109,7 +109,7 @@ func NewType(t string, internalType string, components []ArgumentMarshaling) (ty } typ.stringKind = embeddedType.stringKind + sliced } else { - return Type{}, errors.New("invalid formatting of array type") + return Type{}, fmt.Errorf("invalid formatting of array type") } return typ, err } diff --git a/accounts/abi/unpack.go b/accounts/abi/unpack.go index 68451483cd..1e778a6ff0 100644 --- a/accounts/abi/unpack.go +++ b/accounts/abi/unpack.go @@ -18,7 +18,6 @@ package abi import ( "encoding/binary" - "errors" "fmt" "math" "math/big" @@ -126,7 +125,7 @@ func readBool(word []byte) (bool, error) { // readFunctionType enforces that standard by always presenting it as a 24-array (address + sig = 24 bytes) func readFunctionType(t Type, word []byte) (funcTy [24]byte, err error) { if t.T != FunctionTy { - return [24]byte{}, errors.New("abi: invalid type in call to make function type byte array") + return [24]byte{}, fmt.Errorf("abi: invalid type in call to make function type byte array") } if garbage := binary.BigEndian.Uint64(word[24:32]); garbage != 0 { err = fmt.Errorf("abi: got improperly encoded function type, got %v", word) @@ -139,7 +138,7 @@ func readFunctionType(t Type, word []byte) (funcTy [24]byte, err error) { // ReadFixedBytes uses reflection to create a fixed array to be read from. func ReadFixedBytes(t Type, word []byte) (interface{}, error) { if t.T != FixedBytesTy { - return nil, errors.New("abi: invalid type in call to make fixed byte array") + return nil, fmt.Errorf("abi: invalid type in call to make fixed byte array") } // convert array := reflect.New(t.GetType()).Elem() @@ -167,7 +166,7 @@ func forEachUnpack(t Type, output []byte, start, size int) (interface{}, error) // declare our array refSlice = reflect.New(t.GetType()).Elem() } else { - return nil, errors.New("abi: invalid type in array/slice unpacking stage") + return nil, fmt.Errorf("abi: invalid type in array/slice unpacking stage") } // Arrays have packed elements, resulting in longer unpack steps. diff --git a/accounts/external/backend.go b/accounts/external/backend.go index 6f1581f9b8..d403b7e562 100644 --- a/accounts/external/backend.go +++ b/accounts/external/backend.go @@ -17,7 +17,6 @@ package external import ( - "errors" "fmt" "math/big" "sync" @@ -99,11 +98,11 @@ func (api *ExternalSigner) Status() (string, error) { } func (api *ExternalSigner) Open(passphrase string) error { - return errors.New("operation not supported on external signers") + return fmt.Errorf("operation not supported on external signers") } func (api *ExternalSigner) Close() error { - return errors.New("operation not supported on external signers") + return fmt.Errorf("operation not supported on external signers") } func (api *ExternalSigner) Accounts() []accounts.Account { @@ -146,7 +145,7 @@ func (api *ExternalSigner) Contains(account accounts.Account) bool { } func (api *ExternalSigner) Derive(path accounts.DerivationPath, pin bool) (accounts.Account, error) { - return accounts.Account{}, errors.New("operation not supported on external signers") + return accounts.Account{}, fmt.Errorf("operation not supported on external signers") } func (api *ExternalSigner) SelfDerive(bases []accounts.DerivationPath, chain ethereum.ChainStateReader) { @@ -243,14 +242,14 @@ func (api *ExternalSigner) SignTx(account accounts.Account, tx *types.Transactio } func (api *ExternalSigner) SignTextWithPassphrase(account accounts.Account, passphrase string, text []byte) ([]byte, error) { - return []byte{}, errors.New("password-operations not supported on external signers") + return []byte{}, fmt.Errorf("password-operations not supported on external signers") } func (api *ExternalSigner) SignTxWithPassphrase(account accounts.Account, passphrase string, tx *types.Transaction, chainID *big.Int) (*types.Transaction, error) { - return nil, errors.New("password-operations not supported on external signers") + return nil, fmt.Errorf("password-operations not supported on external signers") } func (api *ExternalSigner) SignDataWithPassphrase(account accounts.Account, passphrase, mimeType string, data []byte) ([]byte, error) { - return nil, errors.New("password-operations not supported on external signers") + return nil, fmt.Errorf("password-operations not supported on external signers") } func (api *ExternalSigner) listAccounts() ([]common.Address, error) { diff --git a/accounts/keystore/account_cache_test.go b/accounts/keystore/account_cache_test.go index 7605d0fbf0..aa71c12018 100644 --- a/accounts/keystore/account_cache_test.go +++ b/accounts/keystore/account_cache_test.go @@ -17,7 +17,6 @@ package keystore import ( - "errors" "fmt" "math/rand" "os" @@ -75,7 +74,7 @@ func waitForAccounts(wantAccounts []accounts.Account, ks *KeyStore) error { select { case <-ks.changes: default: - return errors.New("wasn't notified of new accounts") + return fmt.Errorf("wasn't notified of new accounts") } return nil } diff --git a/accounts/scwallet/securechannel.go b/accounts/scwallet/securechannel.go index bbd8b22647..b1b533eb72 100644 --- a/accounts/scwallet/securechannel.go +++ b/accounts/scwallet/securechannel.go @@ -24,7 +24,6 @@ import ( "crypto/rand" "crypto/sha256" "crypto/sha512" - "errors" "fmt" "github.com/ethereum/go-ethereum/crypto" @@ -126,7 +125,7 @@ func (s *SecureChannelSession) Pair(pairingPassword []byte) error { // Unpair disestablishes an existing pairing. func (s *SecureChannelSession) Unpair() error { if s.PairingKey == nil { - return errors.New("cannot unpair: not paired") + return fmt.Errorf("cannot unpair: not paired") } _, err := s.transmitEncrypted(claSCWallet, insUnpair, s.PairingIndex, 0, []byte{}) @@ -142,7 +141,7 @@ func (s *SecureChannelSession) Unpair() error { // Open initializes the secure channel. func (s *SecureChannelSession) Open() error { if s.iv != nil { - return errors.New("session already opened") + return fmt.Errorf("session already opened") } response, err := s.open() @@ -216,7 +215,7 @@ func (s *SecureChannelSession) pair(p1 uint8, data []byte) (*responseAPDU, error // transmitEncrypted sends an encrypted message, and decrypts and returns the response. func (s *SecureChannelSession) transmitEncrypted(cla, ins, p1, p2 byte, data []byte) (*responseAPDU, error) { if s.iv == nil { - return nil, errors.New("channel not open") + return nil, fmt.Errorf("channel not open") } data, err := s.encryptAPDU(data) @@ -255,7 +254,7 @@ func (s *SecureChannelSession) transmitEncrypted(cla, ins, p1, p2 byte, data []b return nil, err } if !bytes.Equal(s.iv, rmac) { - return nil, errors.New("invalid MAC in response") + return nil, fmt.Errorf("invalid MAC in response") } rapdu := &responseAPDU{} @@ -320,7 +319,7 @@ func unpad(data []byte, terminator byte) ([]byte, error) { return nil, fmt.Errorf("expected end of padding, got %d", data[len(data)-i]) } } - return nil, errors.New("expected end of padding, got 0") + return nil, fmt.Errorf("expected end of padding, got 0") } // updateIV is an internal method that updates the initialization vector after diff --git a/accounts/scwallet/wallet.go b/accounts/scwallet/wallet.go index 067bda83f1..6a40e28ae6 100644 --- a/accounts/scwallet/wallet.go +++ b/accounts/scwallet/wallet.go @@ -252,7 +252,7 @@ func (w *Wallet) release() error { // with the wallet. func (w *Wallet) pair(puk []byte) error { if w.session.paired() { - return errors.New("wallet already paired") + return fmt.Errorf("wallet already paired") } pairing, err := w.session.pair(puk) if err != nil { @@ -813,7 +813,7 @@ func (s *Session) pair(secret []byte) (smartcardPairing, error) { // unpair deletes an existing pairing. func (s *Session) unpair() error { if !s.verified { - return errors.New("unpair requires that the PIN be verified") + return fmt.Errorf("unpair requires that the PIN be verified") } return s.Channel.Unpair() } @@ -907,7 +907,7 @@ func (s *Session) initialize(seed []byte) error { return err } if status == "Online" { - return errors.New("card is already initialized, cowardly refusing to proceed") + return fmt.Errorf("card is already initialized, cowardly refusing to proceed") } s.Wallet.lock.Lock()