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

refactor: use errors.New to replace fmt.Errorf with no parameters #21394

Merged
merged 2 commits into from
Aug 25, 2024

Conversation

xiaobei0715
Copy link
Contributor

@xiaobei0715 xiaobei0715 commented Aug 25, 2024

Description

Similar to #20943

Summary by CodeRabbit

  • Bug Fixes

    • Improved error handling across multiple functions for clearer and more consistent error messages.
  • Chores

    • Streamlined error creation by replacing fmt.Errorf with errors.New throughout the codebase for enhanced readability and maintainability.

@xiaobei0715 xiaobei0715 requested a review from a team as a code owner August 25, 2024 09:29
Copy link
Contributor

coderabbitai bot commented Aug 25, 2024

Walkthrough

Walkthrough

The changes involve an update in error handling across multiple files in the codebase, replacing the use of fmt.Errorf with errors.New for generating error messages. This modification aims to streamline error creation while preserving the existing logic and control flow of the affected functions.

Changes

Files Change Summary
schema/appdata/async_test.go Replaced fmt.Errorf with errors.New in Commit and OnKVPair functions.
server/v2/stf/util.go Updated error handling in getExecutionCtxFromContext to use errors.New.
server/v2/store/snapshot.go Changed LoadArchiveCmd to utilize errors.New for error messages.
store/v2/root/factory.go Modified CreateRootStore to replace fmt.Errorf with errors.New for unsupported store type errors.
store/v2/root/store.go Amended LoadVersionAndUpgrade and loadVersion methods to use errors.New.
x/distribution/keeper/validator.go Updated error handling in IncrementValidatorPeriod and decrementReferenceCount to use errors.New and pkgerr.Is.
x/genutil/genesis.go Replaced fmt.Errorf in InitGenesis with errors.New for error messages.

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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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 as 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.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

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.

@github-actions github-actions bot added C:x/distribution distribution module related C:Store C:x/genutil genutil module issues C:server/v2 Issues related to server/v2 C:schema C:server/v2 stf labels Aug 25, 2024
Copy link
Contributor

@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, codebase verification and nitpick comments (1)
server/v2/store/snapshot.go (1)

340-345: Consider optimizing snapshot comparison.

Using reflect.DeepEqual for comparing large or complex snapshots might be inefficient. If performance is a concern, consider implementing a more efficient comparison method specific to the snapshot's structure.

Review details

Configuration used: .coderabbit.yml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between a554a21 and 26eaff7.

Files selected for processing (7)
  • schema/appdata/async_test.go (3 hunks)
  • server/v2/stf/util.go (2 hunks)
  • server/v2/store/snapshot.go (1 hunks)
  • store/v2/root/factory.go (1 hunks)
  • store/v2/root/store.go (2 hunks)
  • x/distribution/keeper/validator.go (2 hunks)
  • x/genutil/genesis.go (2 hunks)
Files skipped from review due to trivial changes (3)
  • server/v2/stf/util.go
  • store/v2/root/store.go
  • x/genutil/genesis.go
Additional context used
Path-based instructions (4)
schema/appdata/async_test.go (2)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.


Pattern **/*_test.go: "Assess the unit test code assessing sufficient code coverage for the changes associated in the pull request"

store/v2/root/factory.go (1)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.

x/distribution/keeper/validator.go (1)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.

server/v2/store/snapshot.go (1)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.

Additional comments not posted (6)
schema/appdata/async_test.go (2)

81-81: Approved change to error handling in Commit method.

The replacement of fmt.Errorf with errors.New is consistent with the PR's objective to standardize error handling. The change is straightforward and does not introduce any new issues.


144-144: Approved change to error handling in OnKVPair method.

The change from fmt.Errorf to errors.New is appropriate and aligns with the PR's goal of simplifying error creation. The new error handling is correctly implemented.

store/v2/root/factory.go (2)

142-142: Approved change to error handling for unsupported SCType.

The change from fmt.Errorf to errors.New is consistent with the PR's objective. The new error handling method enhances clarity and maintains the semantic meaning of the error.


144-144: Approved change to error handling for unsupported store type.

This change simplifies the error creation process and aligns with the PR's goal of standardizing error handling. The implementation is correct and does not introduce any new issues.

x/distribution/keeper/validator.go (1)

148-148: Approved change to error handling in decrementReferenceCount.

The replacement of fmt.Errorf with errors.New for handling zero reference count is appropriate and aligns with the PR's objective of simplifying error creation. The implementation is correct and does not introduce any new issues.

server/v2/store/snapshot.go (1)

340-340: Approved changes from fmt.Errorf to errors.New.

The changes correctly replace formatted error messages with simpler ones where no formatting parameters are used, aligning with the PR's objectives.

Also applies to: 345-345

Copy link
Contributor

@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

Review details

Configuration used: .coderabbit.yml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between a554a21 and 26eaff7.

Files selected for processing (7)
  • schema/appdata/async_test.go (3 hunks)
  • server/v2/stf/util.go (2 hunks)
  • server/v2/store/snapshot.go (1 hunks)
  • store/v2/root/factory.go (1 hunks)
  • store/v2/root/store.go (2 hunks)
  • x/distribution/keeper/validator.go (2 hunks)
  • x/genutil/genesis.go (2 hunks)
Files skipped from review due to trivial changes (6)
  • server/v2/stf/util.go
  • server/v2/store/snapshot.go
  • store/v2/root/factory.go
  • store/v2/root/store.go
  • x/distribution/keeper/validator.go
  • x/genutil/genesis.go
Additional context used
Path-based instructions (1)
schema/appdata/async_test.go (2)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.


Pattern **/*_test.go: "Assess the unit test code assessing sufficient code coverage for the changes associated in the pull request"

