Skip to content

Commit 26724fc

Browse files
authored
p2p, log, rpc: use errors.New to replace fmt.Errorf with no parameters (#29074)
1 parent 32d4d6e commit 26724fc

File tree

4 files changed

+11
-8
lines changed

4 files changed

+11
-8
lines changed

log/logger_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package log
22

33
import (
44
"bytes"
5+
"errors"
56
"fmt"
67
"io"
78
"math/big"
@@ -77,7 +78,7 @@ func benchmarkLogger(b *testing.B, l Logger) {
7778
tt = time.Now()
7879
bigint = big.NewInt(100)
7980
nilbig *big.Int
80-
err = fmt.Errorf("Oh nooes it's crap")
81+
err = errors.New("Oh nooes it's crap")
8182
)
8283
b.ReportAllocs()
8384
b.ResetTimer()
@@ -106,7 +107,7 @@ func TestLoggerOutput(t *testing.T) {
106107
tt = time.Time{}
107108
bigint = big.NewInt(100)
108109
nilbig *big.Int
109-
err = fmt.Errorf("Oh nooes it's crap")
110+
err = errors.New("Oh nooes it's crap")
110111
smallUint = uint256.NewInt(500_000)
111112
bigUint = &uint256.Int{0xff, 0xff, 0xff, 0xff}
112113
)

p2p/server.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -914,13 +914,13 @@ func (srv *Server) checkInboundConn(remoteIP net.IP) error {
914914
}
915915
// Reject connections that do not match NetRestrict.
916916
if srv.NetRestrict != nil && !srv.NetRestrict.Contains(remoteIP) {
917-
return fmt.Errorf("not in netrestrict list")
917+
return errors.New("not in netrestrict list")
918918
}
919919
// Reject Internet peers that try too often.
920920
now := srv.clock.Now()
921921
srv.inboundHistory.expire(now, nil)
922922
if !netutil.IsLAN(remoteIP) && srv.inboundHistory.contains(remoteIP.String()) {
923-
return fmt.Errorf("too many attempts")
923+
return errors.New("too many attempts")
924924
}
925925
srv.inboundHistory.add(remoteIP.String(), now.Add(inboundThrottleTime))
926926
return nil

p2p/transport.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package p2p
1919
import (
2020
"bytes"
2121
"crypto/ecdsa"
22+
"errors"
2223
"fmt"
2324
"io"
2425
"net"
@@ -157,7 +158,7 @@ func readProtocolHandshake(rw MsgReader) (*protoHandshake, error) {
157158
return nil, err
158159
}
159160
if msg.Size > baseProtocolMaxMsgSize {
160-
return nil, fmt.Errorf("message too big")
161+
return nil, errors.New("message too big")
161162
}
162163
if msg.Code == discMsg {
163164
// Disconnect before protocol handshake is valid according to the

rpc/types.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package rpc
1919
import (
2020
"context"
2121
"encoding/json"
22+
"errors"
2223
"fmt"
2324
"math"
2425
"strings"
@@ -104,7 +105,7 @@ func (bn *BlockNumber) UnmarshalJSON(data []byte) error {
104105
return err
105106
}
106107
if blckNum > math.MaxInt64 {
107-
return fmt.Errorf("block number larger than int64")
108+
return errors.New("block number larger than int64")
108109
}
109110
*bn = BlockNumber(blckNum)
110111
return nil
@@ -154,7 +155,7 @@ func (bnh *BlockNumberOrHash) UnmarshalJSON(data []byte) error {
154155
err := json.Unmarshal(data, &e)
155156
if err == nil {
156157
if e.BlockNumber != nil && e.BlockHash != nil {
157-
return fmt.Errorf("cannot specify both BlockHash and BlockNumber, choose one or the other")
158+
return errors.New("cannot specify both BlockHash and BlockNumber, choose one or the other")
158159
}
159160
bnh.BlockNumber = e.BlockNumber
160161
bnh.BlockHash = e.BlockHash
@@ -202,7 +203,7 @@ func (bnh *BlockNumberOrHash) UnmarshalJSON(data []byte) error {
202203
return err
203204
}
204205
if blckNum > math.MaxInt64 {
205-
return fmt.Errorf("blocknumber too high")
206+
return errors.New("blocknumber too high")
206207
}
207208
bn := BlockNumber(blckNum)
208209
bnh.BlockNumber = &bn

0 commit comments

Comments
 (0)