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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(node/cmd): replace fmt.Errorf without parameters with errors.New #4030

Merged
merged 1 commit into from
Jul 24, 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
5 changes: 3 additions & 2 deletions clients/eth/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"context"
"errors"
"fmt"
"os"
"strconv"
Expand Down Expand Up @@ -183,7 +184,7 @@ func getTransactor(ethC *ethclient.Client) (*abi.AbiTransactor, error) {
addr := common.HexToAddress(contractAddress)
emptyAddr := common.Address{}
if addr == emptyAddr {
return nil, fmt.Errorf("invalid contract address")
return nil, errors.New("invalid contract address")
}

t, err := abi.NewAbiTransactor(addr, ethC)
Expand All @@ -196,7 +197,7 @@ func getTransactor(ethC *ethclient.Client) (*abi.AbiTransactor, error) {

func getGovernanceVaaAction(payload []byte) (uint8, error) {
if len(payload) < 32+2+1 {
return 0, fmt.Errorf("VAA payload does not contain a governance header")
return 0, errors.New("VAA payload does not contain a governance header")
}

return payload[32], nil
Expand Down
3 changes: 2 additions & 1 deletion node/cmd/ccq/p2p.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"context"
"encoding/hex"
"errors"
"fmt"
"net/http"
"time"
Expand Down Expand Up @@ -274,7 +275,7 @@ func runP2P(
failedQueriesByUser.WithLabelValues(pendingResponse.userName).Inc()
delete(responses, requestSignature)
select {
case pendingResponse.errCh <- &ErrorEntry{err: fmt.Errorf("quorum not met"), status: http.StatusBadRequest}:
case pendingResponse.errCh <- &ErrorEntry{err: errors.New("quorum not met"), status: http.StatusBadRequest}:
logger.Info("query failed, quorum not met",
zap.String("peerId", peerId),
zap.String("userId", pendingResponse.userName),
Expand Down
13 changes: 7 additions & 6 deletions node/cmd/ccq/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"crypto/ecdsa"
"encoding/hex"
"errors"
"fmt"
"net/http"
"time"
Expand All @@ -30,12 +31,12 @@ func FetchCurrentGuardianSet(rpcUrl, coreAddr string) (*common.GuardianSet, erro
ethContract := eth_common.HexToAddress(coreAddr)
rawClient, err := ethRpc.DialContext(ctx, rpcUrl)
if err != nil {
return nil, fmt.Errorf("failed to connect to ethereum")
return nil, errors.New("failed to connect to ethereum")
}
client := ethClient.NewClient(rawClient)
caller, err := ethAbi.NewAbiCaller(ethContract, client)
if err != nil {
return nil, fmt.Errorf("failed to create caller")
return nil, errors.New("failed to create caller")
}
currentIndex, err := caller.GetCurrentGuardianSetIndex(&ethBind.CallOpts{Context: ctx})
if err != nil {
Expand All @@ -57,7 +58,7 @@ func validateRequest(logger *zap.Logger, env common.Environment, perms *Permissi
if !exists {
logger.Debug("invalid api key", zap.String("apiKey", apiKey))
invalidQueryRequestReceived.WithLabelValues("invalid_api_key").Inc()
return http.StatusForbidden, nil, fmt.Errorf("invalid api key")
return http.StatusForbidden, nil, errors.New("invalid api key")
}

// TODO: Should we verify the signatures?
Expand All @@ -70,7 +71,7 @@ func validateRequest(logger *zap.Logger, env common.Environment, perms *Permissi
zap.Bool("signerKeyConfigured", signerKey != nil),
)
invalidQueryRequestReceived.WithLabelValues("request_not_signed").Inc()
return http.StatusBadRequest, nil, fmt.Errorf("request not signed")
return http.StatusBadRequest, nil, errors.New("request not signed")
}

// Sign the request using our key.
Expand Down Expand Up @@ -117,7 +118,7 @@ func validateRequest(logger *zap.Logger, env common.Environment, perms *Permissi
default:
logger.Debug("unsupported query type", zap.String("userName", permsForUser.userName), zap.Any("type", pcq.Query))
invalidQueryRequestReceived.WithLabelValues("unsupported_query_type").Inc()
return http.StatusBadRequest, nil, fmt.Errorf("unsupported query type")
return http.StatusBadRequest, nil, errors.New("unsupported query type")
}

if err != nil {
Expand All @@ -142,7 +143,7 @@ func validateCallData(logger *zap.Logger, permsForUser *permissionEntry, callTag
if len(cd.Data) < ETH_CALL_SIG_LENGTH {
logger.Debug("eth call data must be at least four bytes", zap.String("userName", permsForUser.userName), zap.String("data", hex.EncodeToString(cd.Data)))
invalidQueryRequestReceived.WithLabelValues("bad_call_data").Inc()
return http.StatusBadRequest, fmt.Errorf("eth call data must be at least four bytes")
return http.StatusBadRequest, errors.New("eth call data must be at least four bytes")
}
if !permsForUser.allowAnything {
call := hex.EncodeToString(cd.Data[0:ETH_CALL_SIG_LENGTH])
Expand Down
3 changes: 2 additions & 1 deletion node/cmd/guardiand/adminclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"context"
"encoding/csv"
"encoding/hex"
"errors"
"fmt"
"io"
"log"
Expand Down Expand Up @@ -238,7 +239,7 @@ func runSignWormchainValidatorAddress(cmd *cobra.Command, args []string) error {
guardianKeyPath := args[0]
wormchainAddress := args[1]
if !strings.HasPrefix(wormchainAddress, "wormhole") || strings.HasPrefix(wormchainAddress, "wormholeval") {
return fmt.Errorf("must provide a bech32 address that has 'wormhole' prefix")
return errors.New("must provide a bech32 address that has 'wormhole' prefix")
}
gk, err := common.LoadGuardianKey(guardianKeyPath, *unsafeDevnetMode)
if err != nil {
Expand Down
5 changes: 3 additions & 2 deletions node/cmd/guardiand/admintemplate.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package guardiand

import (
"encoding/hex"
"errors"
"fmt"
"log"
"math/big"
Expand Down Expand Up @@ -1214,7 +1215,7 @@ func parseAddress(s string) (string, error) {

func leftPadAddress(a []byte) (string, error) {
if len(a) > 32 {
return "", fmt.Errorf("address longer than 32 bytes")
return "", errors.New("address longer than 32 bytes")
}
return hex.EncodeToString(common.LeftPadBytes(a, 32)), nil
}
Expand Down Expand Up @@ -1246,7 +1247,7 @@ func isValidUint256(s string) (bool, error) {

// Check if i is within the range [0, 2^256 - 1]
if i.Cmp(big.NewInt(0)) < 0 || i.Cmp(upperLimit) > 0 {
return false, fmt.Errorf("value is not a valid uint256")
return false, errors.New("value is not a valid uint256")
}

return true, nil
Expand Down
Loading