Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: use errors.New to replace fmt.Errorf with no parameters #1013

Merged
merged 1 commit into from
Dec 8, 2024

Conversation

ChengenH
Copy link
Contributor

@ChengenH ChengenH commented Dec 8, 2024

No description provided.

Signed-off-by: ChengenH <hce19970702@gmail.com>
@ChengenH ChengenH requested a review from a team as a code owner December 8, 2024 10:39
Copy link

coderabbitai bot commented Dec 8, 2024

Warning

There were issues while running some tools. Please review the errors and either fix the tool’s configuration or disable the tool if it’s a critical failure.

🔧 golangci-lint (1.62.2)

level=warning msg="The linter 'exportloopref' is deprecated (since v1.60.2) due to: Since Go1.22 (loopvar) this linter is no longer relevant. Replaced by copyloopvar."
level=error msg="Running error: context loading failed: no go files to analyze: running go mod tidy may solve the problem"

Walkthrough

The pull request primarily focuses on enhancing error handling across multiple files by replacing instances of fmt.Errorf with errors.New. This change simplifies error creation, making the error messages more straightforward. Additionally, some files introduce new fields or methods related to data management, particularly in the Tree structure. Overall, the changes improve the clarity and maintainability of the code without altering the existing logic or functionality.

Changes

File Path Change Summary
cmd/iaviewer/main.go Updated error handling in OpenDB function; replaced fmt.Errorf with errors.New.
mutable_tree.go Updated error handling in balance and SaveChangeSet methods; replaced fmt.Errorf with errors.New.
nodedb.go Updated error handling in saveFastNodeUnlocked; replaced fmt.Errorf with errors.New.
proof.go Updated error variables ErrInvalidProof, ErrInvalidInputs, and ErrInvalidRoot to use errors.New.
proof_ics23.go Replaced fmt.Errorf with errors.New in GetNonMembershipProof, GetProof, and GetMembershipProof methods.
v2/export.go Updated ErrorExportDone variable to use errors.New; added import for errors.
v2/migrate/v0/migrate_v0.go Updated error handling in latestVersionCommand; replaced fmt.Errorf with errors.New.
v2/node.go Updated error handling in getLeftNode, getRightNode, and balance methods; replaced fmt.Errorf with errors.New.
v2/sqlite.go Updated error handling in EstimateMmapSize; replaced fmt.Errorf with errors.New; added import for errors.
v2/sqlite_metadata.go Updated error handling in NewSqliteKVStore; replaced fmt.Errorf with errors.New.
v2/tree.go Updated error handling in LoadVersion; replaced fmt.Errorf with errors.New; added field deletes and method addDelete.

Possibly related PRs

Suggested reviewers

  • tac0turtle
  • yihuang

Poem

🐰 In the code where errors lay,
A rabbit hops to clear the way.
With errors.New, the path is bright,
Simplifying woes, making it right.
No more fmt, just straightforward cheer,
Hopping through code, we have no fear! 🐇


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ 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.
    • Generate unit testing code for this file.
    • 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. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • 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 src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

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

Documentation and Community

  • 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

🧹 Outside diff range and nitpick comments (1)
v2/migrate/v0/migrate_v0.go (1)

Empty if block needs implementation for setting the latest version

Based on the code context, this is a command that handles both getting and setting the latest version in the metadata.sqlite database. While the 'get' functionality is implemented in the else block, the 'set' functionality is completely missing in the if block. This confirms the original review comment about the empty if block being an incomplete implementation.

The empty block should contain logic to:

  • Serialize the version number to protobuf format
  • Store it in the database using the latestVersionKey
🔗 Analysis chain

Line range hint 118-119: Empty if block needs implementation.

The if set { } block is empty, which suggests incomplete implementation. This could lead to silent failures when attempting to set the version.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check if there are any TODOs or related implementation notes
rg -i "todo.*latest.*version|implement.*set.*version" 

Length of output: 55


Script:

#!/bin/bash
# Let's check the surrounding context of the empty if block
rg -B 5 -A 5 "if set \{" v2/migrate/v0/migrate_v0.go

