all: replace fmt.Errorf() with errors.New() if no param required #29126 (#1175)

This commit is contained in:
JukLee0ira 2025-07-01 17:46:50 +08:00 committed by GitHub
parent f8c116af7b
commit c0315121b4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 14 additions and 13 deletions

View file

@ -17,6 +17,7 @@
package eip1559
import (
"errors"
"fmt"
"math/big"
@ -39,7 +40,7 @@ func VerifyEip1559Header(config *params.ChainConfig, header *types.Header) error
// Verify the header is not malformed
if header.BaseFee == nil {
return fmt.Errorf("header is missing baseFee")
return errors.New("header is missing baseFee")
}
// Verify the baseFee is correct based on the current header.

View file

@ -552,7 +552,7 @@ func NewJsTracer(code string, ctx *Context) (*JsTracer, error) {
hasExit := tracer.vm.GetPropString(tracer.tracerObject, "exit")
tracer.vm.Pop()
if hasEnter != hasExit {
return nil, fmt.Errorf("trace object must expose either both or none of enter() and exit()")
return nil, errors.New("trace object must expose either both or none of enter() and exit()")
}
tracer.traceCallFrames = hasEnter && hasExit
tracer.traceSteps = hasStep

View file

@ -482,7 +482,7 @@ func (s *PersonalAccountAPI) SignTransaction(ctx context.Context, args Transacti
// No need to obtain the noncelock mutex, since we won't be sending this
// tx into the transaction pool, but right back to the user
if args.From == nil {
return nil, fmt.Errorf("sender not specified")
return nil, errors.New("sender not specified")
}
if args.Gas == nil {
return nil, errors.New("gas not specified")

View file

@ -19,7 +19,6 @@ package ethapi
import (
"context"
"errors"
"fmt"
"math/big"
"reflect"
"testing"
@ -159,28 +158,28 @@ func TestSetFeeDefaults(t *testing.T) {
false,
&TransactionArgs{MaxFeePerGas: maxFee},
nil,
fmt.Errorf("maxFeePerGas and maxPriorityFeePerGas are not valid before EIP-1559 is active"),
errors.New("maxFeePerGas and maxPriorityFeePerGas are not valid before EIP-1559 is active"),
},
{
"dynamic fee tx pre-London, priorityFee set",
false,
&TransactionArgs{MaxPriorityFeePerGas: fortytwo},
nil,
fmt.Errorf("maxFeePerGas and maxPriorityFeePerGas are not valid before EIP-1559 is active"),
errors.New("maxFeePerGas and maxPriorityFeePerGas are not valid before EIP-1559 is active"),
},
{
"dynamic fee tx, maxFee < priorityFee",
true,
&TransactionArgs{MaxFeePerGas: maxFee, MaxPriorityFeePerGas: (*hexutil.Big)(big.NewInt(1000))},
nil,
fmt.Errorf("maxFeePerGas (0x3e) < maxPriorityFeePerGas (0x3e8)"),
errors.New("maxFeePerGas (0x3e) < maxPriorityFeePerGas (0x3e8)"),
},
{
"dynamic fee tx, maxFee < priorityFee while setting default",
true,
&TransactionArgs{MaxFeePerGas: (*hexutil.Big)(big.NewInt(7))},
nil,
fmt.Errorf("maxFeePerGas (0x7) < maxPriorityFeePerGas (0x2a)"),
errors.New("maxFeePerGas (0x7) < maxPriorityFeePerGas (0x2a)"),
},
{
"dynamic fee tx post-London, explicit gas price",
@ -196,21 +195,21 @@ func TestSetFeeDefaults(t *testing.T) {
false,
&TransactionArgs{GasPrice: fortytwo, MaxFeePerGas: maxFee, MaxPriorityFeePerGas: fortytwo},
nil,
fmt.Errorf("both gasPrice and (maxFeePerGas or maxPriorityFeePerGas) specified"),
errors.New("both gasPrice and (maxFeePerGas or maxPriorityFeePerGas) specified"),
},
{
"set gas price and maxPriorityFee",
false,
&TransactionArgs{GasPrice: fortytwo, MaxPriorityFeePerGas: fortytwo},
nil,
fmt.Errorf("both gasPrice and (maxFeePerGas or maxPriorityFeePerGas) specified"),
errors.New("both gasPrice and (maxFeePerGas or maxPriorityFeePerGas) specified"),
},
{
"set gas price and maxFee",
true,
&TransactionArgs{GasPrice: fortytwo, MaxFeePerGas: maxFee},
nil,
fmt.Errorf("both gasPrice and (maxFeePerGas or maxPriorityFeePerGas) specified"),
errors.New("both gasPrice and (maxFeePerGas or maxPriorityFeePerGas) specified"),
},
}

View file

@ -19,6 +19,7 @@ package node
import (
"compress/gzip"
"context"
"errors"
"fmt"
"io"
"net"
@ -296,7 +297,7 @@ func (h *httpServer) enableRPC(apis []rpc.API, config httpConfig) error {
defer h.mu.Unlock()
if h.rpcAllowed() {
return fmt.Errorf("JSON-RPC over HTTP is already enabled")
return errors.New("JSON-RPC over HTTP is already enabled")
}
// Create RPC server and handler.
@ -332,7 +333,7 @@ func (h *httpServer) enableWS(apis []rpc.API, config wsConfig) error {
defer h.mu.Unlock()
if h.wsAllowed() {
return fmt.Errorf("JSON-RPC over WebSocket is already enabled")
return errors.New("JSON-RPC over WebSocket is already enabled")
}
// Create RPC server and handler.