From c65fe727d23e3f48946c990551328bd66ccc60de Mon Sep 17 00:00:00 2001 From: LesCyber Date: Mon, 3 Mar 2025 21:27:44 +0800 Subject: [PATCH] refactor: use errors.New to replace fmt.Errorf with no parameters Signed-off-by: LesCyber --- block/sync_service.go | 8 ++++---- cmd/rollkit/commands/run_node.go | 4 ++-- node/full.go | 2 +- node/full_client.go | 8 ++++---- state/executor.go | 2 +- 5 files changed, 12 insertions(+), 12 deletions(-) diff --git a/block/sync_service.go b/block/sync_service.go index 3a7c3585e2..82a4c0b187 100644 --- a/block/sync_service.go +++ b/block/sync_service.go @@ -108,7 +108,7 @@ func (syncService *SyncService[H]) Store() *goheaderstore.Store[H] { func (syncService *SyncService[H]) initStoreAndStartSyncer(ctx context.Context, initial H) error { if initial.IsZero() { - return fmt.Errorf("failed to initialize the store and start syncer") + return errors.New("failed to initialize the store and start syncer") } if err := syncService.store.Init(ctx, initial); err != nil { return err @@ -123,13 +123,13 @@ func (syncService *SyncService[H]) initStoreAndStartSyncer(ctx context.Context, // Note: Only returns an error in case store can't be initialized. Logs error if there's one while broadcasting. func (syncService *SyncService[H]) WriteToStoreAndBroadcast(ctx context.Context, headerOrData H) error { if syncService.genesis.InitialHeight < 0 { - return fmt.Errorf("invalid initial height; cannot be negative") + return errors.New("invalid initial height; cannot be negative") } isGenesis := headerOrData.Height() == uint64(syncService.genesis.InitialHeight) // For genesis header/block initialize the store and start the syncer if isGenesis { if err := syncService.store.Init(ctx, headerOrData); err != nil { - return fmt.Errorf("failed to initialize the store") + return errors.New("failed to initialize the store") } } @@ -137,7 +137,7 @@ func (syncService *SyncService[H]) WriteToStoreAndBroadcast(ctx context.Context, if !syncService.syncerStatus.started.Load() { firstStart = true if err := syncService.StartSyncer(ctx); err != nil { - return fmt.Errorf("failed to start syncer after initializing the store") + return errors.New("failed to start syncer after initializing the store") } } diff --git a/cmd/rollkit/commands/run_node.go b/cmd/rollkit/commands/run_node.go index de8030ae6e..27213795e5 100644 --- a/cmd/rollkit/commands/run_node.go +++ b/cmd/rollkit/commands/run_node.go @@ -220,10 +220,10 @@ func NewRunNodeCmd() *cobra.Command { return err } if res.Block.Height == 0 { - return fmt.Errorf("node hasn't produced any blocks") + return errors.New("node hasn't produced any blocks") } if !rollnode.IsRunning() { - return fmt.Errorf("node is not running") + return errors.New("node is not running") } diff --git a/node/full.go b/node/full.go index 458c9b919b..0286e7b63e 100644 --- a/node/full.go +++ b/node/full.go @@ -237,7 +237,7 @@ func initDALC(nodeConfig config.NodeConfig, logger log.Logger) (*da.DAClient, er } if nodeConfig.DAGasMultiplier < 0 { - return nil, fmt.Errorf("gas multiplier must be greater than or equal to zero") + return nil, errors.New("gas multiplier must be greater than or equal to zero") } client, err := proxyda.NewClient(nodeConfig.DAAddress, nodeConfig.DAAuthToken) diff --git a/node/full_client.go b/node/full_client.go index c40929f11c..8fc4740151 100644 --- a/node/full_client.go +++ b/node/full_client.go @@ -286,12 +286,12 @@ func (c *FullClient) GenesisChunked(context context.Context, id uint) (*ctypes.R return nil, fmt.Errorf("error while creating chunks of the genesis document: %w", err) } if genChunks == nil { - return nil, fmt.Errorf("service configuration error, genesis chunks are not initialized") + return nil, errors.New("service configuration error, genesis chunks are not initialized") } chunkLen := len(genChunks) if chunkLen == 0 { - return nil, fmt.Errorf("service configuration error, there are no chunks") + return nil, errors.New("service configuration error, there are no chunks") } if int(id) > chunkLen-1 { //nolint:gosec @@ -526,7 +526,7 @@ func (c *FullClient) Validators(ctx context.Context, heightPtr *int64, pagePtr, genesisValidators := c.node.GetGenesis().Validators if len(genesisValidators) != 1 { - return nil, fmt.Errorf("there should be exactly one validator in genesis") + return nil, errors.New("there should be exactly one validator in genesis") } // Since it's a centralized sequencer // changed behavior to get this from genesis @@ -740,7 +740,7 @@ func (c *FullClient) Status(ctx context.Context) (*ctypes.ResultStatus, error) { genesisValidators := c.node.GetGenesis().Validators if len(genesisValidators) != 1 { - return nil, fmt.Errorf("there should be exactly one validator in genesis") + return nil, errors.New("there should be exactly one validator in genesis") } // Changed behavior to get this from genesis diff --git a/state/executor.go b/state/executor.go index d5ce1df0db..e26216033e 100644 --- a/state/executor.go +++ b/state/executor.go @@ -214,7 +214,7 @@ func (e *BlockExecutor) ApplyBlock(ctx context.Context, state types.State, heade return types.State{}, nil, err } if !isAppValid { - return types.State{}, nil, fmt.Errorf("proposal processing resulted in an invalid application state") + return types.State{}, nil, errors.New("proposal processing resulted in an invalid application state") } err = e.Validate(state, header, data)