Commit c18ec265 authored by yukionfire's avatar yukionfire Committed by GitHub

chore(op-service): use `errors.New` to replace `fmt.Errorf` with no parameters (#11796)

parent 7db0f6af
...@@ -2,6 +2,7 @@ package dial ...@@ -2,6 +2,7 @@ package dial
import ( import (
"context" "context"
"errors"
"fmt" "fmt"
"testing" "testing"
"time" "time"
...@@ -204,7 +205,7 @@ func TestRollupProvider_FailoverOnErroredSequencer(t *testing.T) { ...@@ -204,7 +205,7 @@ func TestRollupProvider_FailoverOnErroredSequencer(t *testing.T) {
require.NoError(t, err) require.NoError(t, err)
require.Same(t, primarySequencer, firstSequencerUsed) require.Same(t, primarySequencer, firstSequencerUsed)
primarySequencer.ExpectSequencerActive(true, fmt.Errorf("a test error")) // error-out after that primarySequencer.ExpectSequencerActive(true, errors.New("a test error")) // error-out after that
primarySequencer.MaybeClose() primarySequencer.MaybeClose()
secondarySequencer.ExpectSequencerActive(true, nil) secondarySequencer.ExpectSequencerActive(true, nil)
secondSequencerUsed, err := rollupProvider.RollupClient(context.Background()) secondSequencerUsed, err := rollupProvider.RollupClient(context.Background())
...@@ -231,7 +232,7 @@ func TestEndpointProvider_FailoverOnErroredSequencer(t *testing.T) { ...@@ -231,7 +232,7 @@ func TestEndpointProvider_FailoverOnErroredSequencer(t *testing.T) {
require.NoError(t, err) require.NoError(t, err)
require.Same(t, primaryEthClient, firstSequencerUsed) require.Same(t, primaryEthClient, firstSequencerUsed)
primarySequencer.ExpectSequencerActive(true, fmt.Errorf("a test error")) // error out after that primarySequencer.ExpectSequencerActive(true, errors.New("a test error")) // error out after that
primarySequencer.MaybeClose() primarySequencer.MaybeClose()
primaryEthClient.MaybeClose() primaryEthClient.MaybeClose()
secondarySequencer.ExpectSequencerActive(true, nil) secondarySequencer.ExpectSequencerActive(true, nil)
...@@ -465,7 +466,7 @@ func TestRollupProvider_ConstructorErrorOnFirstSequencerOffline(t *testing.T) { ...@@ -465,7 +466,7 @@ func TestRollupProvider_ConstructorErrorOnFirstSequencerOffline(t *testing.T) {
ept := setupEndpointProviderTest(t, 2) ept := setupEndpointProviderTest(t, 2)
// First sequencer is dead, second sequencer is active // First sequencer is dead, second sequencer is active
ept.rollupClients[0].ExpectSequencerActive(false, fmt.Errorf("I am offline")) ept.rollupClients[0].ExpectSequencerActive(false, errors.New("I am offline"))
ept.rollupClients[0].MaybeClose() ept.rollupClients[0].MaybeClose()
ept.rollupClients[1].ExpectSequencerActive(true, nil) ept.rollupClients[1].ExpectSequencerActive(true, nil)
...@@ -482,7 +483,7 @@ func TestEndpointProvider_ConstructorErrorOnFirstSequencerOffline(t *testing.T) ...@@ -482,7 +483,7 @@ func TestEndpointProvider_ConstructorErrorOnFirstSequencerOffline(t *testing.T)
ept := setupEndpointProviderTest(t, 2) ept := setupEndpointProviderTest(t, 2)
// First sequencer is dead, second sequencer is active // First sequencer is dead, second sequencer is active
ept.rollupClients[0].ExpectSequencerActive(false, fmt.Errorf("I am offline")) ept.rollupClients[0].ExpectSequencerActive(false, errors.New("I am offline"))
ept.rollupClients[0].MaybeClose() ept.rollupClients[0].MaybeClose()
ept.rollupClients[1].ExpectSequencerActive(true, nil) ept.rollupClients[1].ExpectSequencerActive(true, nil)
ept.rollupClients[1].ExpectSequencerActive(true, nil) // see comment in other tests about why we expect this twice ept.rollupClients[1].ExpectSequencerActive(true, nil) // see comment in other tests about why we expect this twice
...@@ -533,7 +534,7 @@ func TestRollupProvider_FailOnAllErroredSequencers(t *testing.T) { ...@@ -533,7 +534,7 @@ func TestRollupProvider_FailOnAllErroredSequencers(t *testing.T) {
// All sequencers are inactive // All sequencers are inactive
for _, sequencer := range ept.rollupClients { for _, sequencer := range ept.rollupClients {
sequencer.ExpectSequencerActive(true, fmt.Errorf("a test error")) sequencer.ExpectSequencerActive(true, errors.New("a test error"))
sequencer.MaybeClose() sequencer.MaybeClose()
} }
...@@ -549,7 +550,7 @@ func TestEndpointProvider_FailOnAllErroredSequencers(t *testing.T) { ...@@ -549,7 +550,7 @@ func TestEndpointProvider_FailOnAllErroredSequencers(t *testing.T) {
// All sequencers are inactive // All sequencers are inactive
for _, sequencer := range ept.rollupClients { for _, sequencer := range ept.rollupClients {
sequencer.ExpectSequencerActive(true, fmt.Errorf("a test error")) sequencer.ExpectSequencerActive(true, errors.New("a test error"))
sequencer.MaybeClose() sequencer.MaybeClose()
} }
...@@ -711,7 +712,7 @@ func TestRollupProvider_HandlesManyIndexClientMismatch(t *testing.T) { ...@@ -711,7 +712,7 @@ func TestRollupProvider_HandlesManyIndexClientMismatch(t *testing.T) {
require.NoError(t, err) require.NoError(t, err)
// primarySequencer goes down // primarySequencer goes down
seq0.ExpectSequencerActive(false, fmt.Errorf("I'm offline now")) seq0.ExpectSequencerActive(false, errors.New("I'm offline now"))
seq0.MaybeClose() seq0.MaybeClose()
ept.setRollupDialOutcome(0, false) // primarySequencer fails to dial ept.setRollupDialOutcome(0, false) // primarySequencer fails to dial
// secondarySequencer is inactive, but online // secondarySequencer is inactive, but online
......
package eth package eth
import ( import (
"errors"
"fmt" "fmt"
) )
func ForkchoiceUpdateErr(payloadStatus PayloadStatusV1) error { func ForkchoiceUpdateErr(payloadStatus PayloadStatusV1) error {
switch payloadStatus.Status { switch payloadStatus.Status {
case ExecutionSyncing: case ExecutionSyncing:
return fmt.Errorf("updated forkchoice, but node is syncing") return errors.New("updated forkchoice, but node is syncing")
case ExecutionAccepted, ExecutionInvalidTerminalBlock, ExecutionInvalidBlockHash: case ExecutionAccepted, ExecutionInvalidTerminalBlock, ExecutionInvalidBlockHash:
// ACCEPTED, INVALID_TERMINAL_BLOCK, INVALID_BLOCK_HASH are only for execution // ACCEPTED, INVALID_TERMINAL_BLOCK, INVALID_BLOCK_HASH are only for execution
return fmt.Errorf("unexpected %s status, could not update forkchoice", payloadStatus.Status) return fmt.Errorf("unexpected %s status, could not update forkchoice", payloadStatus.Status)
case ExecutionInvalid: case ExecutionInvalid:
return fmt.Errorf("cannot update forkchoice, block is invalid") return errors.New("cannot update forkchoice, block is invalid")
case ExecutionValid: case ExecutionValid:
return nil return nil
default: default:
......
...@@ -69,7 +69,7 @@ func ReadUint64(r io.Reader) (uint64, error) { ...@@ -69,7 +69,7 @@ func ReadUint64(r io.Reader) (uint64, error) {
return n, fmt.Errorf("number padding was not empty: %x", readPadding[:]) return n, fmt.Errorf("number padding was not empty: %x", readPadding[:])
} }
if err := binary.Read(r, binary.BigEndian, &n); err != nil { if err := binary.Read(r, binary.BigEndian, &n); err != nil {
return 0, fmt.Errorf("expected number length to be 8 bytes") return 0, errors.New("expected number length to be 8 bytes")
} }
return n, nil return n, nil
} }
......
...@@ -2,6 +2,7 @@ package batching ...@@ -2,6 +2,7 @@ package batching
import ( import (
"context" "context"
"errors"
"fmt" "fmt"
"io" "io"
"sync" "sync"
...@@ -176,7 +177,7 @@ func (ibc *IterativeBatchCall[K, V]) Result() ([]V, error) { ...@@ -176,7 +177,7 @@ func (ibc *IterativeBatchCall[K, V]) Result() ([]V, error) {
ibc.resetLock.RLock() ibc.resetLock.RLock()
if atomic.LoadUint32(&ibc.completed) < uint32(len(ibc.requestsKeys)) { if atomic.LoadUint32(&ibc.completed) < uint32(len(ibc.requestsKeys)) {
ibc.resetLock.RUnlock() ibc.resetLock.RUnlock()
return nil, fmt.Errorf("results not available yet, Fetch more first") return nil, errors.New("results not available yet, Fetch more first")
} }
ibc.resetLock.RUnlock() ibc.resetLock.RUnlock()
return ibc.requestsValues, nil return ibc.requestsValues, nil
......
...@@ -35,7 +35,7 @@ func (c *expectedCall) Matches(rpcMethod string, args ...interface{}) error { ...@@ -35,7 +35,7 @@ func (c *expectedCall) Matches(rpcMethod string, args ...interface{}) error {
} }
callOpts, ok := args[0].(map[string]any) callOpts, ok := args[0].(map[string]any)
if !ok { if !ok {
return fmt.Errorf("arg 0 is not a map[string]any") return errors.New("arg 0 is not a map[string]any")
} }
actualBlockRef := args[1] actualBlockRef := args[1]
to, ok := callOpts["to"].(*common.Address) to, ok := callOpts["to"].(*common.Address)
......
...@@ -2,7 +2,7 @@ package sources ...@@ -2,7 +2,7 @@ package sources
import ( import (
"context" "context"
"fmt" "errors"
"net" "net"
"sync/atomic" "sync/atomic"
"testing" "testing"
...@@ -97,10 +97,10 @@ func TestLimitClient(t *testing.T) { ...@@ -97,10 +97,10 @@ func TestLimitClient(t *testing.T) {
// None of the clients should return yet // None of the clients should return yet
} }
m.errC <- fmt.Errorf("fake-error") m.errC <- errors.New("fake-error")
m.errC <- fmt.Errorf("fake-error") m.errC <- errors.New("fake-error")
require.Eventually(t, func() bool { return m.blockedCallers.Load() == 1 }, time.Second, 10*time.Millisecond) require.Eventually(t, func() bool { return m.blockedCallers.Load() == 1 }, time.Second, 10*time.Millisecond)
m.errC <- fmt.Errorf("fake-error") m.errC <- errors.New("fake-error")
require.ErrorContains(t, <-errC1, "fake-error") require.ErrorContains(t, <-errC1, "fake-error")
require.ErrorContains(t, <-errC2, "fake-error") require.ErrorContains(t, <-errC2, "fake-error")
......
package sources package sources
import ( import (
"errors"
"fmt" "fmt"
"math/big" "math/big"
"strings" "strings"
...@@ -229,7 +230,7 @@ func (block *RPCBlock) verify() error { ...@@ -229,7 +230,7 @@ func (block *RPCBlock) verify() error {
} }
if block.WithdrawalsRoot != nil { if block.WithdrawalsRoot != nil {
if block.Withdrawals == nil { if block.Withdrawals == nil {
return fmt.Errorf("expected withdrawals") return errors.New("expected withdrawals")
} }
for i, w := range *block.Withdrawals { for i, w := range *block.Withdrawals {
if w == nil { if w == nil {
......
...@@ -376,7 +376,7 @@ func (m *SimpleTxManager) craftTx(ctx context.Context, candidate TxCandidate) (* ...@@ -376,7 +376,7 @@ func (m *SimpleTxManager) craftTx(ctx context.Context, candidate TxCandidate) (*
var txMessage types.TxData var txMessage types.TxData
if sidecar != nil { if sidecar != nil {
if blobBaseFee == nil { if blobBaseFee == nil {
return nil, fmt.Errorf("expected non-nil blobBaseFee") return nil, errors.New("expected non-nil blobBaseFee")
} }
blobFeeCap := m.calcBlobFeeCap(blobBaseFee) blobFeeCap := m.calcBlobFeeCap(blobBaseFee)
message := &types.BlobTx{ message := &types.BlobTx{
...@@ -1036,19 +1036,19 @@ func errStringMatch(err, target error) bool { ...@@ -1036,19 +1036,19 @@ func errStringMatch(err, target error) bool {
func finishBlobTx(message *types.BlobTx, chainID, tip, fee, blobFee, value *big.Int) error { func finishBlobTx(message *types.BlobTx, chainID, tip, fee, blobFee, value *big.Int) error {
var o bool var o bool
if message.ChainID, o = uint256.FromBig(chainID); o { if message.ChainID, o = uint256.FromBig(chainID); o {
return fmt.Errorf("ChainID overflow") return errors.New("ChainID overflow")
} }
if message.GasTipCap, o = uint256.FromBig(tip); o { if message.GasTipCap, o = uint256.FromBig(tip); o {
return fmt.Errorf("GasTipCap overflow") return errors.New("GasTipCap overflow")
} }
if message.GasFeeCap, o = uint256.FromBig(fee); o { if message.GasFeeCap, o = uint256.FromBig(fee); o {
return fmt.Errorf("GasFeeCap overflow") return errors.New("GasFeeCap overflow")
} }
if message.BlobFeeCap, o = uint256.FromBig(blobFee); o { if message.BlobFeeCap, o = uint256.FromBig(blobFee); o {
return fmt.Errorf("BlobFeeCap overflow") return errors.New("BlobFeeCap overflow")
} }
if message.Value, o = uint256.FromBig(value); o { if message.Value, o = uint256.FromBig(value); o {
return fmt.Errorf("Value overflow") return errors.New("Value overflow")
} }
return nil return nil
} }
...@@ -669,7 +669,7 @@ func TestTxMgr_EstimateGasFails(t *testing.T) { ...@@ -669,7 +669,7 @@ func TestTxMgr_EstimateGasFails(t *testing.T) {
lastNonce := tx.Nonce() lastNonce := tx.Nonce()
// Mock gas estimation failure. // Mock gas estimation failure.
h.gasPricer.err = fmt.Errorf("execution error") h.gasPricer.err = errors.New("execution error")
_, err = h.mgr.craftTx(context.Background(), candidate) _, err = h.mgr.craftTx(context.Background(), candidate)
require.ErrorContains(t, err, "failed to estimate gas") require.ErrorContains(t, err, "failed to estimate gas")
...@@ -686,7 +686,7 @@ func TestTxMgr_SigningFails(t *testing.T) { ...@@ -686,7 +686,7 @@ func TestTxMgr_SigningFails(t *testing.T) {
cfg := configWithNumConfs(1) cfg := configWithNumConfs(1)
cfg.Signer = func(ctx context.Context, from common.Address, tx *types.Transaction) (*types.Transaction, error) { cfg.Signer = func(ctx context.Context, from common.Address, tx *types.Transaction) (*types.Transaction, error) {
if errorSigning { if errorSigning {
return nil, fmt.Errorf("signer error") return nil, errors.New("signer error")
} else { } else {
return tx, nil return tx, nil
} }
......
...@@ -130,5 +130,5 @@ func FindMonorepoRoot(startDir string) (string, error) { ...@@ -130,5 +130,5 @@ func FindMonorepoRoot(startDir string) (string, error) {
} }
dir = parentDir dir = parentDir
} }
return "", fmt.Errorf("monorepo root not found") return "", errors.New("monorepo root not found")
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment