Skip to content

Commit

Permalink
Lint: Fix violations of non-constant format string in call (#14974)
Browse files Browse the repository at this point in the history
* Fix violations of non-constant format string in call

* Changelog fragment
  • Loading branch information
prestonvanloon authored Feb 21, 2025
1 parent 9bceaa5 commit 014dbd5
Show file tree
Hide file tree
Showing 18 changed files with 35 additions and 45 deletions.
6 changes: 2 additions & 4 deletions beacon-chain/forkchoice/doubly-linked-tree/proposer_boost.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package doublylinkedtree

import (
"fmt"

fieldparams "github.com/prysmaticlabs/prysm/v5/config/fieldparams"
"github.com/prysmaticlabs/prysm/v5/config/params"
)
Expand All @@ -15,7 +13,7 @@ func (f *ForkChoice) applyProposerBoostScore() error {
if s.previousProposerBoostRoot != params.BeaconConfig().ZeroHash {
previousNode, ok := s.nodeByRoot[s.previousProposerBoostRoot]
if !ok || previousNode == nil {
log.WithError(errInvalidProposerBoostRoot).Errorf(fmt.Sprintf("invalid prev root %#x", s.previousProposerBoostRoot))
log.WithError(errInvalidProposerBoostRoot).Errorf("invalid prev root %#x", s.previousProposerBoostRoot)
} else {
previousNode.balance -= s.previousProposerBoostScore
}
Expand All @@ -24,7 +22,7 @@ func (f *ForkChoice) applyProposerBoostScore() error {
if s.proposerBoostRoot != params.BeaconConfig().ZeroHash {
currentNode, ok := s.nodeByRoot[s.proposerBoostRoot]
if !ok || currentNode == nil {
log.WithError(errInvalidProposerBoostRoot).Errorf(fmt.Sprintf("invalid current root %#x", s.proposerBoostRoot))
log.WithError(errInvalidProposerBoostRoot).Errorf("invalid current root %#x", s.proposerBoostRoot)
} else {
proposerScore = (s.committeeWeight * params.BeaconConfig().ProposerScoreBoost) / 100
currentNode.balance += proposerScore
Expand Down
2 changes: 1 addition & 1 deletion beacon-chain/node/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ func configureExecutionSetting(cliCtx *cli.Context) error {
}

if !cliCtx.IsSet(flags.SuggestedFeeRecipient.Name) {
log.Warnf("In order to receive transaction fees from proposing blocks, " +
log.Warn("In order to receive transaction fees from proposing blocks, " +
"you must provide flag --" + flags.SuggestedFeeRecipient.Name + " with a valid ethereum address when starting your beacon node. " +
"Please see our documentation for more information on this requirement (https://docs.prylabs.network/docs/execution-node/fee-recipient).")
return nil
Expand Down
3 changes: 1 addition & 2 deletions beacon-chain/p2p/utils_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package p2p

import (
"fmt"
"testing"

"github.com/ethereum/go-ethereum/crypto"
Expand All @@ -28,7 +27,7 @@ func TestVerifyConnectivity(t *testing.T) {
{"123.123.123.123", 19000, false, "Dialing an unreachable IP: 123.123.123.123:19000"},
}
for _, tc := range cases {
t.Run(fmt.Sprintf(tc.name),
t.Run(tc.name,
func(t *testing.T) {
verifyConnectivity(tc.address, tc.port, "tcp")
logMessage := "IP address is not accessible"
Expand Down
2 changes: 1 addition & 1 deletion beacon-chain/rpc/eth/builder/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ func buildExpectedWithdrawalsData(withdrawals []*enginev1.Withdrawal) []*structs

func handleWrapError(err error, message string, code int) *httputil.DefaultJsonError {
return &httputil.DefaultJsonError{
Message: errors.Wrapf(err, message).Error(),
Message: errors.Wrap(err, message).Error(),
Code: code,
}
}
2 changes: 1 addition & 1 deletion beacon-chain/rpc/eth/events/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ func newTopicRequest(topics []string) (*topicRequest, error) {
} else if topicsForOpsFeed[name] {
req.needOpsFeed = true
} else {
return nil, errors.Wrapf(errInvalidTopicName, name)
return nil, errors.Wrap(errInvalidTopicName, name)
}
req.topics[name] = true
}
Expand Down
2 changes: 1 addition & 1 deletion beacon-chain/rpc/eth/node/handlers_peers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ func TestGetPeers(t *testing.T) {
}
}
if !found {
t.Errorf("Expected ID '" + expectedId + "' not found")
t.Error("Expected ID '" + expectedId + "' not found")
}
}
})
Expand Down
4 changes: 2 additions & 2 deletions beacon-chain/rpc/prysm/v1alpha1/validator/proposer.go
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ func (vs *Server) PrepareBeaconProposer(
for _, r := range request.Recipients {
recipient := hexutil.Encode(r.FeeRecipient)
if !common.IsHexAddress(recipient) {
return nil, status.Errorf(codes.InvalidArgument, fmt.Sprintf("Invalid fee recipient address: %v", recipient))
return nil, status.Errorf(codes.InvalidArgument, "Invalid fee recipient address: %v", recipient)
}
// Use default address if the burn address is return
feeRecipient := primitives.ExecutionAddress(r.FeeRecipient)
Expand Down Expand Up @@ -470,7 +470,7 @@ func (vs *Server) GetFeeRecipientByPubKey(ctx context.Context, request *ethpb.Fe
}, nil
} else {
log.WithError(err).Error("An error occurred while retrieving fee recipient from db")
return nil, status.Errorf(codes.Internal, err.Error())
return nil, status.Errorf(codes.Internal, "error=%s", err)
}
}
return &ethpb.FeeRecipientByPubKeyResponse{
Expand Down
2 changes: 1 addition & 1 deletion beacon-chain/rpc/prysm/v1alpha1/validator/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ func (vs *Server) optimisticStatus(ctx context.Context) error {
return nil
}

return status.Errorf(codes.Unavailable, errOptimisticMode.Error())
return status.Errorf(codes.Unavailable, "error=%v", errOptimisticMode)
}

// validatorStatus searches for the requested validator's state and deposit to retrieve its inclusion estimate. Also returns the validators index.
Expand Down
4 changes: 2 additions & 2 deletions beacon-chain/rpc/prysm/v1alpha1/validator/sync_committee.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func (vs *Server) GetSyncMessageBlockRoot(
// It also saves the sync committee message into the pending pool for block inclusion.
func (vs *Server) SubmitSyncMessage(ctx context.Context, msg *ethpb.SyncCommitteeMessage) (*emptypb.Empty, error) {
if err := vs.CoreService.SubmitSyncMessage(ctx, msg); err != nil {
return &emptypb.Empty{}, status.Errorf(core.ErrorReasonToGRPC(err.Reason), err.Err.Error())
return &emptypb.Empty{}, status.Errorf(core.ErrorReasonToGRPC(err.Reason), "error=%s", err.Err)
}
return &emptypb.Empty{}, nil
}
Expand Down Expand Up @@ -105,7 +105,7 @@ func (vs *Server) SubmitSignedContributionAndProof(
) (*emptypb.Empty, error) {
err := vs.CoreService.SubmitSignedContributionAndProof(ctx, s)
if err != nil {
return &emptypb.Empty{}, status.Errorf(core.ErrorReasonToGRPC(err.Reason), err.Err.Error())
return &emptypb.Empty{}, status.Errorf(core.ErrorReasonToGRPC(err.Reason), "error=%s", err.Err)
}
return &emptypb.Empty{}, nil
}
Expand Down
2 changes: 1 addition & 1 deletion beacon-chain/sync/rpc_send_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ func readChunkedBlobSidecar(stream network.Stream, encoding encoder.NetworkEncod

v, found := ctxMap[bytesutil.ToBytes4(ctxb)]
if !found {
return b, errors.Wrapf(errBlobUnmarshal, fmt.Sprintf("unrecognized fork digest %#x", ctxb))
return b, errors.Wrapf(errBlobUnmarshal, "unrecognized fork digest %#x", ctxb)
}
// Only deneb and electra are supported at this time, because we lack a fork-spanning interface/union type for blobs.
// In electra, there's no changes to blob type.
Expand Down
3 changes: 3 additions & 0 deletions changelog/pvl_fmt-fix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
### Fixed

- Lint: Fix violations of non-constant format string in call
2 changes: 1 addition & 1 deletion crypto/bls/signature_batch.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func (s *SignatureBatch) VerifyVerbosely() (bool, error) {
}
}

return false, errors.Errorf(errmsg)
return false, errors.New(errmsg)
}

// Copy the attached signature batch and return it
Expand Down
4 changes: 2 additions & 2 deletions tools/analyzers/comparesame/analyzer.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ func run(pass *analysis.Pass) (interface{}, error) {
case token.EQL, token.NEQ, token.GEQ, token.LEQ, token.GTR, token.LSS:
var xBuf, yBuf bytes.Buffer
if err := printer.Fprint(&xBuf, pass.Fset, expr.X); err != nil {
pass.Reportf(expr.X.Pos(), err.Error())
pass.Reportf(expr.X.Pos(), "error=%s", err)
}
if err := printer.Fprint(&yBuf, pass.Fset, expr.Y); err != nil {
pass.Reportf(expr.Y.Pos(), err.Error())
pass.Reportf(expr.Y.Pos(), "error=%s", err)
}
if xBuf.String() == yBuf.String() {
switch expr.Op {
Expand Down
5 changes: 2 additions & 3 deletions tools/analyzers/cryptorand/analyzer.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ package cryptorand

import (
"errors"
"fmt"
"go/ast"
"strings"

Expand Down Expand Up @@ -62,8 +61,8 @@ func run(pass *analysis.Pass) (interface{}, error) {
for pkg, path := range aliases {
for _, fn := range disallowedFns {
if isPkgDot(stmt.Fun, pkg, fn) {
pass.Reportf(node.Pos(), fmt.Sprintf(
"%s: %s.%s() (from %s)", errWeakCrypto.Error(), pkg, fn, path))
pass.Reportf(node.Pos(),
"%s: %s.%s() (from %s)", errWeakCrypto.Error(), pkg, fn, path)
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion tools/analyzers/maligned/analyzer.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func run(pass *analysis.Pass) (interface{}, error) {
inspection.Preorder(nodeFilter, func(node ast.Node) {
if s, ok := node.(*ast.StructType); ok {
if err := malign(node.Pos(), pass.TypesInfo.Types[s].Type.(*types.Struct)); err != nil {
pass.Reportf(node.Pos(), err.Error())
pass.Reportf(node.Pos(), "error=%s", err)
}
}
})
Expand Down
13 changes: 5 additions & 8 deletions tools/analyzers/properpermissions/analyzer.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ package properpermissions

import (
"errors"
"fmt"
"go/ast"

"golang.org/x/tools/go/analysis"
Expand Down Expand Up @@ -75,13 +74,11 @@ func run(pass *analysis.Pass) (interface{}, error) {
if isPkgDot(stmt.Fun, alias, fn) {
pass.Reportf(
node.Pos(),
fmt.Sprintf(
"%v: %s.%s() (from %s)",
errUnsafePackage,
alias,
fn,
pkg,
),
"%v: %s.%s() (from %s)",
errUnsafePackage,
alias,
fn,
pkg,
)
}
}
Expand Down
20 changes: 7 additions & 13 deletions tools/analyzers/recursivelock/analyzer.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,30 +236,24 @@ func checkForRecLocks(node ast.Node, pass *analysis.Pass, inspect *inspector.Ins
if lockTracker.rLockSelector.isRelated(selMap, 0) {
pass.Reportf(
node.Pos(),
fmt.Sprintf(
"%v",
errNestedMixedLock,
),
"%v",
errNestedMixedLock,
)
}
if lockTracker.rLockSelector.isEqual(selMap, 0) {
pass.Reportf(
node.Pos(),
fmt.Sprintf(
"%v",
lockmode.ErrorFound(),
),
"%v",
lockmode.ErrorFound(),
)
} else {
if stack := hasNestedlock(lockTracker.rLockSelector, lockTracker.goroutinePos, selMap, call, inspect, pass, make(map[string]bool),
lockmode.UnLockName()); stack != "" {
pass.Reportf(
node.Pos(),
fmt.Sprintf(
"%v\n%v",
lockmode.ErrorFound(),
stack,
),
"%v\n%v",
lockmode.ErrorFound(),
stack,
)
}
}
Expand Down
2 changes: 1 addition & 1 deletion validator/client/beacon-api/doppelganger.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ func buildResponse(
func (c *beaconApiValidatorClient) indexToLiveness(ctx context.Context, epoch primitives.Epoch, indexes []string) (map[string]bool, error) {
livenessResponse, err := c.liveness(ctx, epoch, indexes)
if err != nil || livenessResponse.Data == nil {
return nil, errors.Wrapf(err, fmt.Sprintf("failed to get liveness for epoch %d", epoch))
return nil, errors.Wrapf(err, "failed to get liveness for epoch %d", epoch)
}

indexToLiveness := make(map[string]bool, len(livenessResponse.Data))
Expand Down

0 comments on commit 014dbd5

Please sign in to comment.