Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf(main): use errors.New to replace fmt.Errorf with no parameters #16777

Merged
merged 1 commit into from
Apr 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/eventindexer/disperser/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package disperser
import (
"crypto/ecdsa"
"database/sql"
"errors"
"fmt"
"math/big"

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

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

return &Config{
Expand Down
2 changes: 1 addition & 1 deletion packages/fork-diff/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ func main() {

err := enc.Encode(FilePatch{filePatch: fps.Patch})
if err != nil {
return "", fmt.Errorf("")
return "", errors.New("")
}
return string(t2html.Render(out.Bytes())), nil
},
Expand Down
3 changes: 2 additions & 1 deletion packages/relayer/bridge/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package bridge

import (
"crypto/ecdsa"
"errors"
"fmt"
"math/big"

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

bridgeMessageValue, ok := new(big.Int).SetString(c.String(flags.BridgeMessageValue.Name), 10)
if !ok {
return nil, fmt.Errorf("invalid bridgeMessageValue")
return nil, errors.New("invalid bridgeMessageValue")
}

return &Config{
Expand Down
16 changes: 8 additions & 8 deletions packages/relayer/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,13 +146,13 @@ func decodeDataAsERC20(decodedData []byte) (CanonicalToken, *big.Int, error) {
chunks := splitByteArray(decodedData, 32)

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// Extract the revert reason string
Expand Down
Loading