Length of output: 262


Script:

#!/bin/bash
# Let's also check for any similar patterns or implementations in the codebase
ast-grep --pattern 'if set {
  $$$
}'

Length of output: 765


Script:

#!/bin/bash
# Let's see the entire function implementation for better context
ast-grep --pattern 'func LatestVersion($$$) {
  $$$
}'

Length of output: 56


Script:

#!/bin/bash
# Let's check the function name and its full implementation
rg -B 10 -A 20 "func.*Version.*\(" v2/migrate/v0/migrate_v0.go

Length of output: 820

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between a989ed4 and 0f97ca7.

📒 Files selected for processing (11)
  • cmd/iaviewer/main.go (2 hunks)
  • mutable_tree.go (2 hunks)
  • nodedb.go (1 hunks)
  • proof.go (1 hunks)
  • proof_ics23.go (3 hunks)
  • v2/export.go (2 hunks)
  • v2/migrate/v0/migrate_v0.go (2 hunks)
  • v2/node.go (3 hunks)
  • v2/sqlite.go (2 hunks)
  • v2/sqlite_metadata.go (2 hunks)
  • v2/tree.go (2 hunks)
🧰 Additional context used
🪛 golangci-lint (1.62.2)
proof_ics23.go

5-5: File is not gofumpt-ed

(gofumpt)

🔇 Additional comments (14)
v2/export.go (1)

3-5: LGTM: Appropriate use of errors.New

The change from fmt.Errorf to errors.New is correct here since the error message doesn't require any formatting.

Also applies to: 103-103

v2/sqlite_metadata.go (1)

4-4: LGTM: Appropriate use of errors.New

The change from fmt.Errorf to errors.New is correct here since the error message doesn't require any formatting.

Also applies to: 23-23

cmd/iaviewer/main.go (1)

7-7: LGTM: Appropriate use of errors.New

The change from fmt.Errorf to errors.New is correct here since the error message doesn't require any formatting. The remaining fmt.Errorf usage in the file is correctly left unchanged as it requires string formatting.

Also applies to: 71-71

proof.go (1)

22-28: LGTM! Good improvement in error handling.

The replacement of fmt.Errorf with errors.New for static error messages is appropriate here. This change:

  • Improves performance by avoiding unnecessary string formatting
  • Follows Go best practices for declaring constant error values
proof_ics23.go (1)

50-50: LGTM! Appropriate use of errors.New.

The changes correctly replace fmt.Errorf with errors.New for static error messages, improving code clarity and performance.

Also applies to: 179-179

v2/migrate/v0/migrate_v0.go (1)

115-115: LGTM! Good error handling improvement.

The replacement of fmt.Errorf with errors.New for the static error message is appropriate.

v2/node.go (3)

105-105: LGTM! Good simplification of error handling

The change from fmt.Errorf to errors.New is appropriate here since the error message is static and requires no formatting.


120-120: LGTM! Consistent error handling

The change to errors.New matches the similar change in getLeftNode, maintaining consistency in error handling throughout the codebase.


161-161: LGTM! Simplified error creation

The change to errors.New is appropriate for this static error message when attempting to balance a persisted node.

v2/tree.go (1)

106-106: LGTM! Appropriate error handling

The change to errors.New is suitable for this nil check error message.

v2/sqlite.go (1)

103-103: LGTM! Simplified error message

The change to errors.New is appropriate for this static "no row" error message.

mutable_tree.go (2)

963-963: LGTM: Good simplification of error handling

The change from fmt.Errorf to errors.New is appropriate here since the error message is static and doesn't require any string formatting.


1087-1087: LGTM: Appropriate error handling simplification

The change from fmt.Errorf to errors.New is correct here as the error message is static and doesn't require string interpolation.

nodedb.go (1)

363-363: LGTM: Simplified error handling

The change from fmt.Errorf to errors.New is appropriate here since the error message is static and doesn't require any string formatting.

@julienrbrt julienrbrt merged commit 456159f into cosmos:master Dec 8, 2024
8 of 9 checks passed
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