Additional comments not posted (2)
schema/appdata/async_test.go (2)

81-81: Refactor to errors.New is appropriate for static error messages.

The change from fmt.Errorf to errors.New is consistent with the PR's objective to simplify error creation when no formatting is needed. This enhances readability and maintainability.


144-144: Refactor to errors.New is appropriate for static error messages.

The change from fmt.Errorf to errors.New is consistent with the PR's objective to simplify error creation when no formatting is needed. This enhances readability and maintainability.

Copy link
Contributor

@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

Review details

Configuration used: .coderabbit.yml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between a554a21 and 26eaff7.

Files selected for processing (7)
  • schema/appdata/async_test.go (3 hunks)
  • server/v2/stf/util.go (2 hunks)
  • server/v2/store/snapshot.go (1 hunks)
  • store/v2/root/factory.go (1 hunks)
  • store/v2/root/store.go (2 hunks)
  • x/distribution/keeper/validator.go (2 hunks)
  • x/genutil/genesis.go (2 hunks)
Files skipped from review due to trivial changes (3)
  • server/v2/stf/util.go
  • store/v2/root/factory.go
  • x/genutil/genesis.go
Additional context used
Path-based instructions (4)
schema/appdata/async_test.go (2)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.


Pattern **/*_test.go: "Assess the unit test code assessing sufficient code coverage for the changes associated in the pull request"

x/distribution/keeper/validator.go (1)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.

server/v2/store/snapshot.go (1)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.

store/v2/root/store.go (1)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.

Additional comments not posted (8)
schema/appdata/async_test.go (2)

81-81: Approved change to error handling in Commit.

The use of errors.New is appropriate for static error messages, enhancing code clarity.


144-144: Approved change to error handling in OnKVPair.

Switching to errors.New for static error messages is a good practice for improving readability.

x/distribution/keeper/validator.go (1)

148-148: Approved change to error handling in decrementReferenceCount.

Using errors.New for static error messages simplifies the error creation process and enhances code clarity.

server/v2/store/snapshot.go (2)

340-340: Approved change to error handling in LoadArchiveCmd.

The transition to errors.New for static error messages is appropriate and improves code clarity.


345-345: Approved change to error handling in LoadArchiveCmd.

Using errors.New for static error messages is consistent with the PR's objectives and enhances readability.

store/v2/root/store.go (3)

248-248: Approved replacement of fmt.Errorf with errors.New.

The change correctly replaces fmt.Errorf with errors.New for a static error message, aligning with the PR's objectives.


256-256: Approved replacement of fmt.Errorf with errors.New.

This change is consistent with the PR's goal of using errors.New for static error messages.


286-286: Approved replacement of fmt.Errorf with errors.New.

The change correctly replaces fmt.Errorf with errors.New for a static error message, aligning with the PR's objectives.

Copy link
Contributor

@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

Review details

Configuration used: .coderabbit.yml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 26eaff7 and 1a81c21.

Files selected for processing (1)
  • x/distribution/keeper/validator.go (4 hunks)
Files skipped from review as they are similar to previous changes (1)
  • x/distribution/keeper/validator.go

@tac0turtle tac0turtle added this pull request to the merge queue Aug 25, 2024
Merged via the queue into cosmos:main with commit c40cf3e Aug 25, 2024
73 of 74 checks passed
@xiaobei0715 xiaobei0715 deleted the chore/error-new branch October 14, 2024 14:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C:schema C:server/v2 stf C:server/v2 Issues related to server/v2 C:Store C:x/distribution distribution module related C:x/genutil genutil module issues
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants