Skip to content

Commit 9358b62

Browse files
authored
accounts: replace noarg fmt.Errorf with errors.New (ethereum#27331)
* accounts: replace noarg fmt.Errorf with errors.New Signed-off-by: jsvisa <delweng@gmail.com> * accounts: go autoimport Signed-off-by: jsvisa <delweng@gmail.com> --------- Signed-off-by: jsvisa <delweng@gmail.com>
1 parent 6c73276 commit 9358b62

File tree

9 files changed

+30
-25
lines changed

9 files changed

+30
-25
lines changed

accounts/abi/bind/backends/simulated.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -681,7 +681,7 @@ func (b *SimulatedBackend) SendTransaction(ctx context.Context, tx *types.Transa
681681
// Get the last block
682682
block, err := b.blockByHash(ctx, b.pendingBlock.ParentHash())
683683
if err != nil {
684-
return fmt.Errorf("could not fetch parent")
684+
return errors.New("could not fetch parent")
685685
}
686686
// Check transaction validity
687687
signer := types.MakeSigner(b.blockchain.Config(), block.Number(), block.Time())
@@ -815,7 +815,7 @@ func (b *SimulatedBackend) AdjustTime(adjustment time.Duration) error {
815815
// Get the last block
816816
block := b.blockchain.GetBlockByHash(b.pendingBlock.ParentHash())
817817
if block == nil {
818-
return fmt.Errorf("could not find parent")
818+
return errors.New("could not find parent")
819819
}
820820

821821
blocks, _ := core.GenerateChain(b.config, block, ethash.NewFaker(), b.database, 1, func(number int, block *core.BlockGen) {

accounts/abi/reflect.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ func mapArgNamesToStructFields(argNames []string, value reflect.Value) (map[stri
228228
structFieldName := ToCamelCase(argName)
229229

230230
if structFieldName == "" {
231-
return nil, fmt.Errorf("abi: purely underscored output cannot unpack to struct")
231+
return nil, errors.New("abi: purely underscored output cannot unpack to struct")
232232
}
233233

234234
// this abi has already been paired, skip it... unless there exists another, yet unassigned

accounts/abi/selector_parser.go

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

1919
import (
20+
"errors"
2021
"fmt"
2122
)
2223

@@ -40,7 +41,7 @@ func isIdentifierSymbol(c byte) bool {
4041

4142
func parseToken(unescapedSelector string, isIdent bool) (string, string, error) {
4243
if len(unescapedSelector) == 0 {
43-
return "", "", fmt.Errorf("empty token")
44+
return "", "", errors.New("empty token")
4445
}
4546
firstChar := unescapedSelector[0]
4647
position := 1
@@ -110,7 +111,7 @@ func parseCompositeType(unescapedSelector string) ([]interface{}, string, error)
110111

111112
func parseType(unescapedSelector string) (interface{}, string, error) {
112113
if len(unescapedSelector) == 0 {
113-
return nil, "", fmt.Errorf("empty type")
114+
return nil, "", errors.New("empty type")
114115
}
115116
if unescapedSelector[0] == '(' {
116117
return parseCompositeType(unescapedSelector)

accounts/abi/type.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ var (
7070
func NewType(t string, internalType string, components []ArgumentMarshaling) (typ Type, err error) {
7171
// check that array brackets are equal if they exist
7272
if strings.Count(t, "[") != strings.Count(t, "]") {
73-
return Type{}, fmt.Errorf("invalid arg type in abi")
73+
return Type{}, errors.New("invalid arg type in abi")
7474
}
7575
typ.stringKind = t
7676

@@ -109,7 +109,7 @@ func NewType(t string, internalType string, components []ArgumentMarshaling) (ty
109109
}
110110
typ.stringKind = embeddedType.stringKind + sliced
111111
} else {
112-
return Type{}, fmt.Errorf("invalid formatting of array type")
112+
return Type{}, errors.New("invalid formatting of array type")
113113
}
114114
return typ, err
115115
}

accounts/abi/unpack.go

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

1919
import (
2020
"encoding/binary"
21+
"errors"
2122
"fmt"
2223
"math"
2324
"math/big"
@@ -125,7 +126,7 @@ func readBool(word []byte) (bool, error) {
125126
// readFunctionType enforces that standard by always presenting it as a 24-array (address + sig = 24 bytes)
126127
func readFunctionType(t Type, word []byte) (funcTy [24]byte, err error) {
127128
if t.T != FunctionTy {
128-
return [24]byte{}, fmt.Errorf("abi: invalid type in call to make function type byte array")
129+
return [24]byte{}, errors.New("abi: invalid type in call to make function type byte array")
129130
}
130131
if garbage := binary.BigEndian.Uint64(word[24:32]); garbage != 0 {
131132
err = fmt.Errorf("abi: got improperly encoded function type, got %v", word)
@@ -138,7 +139,7 @@ func readFunctionType(t Type, word []byte) (funcTy [24]byte, err error) {
138139
// ReadFixedBytes uses reflection to create a fixed array to be read from.
139140
func ReadFixedBytes(t Type, word []byte) (interface{}, error) {
140141
if t.T != FixedBytesTy {
141-
return nil, fmt.Errorf("abi: invalid type in call to make fixed byte array")
142+
return nil, errors.New("abi: invalid type in call to make fixed byte array")
142143
}
143144
// convert
144145
array := reflect.New(t.GetType()).Elem()
@@ -166,7 +167,7 @@ func forEachUnpack(t Type, output []byte, start, size int) (interface{}, error)
166167
// declare our array
167168
refSlice = reflect.New(t.GetType()).Elem()
168169
} else {
169-
return nil, fmt.Errorf("abi: invalid type in array/slice unpacking stage")
170+
return nil, errors.New("abi: invalid type in array/slice unpacking stage")
170171
}
171172

172173
// Arrays have packed elements, resulting in longer unpack steps.

accounts/external/backend.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package external
1818

1919
import (
20+
"errors"
2021
"fmt"
2122
"math/big"
2223
"sync"
@@ -98,11 +99,11 @@ func (api *ExternalSigner) Status() (string, error) {
9899
}
99100

100101
func (api *ExternalSigner) Open(passphrase string) error {
101-
return fmt.Errorf("operation not supported on external signers")
102+
return errors.New("operation not supported on external signers")
102103
}
103104

104105
func (api *ExternalSigner) Close() error {
105-
return fmt.Errorf("operation not supported on external signers")
106+
return errors.New("operation not supported on external signers")
106107
}
107108

108109
func (api *ExternalSigner) Accounts() []accounts.Account {
@@ -145,7 +146,7 @@ func (api *ExternalSigner) Contains(account accounts.Account) bool {
145146
}
146147

147148
func (api *ExternalSigner) Derive(path accounts.DerivationPath, pin bool) (accounts.Account, error) {
148-
return accounts.Account{}, fmt.Errorf("operation not supported on external signers")
149+
return accounts.Account{}, errors.New("operation not supported on external signers")
149150
}
150151

151152
func (api *ExternalSigner) SelfDerive(bases []accounts.DerivationPath, chain ethereum.ChainStateReader) {
@@ -242,14 +243,14 @@ func (api *ExternalSigner) SignTx(account accounts.Account, tx *types.Transactio
242243
}
243244

244245
func (api *ExternalSigner) SignTextWithPassphrase(account accounts.Account, passphrase string, text []byte) ([]byte, error) {
245-
return []byte{}, fmt.Errorf("password-operations not supported on external signers")
246+
return []byte{}, errors.New("password-operations not supported on external signers")
246247
}
247248

248249
func (api *ExternalSigner) SignTxWithPassphrase(account accounts.Account, passphrase string, tx *types.Transaction, chainID *big.Int) (*types.Transaction, error) {
249-
return nil, fmt.Errorf("password-operations not supported on external signers")
250+
return nil, errors.New("password-operations not supported on external signers")
250251
}
251252
func (api *ExternalSigner) SignDataWithPassphrase(account accounts.Account, passphrase, mimeType string, data []byte) ([]byte, error) {
252-
return nil, fmt.Errorf("password-operations not supported on external signers")
253+
return nil, errors.New("password-operations not supported on external signers")
253254
}
254255

255256
func (api *ExternalSigner) listAccounts() ([]common.Address, error) {

accounts/keystore/account_cache_test.go

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

1919
import (
20+
"errors"
2021
"fmt"
2122
"math/rand"
2223
"os"
@@ -74,7 +75,7 @@ func waitForAccounts(wantAccounts []accounts.Account, ks *KeyStore) error {
7475
select {
7576
case <-ks.changes:
7677
default:
77-
return fmt.Errorf("wasn't notified of new accounts")
78+
return errors.New("wasn't notified of new accounts")
7879
}
7980
return nil
8081
}

accounts/scwallet/securechannel.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
"crypto/rand"
2525
"crypto/sha256"
2626
"crypto/sha512"
27+
"errors"
2728
"fmt"
2829

2930
"github.com/ethereum/go-ethereum/crypto"
@@ -125,7 +126,7 @@ func (s *SecureChannelSession) Pair(pairingPassword []byte) error {
125126
// Unpair disestablishes an existing pairing.
126127
func (s *SecureChannelSession) Unpair() error {
127128
if s.PairingKey == nil {
128-
return fmt.Errorf("cannot unpair: not paired")
129+
return errors.New("cannot unpair: not paired")
129130
}
130131

131132
_, err := s.transmitEncrypted(claSCWallet, insUnpair, s.PairingIndex, 0, []byte{})
@@ -141,7 +142,7 @@ func (s *SecureChannelSession) Unpair() error {
141142
// Open initializes the secure channel.
142143
func (s *SecureChannelSession) Open() error {
143144
if s.iv != nil {
144-
return fmt.Errorf("session already opened")
145+
return errors.New("session already opened")
145146
}
146147

147148
response, err := s.open()
@@ -215,7 +216,7 @@ func (s *SecureChannelSession) pair(p1 uint8, data []byte) (*responseAPDU, error
215216
// transmitEncrypted sends an encrypted message, and decrypts and returns the response.
216217
func (s *SecureChannelSession) transmitEncrypted(cla, ins, p1, p2 byte, data []byte) (*responseAPDU, error) {
217218
if s.iv == nil {
218-
return nil, fmt.Errorf("channel not open")
219+
return nil, errors.New("channel not open")
219220
}
220221

221222
data, err := s.encryptAPDU(data)
@@ -254,7 +255,7 @@ func (s *SecureChannelSession) transmitEncrypted(cla, ins, p1, p2 byte, data []b
254255
return nil, err
255256
}
256257
if !bytes.Equal(s.iv, rmac) {
257-
return nil, fmt.Errorf("invalid MAC in response")
258+
return nil, errors.New("invalid MAC in response")
258259
}
259260

260261
rapdu := &responseAPDU{}
@@ -319,7 +320,7 @@ func unpad(data []byte, terminator byte) ([]byte, error) {
319320
return nil, fmt.Errorf("expected end of padding, got %d", data[len(data)-i])
320321
}
321322
}
322-
return nil, fmt.Errorf("expected end of padding, got 0")
323+
return nil, errors.New("expected end of padding, got 0")
323324
}
324325

325326
// updateIV is an internal method that updates the initialization vector after

accounts/scwallet/wallet.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ func (w *Wallet) release() error {
252252
// with the wallet.
253253
func (w *Wallet) pair(puk []byte) error {
254254
if w.session.paired() {
255-
return fmt.Errorf("wallet already paired")
255+
return errors.New("wallet already paired")
256256
}
257257
pairing, err := w.session.pair(puk)
258258
if err != nil {
@@ -813,7 +813,7 @@ func (s *Session) pair(secret []byte) (smartcardPairing, error) {
813813
// unpair deletes an existing pairing.
814814
func (s *Session) unpair() error {
815815
if !s.verified {
816-
return fmt.Errorf("unpair requires that the PIN be verified")
816+
return errors.New("unpair requires that the PIN be verified")
817817
}
818818
return s.Channel.Unpair()
819819
}
@@ -907,7 +907,7 @@ func (s *Session) initialize(seed []byte) error {
907907
return err
908908
}
909909
if status == "Online" {
910-
return fmt.Errorf("card is already initialized, cowardly refusing to proceed")
910+
return errors.New("card is already initialized, cowardly refusing to proceed")
911911
}
912912

913913
s.Wallet.lock.Lock()

0 commit comments

Comments
 (0)