Skip to content

Conversation

RiceChuan
Copy link

@RiceChuan RiceChuan commented Aug 19, 2025

chore: suggest using errors.New instead of fmt.Errorf with no parameters

Summary by CodeRabbit

  • Refactor
    • Standardized error handling across components for consistency and maintainability. No changes to functionality or user experience.
  • Chores
    • Updated imports to align with the new error handling approach.

Copy link

coderabbitai bot commented Aug 19, 2025

Walkthrough

Replaced several fmt.Errorf(...) calls with errors.New(...) across three files, adding the errors import where needed. Error messages and control flow remain unchanged; no public APIs were modified.

Changes

Cohort / File(s) Summary of Changes
Error construction standardization
rollup/cmd/permissionless_batches/app/app.go, rollup/internal/controller/relayer/l2_relayer_sanity.go, rollup/internal/controller/sender/transaction_signer.go
Switched error creation from fmt.Errorf(...) to errors.New(...); added errors import; preserved error messages and logic; no API/signature changes.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Possibly related PRs

Suggested reviewers

  • jonastheis
  • georgehao
  • Thegaram

Poem

I nudge my nose at tidy errs,
Replacing fmt with simpler purrs.
A hop, a skip, imports aligned,
The code now whispers, clearly signed.
Small carrots, big smiles—compile time purrs. 🥕🐇

Tip

🔌 Remote MCP (Model Context Protocol) integration is now available!

Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (4)
rollup/internal/controller/relayer/l2_relayer_sanity.go (3)

66-66: Replace remaining fmt.Errorf calls without formatting with errors.New for consistency

There are still several fmt.Errorf sites that don’t use formatting directives. Converting them improves clarity and follows the PR objective.

Apply this diff:

--- a/rollup/internal/controller/relayer/l2_relayer_sanity.go
+++ b/rollup/internal/controller/relayer/l2_relayer_sanity.go
@@
-        return nil, fmt.Errorf("failed to type assert version to uint8")
+        return nil, errors.New("failed to type assert version to uint8")
@@
-        return nil, fmt.Errorf("failed to type assert parentBatchHash to [32]uint8")
+        return nil, errors.New("failed to type assert parentBatchHash to [32]uint8")
@@
-        return nil, fmt.Errorf("failed to type assert lastBatchHash to [32]uint8")
+        return nil, errors.New("failed to type assert lastBatchHash to [32]uint8")
@@
-        return fmt.Errorf("no batches to validate")
+        return errors.New("no batches to validate")
@@
-        return fmt.Errorf("chunk is nil")
+        return errors.New("chunk is nil")
@@
-        return fmt.Errorf("no blobs provided")
+        return errors.New("no blobs provided")

Also applies to: 71-71, 77-77, 166-166, 289-289, 340-340


169-176: Avoid a potential index-out-of-range panic when the first batch has zero chunks

firstChunk := batchesToValidate[0].Chunks[0] can panic if the first batch has an empty Chunks slice. You do check for empty chunks later per-batch, but this early access precedes that guard.

Minimal guard:

@@
-    // Get previous chunk for continuity check
-    firstChunk := batchesToValidate[0].Chunks[0]
+    // Get previous chunk for continuity check
+    if len(batchesToValidate[0].Chunks) == 0 {
+        return fmt.Errorf("batch %d has no chunks", batchesToValidate[0].Batch.Index)
+    }
+    firstChunk := batchesToValidate[0].Chunks[0]

4-4: Refactor static fmt.Errorf calls to errors.New

A repo-wide scan uncovered 14 instances where fmt.Errorf is used with a plain string literal (no formatting directives). These should be replaced with errors.New("…") for clarity and to avoid unnecessary formatting overhead. Please update each occurrence (adding an import "errors" if needed):

  • rollup/internal/controller/relayer/full_recovery.go:243
  • rollup/internal/controller/relayer/l2_relayer_sanity.go:66, 71, 77, 166, 289, 340
  • rollup/internal/controller/permissionless_batches/minimal_recovery.go:183
  • rollup/internal/controller/relayer/l2_relayer.go:296, 1039, 1269
  • coordinator/internal/logic/provertask/prover_task.go:197
  • coordinator/internal/controller/api/l2_syncer.go:30
  • bridge-history-api/internal/controller/fetcher/l1_fetcher.go:60

Example:

- return fmt.Errorf("no finalized batches to process")
+ return errors.New("no finalized batches to process")
rollup/cmd/permissionless_batches/app/app.go (1)

55-67: Optional: extract config validation into a helper for readability

Not required for this PR, but action is getting dense. Consider a small validateRecoveryConfig(cfg) helper to keep action focused on orchestration.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 1f2b397 and cd0cbf2.

📒 Files selected for processing (3)
  • rollup/cmd/permissionless_batches/app/app.go (2 hunks)
  • rollup/internal/controller/relayer/l2_relayer_sanity.go (2 hunks)
  • rollup/internal/controller/sender/transaction_signer.go (3 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
rollup/cmd/permissionless_batches/app/app.go (1)
rollup/internal/config/recovery.go (1)
  • RecoveryConfig (3-14)
🔇 Additional comments (4)
rollup/internal/controller/relayer/l2_relayer_sanity.go (2)

4-4: LGTM: importing errors is appropriate for static error values

The file still uses fmt for wrapped/parameterized errors elsewhere, so both imports are necessary.


22-22: LGTM: use errors.New for a static message

Switching from fmt.Errorf to errors.New here is correct and aligns with the PR goal. No behavior change.

rollup/cmd/permissionless_batches/app/app.go (1)

5-5: LGTM: consistent use of errors.New for static validation errors

These config sanity checks all return static error strings, so switching to errors.New is correct and aligns with the PR objective. fmt remains needed elsewhere for wrapped/parameterized errors and printing.

Also applies to: 57-57, 61-61, 63-63, 66-66

rollup/internal/controller/sender/transaction_signer.go (1)

5-5: LGTM: swapped to errors.New where no formatting is used

  • Importing errors is necessary and retained alongside fmt for wrapped/parameterized errors.
  • Using errors.New for the empty signer address and unknown signer type paths is correct and matches the PR goal.

Also applies to: 55-55, 98-98

@Thegaram Thegaram closed this Aug 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants