Skip to content

Commit bb0c1ae

Browse files
authored
perf(main): use errors.New to replace fmt.Errorf with no parameters (#16777)
1 parent 00f8954 commit bb0c1ae

File tree

4 files changed

+13
-11
lines changed

4 files changed

+13
-11
lines changed

packages/eventindexer/disperser/config.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package disperser
33
import (
44
"crypto/ecdsa"
55
"database/sql"
6+
"errors"
67
"fmt"
78
"math/big"
89

@@ -52,7 +53,7 @@ func NewConfigFromCliContext(c *cli.Context) (*Config, error) {
5253

5354
dispersalAmount, ok := new(big.Int).SetString(c.String(flags.DispersalAmount.Name), 10)
5455
if !ok {
55-
return nil, fmt.Errorf("Invalid dispersal amount")
56+
return nil, errors.New("Invalid dispersal amount")
5657
}
5758

5859
return &Config{

packages/fork-diff/main.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ func main() {
201201

202202
err := enc.Encode(FilePatch{filePatch: fps.Patch})
203203
if err != nil {
204-
return "", fmt.Errorf("")
204+
return "", errors.New("")
205205
}
206206
return string(t2html.Render(out.Bytes())), nil
207207
},

packages/relayer/bridge/config.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package bridge
22

33
import (
44
"crypto/ecdsa"
5+
"errors"
56
"fmt"
67
"math/big"
78

@@ -48,7 +49,7 @@ func NewConfigFromCliContext(c *cli.Context) (*Config, error) {
4849

4950
bridgeMessageValue, ok := new(big.Int).SetString(c.String(flags.BridgeMessageValue.Name), 10)
5051
if !ok {
51-
return nil, fmt.Errorf("invalid bridgeMessageValue")
52+
return nil, errors.New("invalid bridgeMessageValue")
5253
}
5354

5455
return &Config{

packages/relayer/types.go

+8-8
Original file line numberDiff line numberDiff line change
@@ -146,13 +146,13 @@ func decodeDataAsERC20(decodedData []byte) (CanonicalToken, *big.Int, error) {
146146
chunks := splitByteArray(decodedData, 32)
147147

148148
if len(chunks) < 4 {
149-
return token, big.NewInt(0), fmt.Errorf("data too short")
149+
return token, big.NewInt(0), errors.New("data too short")
150150
}
151151

152152
offset, ok := new(big.Int).SetString(common.Bytes2Hex((chunks[canonicalTokenDataStartingindex])), 16)
153153

154154
if !ok {
155-
return token, big.NewInt(0), fmt.Errorf("data for BigInt is invalid")
155+
return token, big.NewInt(0), errors.New("data for BigInt is invalid")
156156
}
157157

158158
canonicalTokenData := decodedData[offset.Int64()+canonicalTokenDataStartingindex*32:]
@@ -172,7 +172,7 @@ func decodeDataAsERC20(decodedData []byte) (CanonicalToken, *big.Int, error) {
172172

173173
amount, ok := new(big.Int).SetString(common.Bytes2Hex((chunks[canonicalTokenDataStartingindex+3])), 16)
174174
if !ok {
175-
return token, big.NewInt(0), fmt.Errorf("data for BigInt is invalid")
175+
return token, big.NewInt(0), errors.New("data for BigInt is invalid")
176176
}
177177

178178
return token, amount, nil
@@ -187,7 +187,7 @@ func decodeDataAsNFT(decodedData []byte) (EventType, CanonicalToken, *big.Int, e
187187
offset, ok := new(big.Int).SetString(common.Bytes2Hex((chunks[canonicalTokenDataStartingindex])), 16)
188188

189189
if !ok || offset.Int64()%32 != 0 {
190-
return EventTypeSendETH, token, big.NewInt(0), fmt.Errorf("data for BigInt is invalid")
190+
return EventTypeSendETH, token, big.NewInt(0), errors.New("data for BigInt is invalid")
191191
}
192192

193193
canonicalTokenData := decodedData[offset.Int64()+canonicalTokenDataStartingindex*32:]
@@ -211,14 +211,14 @@ func decodeDataAsNFT(decodedData []byte) (EventType, CanonicalToken, *big.Int, e
211211
} else if offset.Int64() == 160 {
212212
offset, ok := new(big.Int).SetString(common.Bytes2Hex((chunks[canonicalTokenDataStartingindex+4])), 16)
213213
if !ok || offset.Int64()%32 != 0 {
214-
return EventTypeSendETH, token, big.NewInt(0), fmt.Errorf("data for BigInt is invalid")
214+
return EventTypeSendETH, token, big.NewInt(0), errors.New("data for BigInt is invalid")
215215
}
216216

217217
indexOffset := canonicalTokenDataStartingindex + int64(offset.Int64()/32)
218218

219219
length, ok := new(big.Int).SetString(common.Bytes2Hex((chunks[indexOffset])), 16)
220220
if !ok {
221-
return EventTypeSendETH, token, big.NewInt(0), fmt.Errorf("data for BigInt is invalid")
221+
return EventTypeSendETH, token, big.NewInt(0), errors.New("data for BigInt is invalid")
222222
}
223223

224224
amount := big.NewInt(0)
@@ -364,7 +364,7 @@ func DecodeRevertReason(hexStr string) (string, error) {
364364

365365
// Ensure the data is long enough to contain a valid revert reason
366366
if len(data) < 68 {
367-
return "", fmt.Errorf("data too short to contain a valid revert reason")
367+
return "", errors.New("data too short to contain a valid revert reason")
368368
}
369369

370370
// The revert reason is encoded in the data returned by a failed transaction call
@@ -377,7 +377,7 @@ func DecodeRevertReason(hexStr string) (string, error) {
377377

378378
// Ensure the data contains the full revert string
379379
if uint64(len(data)) < 68+strLen {
380-
return "", fmt.Errorf("data too short to contain the full revert reason")
380+
return "", errors.New("data too short to contain the full revert reason")
381381
}
382382

383383
// Extract the revert reason string

0 commit comments

Comments
 (0)