Skip to content

Commit dd25a4f

Browse files
authored
les, signer, light: replace noarg fmt.Errorf with errors.New (ethereum#27336)
Signed-off-by: jsvisa <delweng@gmail.com>
1 parent 21c87e0 commit dd25a4f

File tree

8 files changed

+18
-16
lines changed

8 files changed

+18
-16
lines changed

les/benchmark.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ package les
1919
import (
2020
crand "crypto/rand"
2121
"encoding/binary"
22-
"fmt"
22+
"errors"
2323
"math/big"
2424
"math/rand"
2525
"sync"
@@ -59,7 +59,7 @@ func (b *benchmarkBlockHeaders) init(h *serverHandler, count int) error {
5959
b.offset = 0
6060
b.randMax = h.blockchain.CurrentHeader().Number.Int64() + 1 - d
6161
if b.randMax < 0 {
62-
return fmt.Errorf("chain is too short")
62+
return errors.New("chain is too short")
6363
}
6464
if b.reverse {
6565
b.offset = d
@@ -137,7 +137,7 @@ func (b *benchmarkHelperTrie) init(h *serverHandler, count int) error {
137137
b.headNum = b.sectionCount*params.CHTFrequency - 1
138138
}
139139
if b.sectionCount == 0 {
140-
return fmt.Errorf("no processed sections available")
140+
return errors.New("no processed sections available")
141141
}
142142
return nil
143143
}
@@ -338,7 +338,7 @@ func (h *serverHandler) measure(setup *benchmarkSetup, count int) error {
338338
case <-h.closeCh:
339339
clientPipe.Close()
340340
serverPipe.Close()
341-
return fmt.Errorf("Benchmark cancelled")
341+
return errors.New("Benchmark cancelled")
342342
}
343343

344344
setup.totalTime += time.Duration(mclock.Now() - start)

les/catalyst/api.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ func (api *ConsensusAPI) ExchangeTransitionConfigurationV1(config engine.Transit
213213
TerminalBlockNumber: config.TerminalBlockNumber,
214214
}, nil
215215
}
216-
return nil, fmt.Errorf("invalid terminal block hash")
216+
return nil, errors.New("invalid terminal block hash")
217217
}
218218

219219
return &engine.TransitionConfigurationV1{TerminalTotalDifficulty: (*hexutil.Big)(ttd)}, nil

les/client.go

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

2020
import (
21-
"fmt"
21+
"errors"
2222
"strings"
2323
"time"
2424

@@ -268,12 +268,12 @@ type LightDummyAPI struct{}
268268

269269
// Etherbase is the address that mining rewards will be send to
270270
func (s *LightDummyAPI) Etherbase() (common.Address, error) {
271-
return common.Address{}, fmt.Errorf("mining is not supported in light mode")
271+
return common.Address{}, errors.New("mining is not supported in light mode")
272272
}
273273

274274
// Coinbase is the address that mining rewards will be send to (alias for Etherbase)
275275
func (s *LightDummyAPI) Coinbase() (common.Address, error) {
276-
return common.Address{}, fmt.Errorf("mining is not supported in light mode")
276+
return common.Address{}, errors.New("mining is not supported in light mode")
277277
}
278278

279279
// Hashrate returns the POW hashrate

les/retrieve.go

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

1919
import (
2020
"context"
21-
"fmt"
21+
"errors"
2222
"sync"
2323
"time"
2424

@@ -110,7 +110,7 @@ func (rm *retrieveManager) retrieve(ctx context.Context, reqID uint64, req *dist
110110
case <-ctx.Done():
111111
sentReq.stop(ctx.Err())
112112
case <-shutdown:
113-
sentReq.stop(fmt.Errorf("client is shutting down"))
113+
sentReq.stop(errors.New("client is shutting down"))
114114
}
115115
return sentReq.getError()
116116
}

light/trie_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package light
1919
import (
2020
"bytes"
2121
"context"
22+
"errors"
2223
"fmt"
2324
"math/big"
2425
"testing"
@@ -78,9 +79,9 @@ func diffTries(t1, t2 state.Trie) error {
7879
case i2.Err != nil:
7980
return fmt.Errorf("light trie iterator error: %v", i2.Err)
8081
case i1.Next():
81-
return fmt.Errorf("full trie iterator has more k/v pairs")
82+
return errors.New("full trie iterator has more k/v pairs")
8283
case i2.Next():
83-
return fmt.Errorf("light trie iterator has more k/v pairs")
84+
return errors.New("light trie iterator has more k/v pairs")
8485
}
8586
return nil
8687
}

signer/core/signed_data.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -304,10 +304,10 @@ func (api *SignerAPI) EcRecover(ctx context.Context, data hexutil.Bytes, sig hex
304304
//
305305
// https://github.com/ethereum/go-ethereum/wiki/Management-APIs#personal_ecRecover
306306
if len(sig) != 65 {
307-
return common.Address{}, fmt.Errorf("signature must be 65 bytes long")
307+
return common.Address{}, errors.New("signature must be 65 bytes long")
308308
}
309309
if sig[64] != 27 && sig[64] != 28 {
310-
return common.Address{}, fmt.Errorf("invalid Ethereum signature (V is not 27 or 28)")
310+
return common.Address{}, errors.New("invalid Ethereum signature (V is not 27 or 28)")
311311
}
312312
sig[64] -= 27 // Transform yellow paper V from 27/28 to 0/1
313313
hash := accounts.TextHash(data)

signer/core/uiapi.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ func (s *UIServerAPI) Export(ctx context.Context, addr common.Address) (json.Raw
177177
return nil, err
178178
}
179179
if wallet.URL().Scheme != keystore.KeyStoreScheme {
180-
return nil, fmt.Errorf("account is not a keystore-account")
180+
return nil, errors.New("account is not a keystore-account")
181181
}
182182
return os.ReadFile(wallet.URL().Path)
183183
}

signer/rules/rules.go

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

1919
import (
2020
"encoding/json"
21+
"errors"
2122
"fmt"
2223
"os"
2324
"strings"
@@ -146,7 +147,7 @@ func (r *rulesetUI) checkApproval(jsfunc string, jsarg []byte, err error) (bool,
146147
log.Info("Op rejected")
147148
return false, nil
148149
}
149-
return false, fmt.Errorf("unknown response")
150+
return false, errors.New("unknown response")
150151
}
151152

152153
func (r *rulesetUI) ApproveTx(request *core.SignTxRequest) (core.SignTxResponse, error) {

0 commit comments

Comments
 (0)