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 #20943

Merged
merged 2 commits into from
Jul 18, 2024

Conversation

0x2d3c
Copy link
Contributor

@0x2d3c 0x2d3c commented Jul 12, 2024

Description

Closes: #20608

Summary by CodeRabbit

  • Refactor
    • Improved error handling consistency by replacing fmt.Errorf with errors.New across multiple functions and files.

Copy link
Contributor

coderabbitai bot commented Jul 12, 2024

Caution

Review failed

The pull request is closed.

Walkthrough

Walkthrough

The changes involve refactoring error handling across multiple files by replacing fmt.Errorf with errors.New where no parameter formatting is required. This refactor aims to standardize error message creation for consistency and clarity without altering the functionalities or the public API.

Changes

Files Change Summaries
baseapp/abci_utils.go, client/config/config.go, client/prompt_validation.go, client/pruning/main.go Updated error creation from fmt.Errorf to errors.New for consistency.
client/rpc/tx.go Replaced errors with sdkerrors and updated error message formatting.
client/v2/autocli/flag/pubkey.go, client/v2/autocli/query.go Changed error handling from fmt.Errorf to errors.New for specific error messages.
runtime/router.go Updated error creation in CanInvoke methods to use errors.New.
schema/decoding/resolver_test.go Replaced fmt.Errorf with errors.New for generating test errors.
schema/enum.go Modified import statements and error handling to use errors.New.
server/util.go Updated the error message handling for customAppTemplate and customConfig variables.
store/v2/root/factory.go Replaced fmt.Errorf with errors.New for unsupported database type errors.
telemetry/metrics.go Introduced the use of errors.New for error creation in gatherPrometheus and gatherGeneric.
testutil/key.go Changed error creation to use errors.New in the GenerateSaveCoinKey function.
tools/cosmovisor/process.go Updated error handling messages to use errors.New in Launcher methods.
types/tx/types.go Switched error generation to use errors.New in the ValidateBasic method of the Tx struct.
x/auth/client/cli/query.go, x/auth/client/cli/tx_sign.go Replaced fmt.Errorf with errors.New and updated error handling consistency.
x/authz/client/cli/tx.go Changed to use errors.New for creating spend-limit validation errors.
x/genutil/types/genesis.go Updated error handling in ValidateAndComplete method to use errors.New.
x/protocolpool/keeper/keeper.go Replaced fmt.Errorf with errors.New for various fund distribution and budget proposal errors.
x/staking/types/authz.go Modified error handling to use errors.New in ValidateBasic and normalizeAuthzType functions.

Assessment against linked issues

Objective (Issue) Addressed Explanation
Standardize error message creation by using errors.New instead of fmt.Errorf with no parameters (#20608)

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.

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
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 dc5c16b and 32c4c0d.

Files selected for processing (22)
  • baseapp/abci_utils.go (1 hunks)
  • client/config/config.go (2 hunks)
  • client/prompt_validation.go (2 hunks)
  • client/pruning/main.go (2 hunks)
  • client/rpc/tx.go (4 hunks)
  • client/v2/autocli/flag/pubkey.go (2 hunks)
  • client/v2/autocli/query.go (3 hunks)
  • runtime/router.go (3 hunks)
  • schema/decoding/resolver_test.go (2 hunks)
  • schema/enum.go (2 hunks)
  • server/util.go (1 hunks)
  • store/v2/root/factory.go (3 hunks)
  • telemetry/metrics.go (3 hunks)
  • testutil/key.go (2 hunks)
  • tools/cosmovisor/process.go (2 hunks)
  • types/tx/types.go (2 hunks)
  • x/auth/client/cli/query.go (6 hunks)
  • x/auth/client/cli/tx_sign.go (3 hunks)
  • x/authz/client/cli/tx.go (2 hunks)
  • x/genutil/types/genesis.go (1 hunks)
  • x/protocolpool/keeper/keeper.go (7 hunks)
  • x/staking/types/authz.go (3 hunks)
Files skipped from review due to trivial changes (3)
  • baseapp/abci_utils.go
  • server/util.go
  • tools/cosmovisor/process.go
Additional context used
Path-based instructions (19)
client/v2/autocli/flag/pubkey.go (1)

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

client/prompt_validation.go (1)

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

testutil/key.go (1)

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

schema/enum.go (1)

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

schema/decoding/resolver_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.

client/pruning/main.go (1)

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

runtime/router.go (1)

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

client/config/config.go (1)

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

x/auth/client/cli/query.go (1)

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

types/tx/types.go (1)

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

client/rpc/tx.go (1)

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

x/genutil/types/genesis.go (1)

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

client/v2/autocli/query.go (1)

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

x/staking/types/authz.go (1)

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

telemetry/metrics.go (1)

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

x/authz/client/cli/tx.go (1)

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

x/auth/client/cli/tx_sign.go (1)

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

x/protocolpool/keeper/keeper.go (1)

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

Additional comments not posted (59)
client/v2/autocli/flag/pubkey.go (1)

51-51: LGTM!

The change from fmt.Errorf to errors.New is correct and improves consistency.

client/prompt_validation.go (1)

15-15: LGTM!

The change from fmt.Errorf to errors.New is correct and improves consistency.

testutil/key.go (2)

50-50: LGTM!

The change from fmt.Errorf to errors.New is correct and improves consistency.


55-55: LGTM!

The change from fmt.Errorf to errors.New is correct and improves consistency.

schema/enum.go (1)

28-28: LGTM!

The change from fmt.Errorf to errors.New is correct and improves consistency.

schema/decoding/resolver_test.go (2)

4-4: LGTM!

The import of errors is correct and necessary for the change.


108-108: LGTM!

The change from fmt.Errorf to errors.New is correct and simplifies the error creation.

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

4-4: LGTM!

The import of errors is correct and necessary for the change.


80-80: LGTM!

The change from fmt.Errorf to errors.New is correct and simplifies the error creation for unsupported rocksdb.


114-114: LGTM!

The change from fmt.Errorf to errors.New is correct and simplifies the error creation for unsupported iavl v2.

client/pruning/main.go (2)

4-4: LGTM!

The import of errors is correct and necessary for the change.


80-80: LGTM!

The change from fmt.Errorf to errors.New is correct and simplifies the error creation for unsupported pruning.

runtime/router.go (3)

5-5: LGTM!

The import of errors is correct and necessary for the change.


35-35: LGTM!

The change from fmt.Errorf to errors.New is correct and simplifies the error creation for missing type URLs.


98-98: LGTM!

The change from fmt.Errorf to errors.New is correct and simplifies the error creation for missing type URLs.

client/config/config.go (2)

5-5: Import errors package.

The import of the errors package is necessary for the refactoring.


72-72: Refactor: Use errors.New instead of fmt.Errorf.

The change correctly replaces fmt.Errorf with errors.New since no formatting is needed.

x/auth/client/cli/query.go (7)

4-4: Import errors package.

The import of the errors package is necessary for the refactoring.


105-105: Refactor: Use errors.New instead of fmt.Errorf.

The change correctly replaces fmt.Errorf("argument should be a tx hash") with errors.New("argument should be a tx hash") since no formatting is needed.


139-139: Refactor: Use errors.New instead of fmt.Errorf.

The change correctly replaces fmt.Errorf("found no txs matching given signatures") with errors.New("found no txs matching given signatures") since no formatting is needed.


144-144: Use sdkerrors.ErrLogic.Wrapf for specific error.

The use of sdkerrors.ErrLogic.Wrapf is appropriate for wrapping logic errors.


151-151: Refactor: Use errors.New instead of fmt.Errorf.

The change correctly replaces fmt.Errorf("acc_seq type takes an argument '<addr>/<seq>'") with errors.New("acc_seq type takes an argument '<addr>/<seq>'") since no formatting is needed.


162-162: Refactor: Use errors.New instead of fmt.Errorf.

The change correctly replaces fmt.Errorf("found no txs matching given address and sequence combination") with errors.New("found no txs matching given address and sequence combination") since no formatting is needed.


187-187: Refactor: Use errors.New instead of fmt.Errorf.

The change correctly replaces fmt.Errorf("argument should be comma-separated signatures") with errors.New("argument should be comma-separated signatures") since no formatting is needed.

types/tx/types.go (5)

4-4: Import errors package.

The import of the errors package is necessary for the refactoring.


43-43: Refactor: Use errors.New instead of fmt.Errorf.

The change correctly replaces fmt.Errorf("bad Tx") with errors.New("bad Tx") since no formatting is needed.


48-48: Refactor: Use errors.New instead of fmt.Errorf.

The change correctly replaces fmt.Errorf("missing TxBody") with errors.New("missing TxBody") since no formatting is needed.


53-53: Refactor: Use errors.New instead of fmt.Errorf.

The change correctly replaces fmt.Errorf("missing AuthInfo") with errors.New("missing AuthInfo") since no formatting is needed.


58-58: Refactor: Use errors.New instead of fmt.Errorf.

The change correctly replaces fmt.Errorf("missing fee") with errors.New("missing fee") since no formatting is needed.

client/rpc/tx.go (2)

7-7: Import errors package.

The import of the errors package is necessary for the refactoring.


226-226: Refactor: Use errors.New instead of fmt.Errorf.

The change correctly replaces fmt.Errorf("txhash not found") with errors.New("txhash not found") since no formatting is needed.

x/genutil/types/genesis.go (1)

212-212: Replace fmt.Errorf with errors.New

The fmt.Errorf is replaced with errors.New for better consistency and clarity. The change is correct and aligns with the PR objectives.

client/v2/autocli/query.go (5)

5-5: Add missing import for errors package

The errors package is imported to replace fmt.Errorf with errors.New. This change is necessary for the new error handling approach.


180-180: Replace fmt.Errorf with errors.New

The fmt.Errorf is replaced with errors.New for better consistency and clarity. The change is correct and aligns with the PR objectives.


187-187: Replace fmt.Errorf with errors.New

The fmt.Errorf is replaced with errors.New for better consistency and clarity. The change is correct and aligns with the PR objectives.


203-203: Replace fmt.Errorf with errors.New

The fmt.Errorf is replaced with errors.New for better consistency and clarity. The change is correct and aligns with the PR objectives.


210-210: Replace fmt.Errorf with errors.New

The fmt.Errorf is replaced with errors.New for better consistency and clarity. The change is correct and aligns with the PR objectives.

x/staking/types/authz.go (4)

5-5: Add missing import for errors package

The errors package is imported to replace fmt.Errorf with errors.New. This change is necessary for the new error handling approach.


67-68: Replace fmt.Errorf with errors.New

The fmt.Errorf is replaced with errors.New wrapped by errorsmod.Wrapf for better consistency and clarity. The change is correct and aligns with the PR objectives.


72-72: Replace fmt.Errorf with errors.New

The fmt.Errorf is replaced with errors.New for better consistency and clarity. The change is correct and aligns with the PR objectives.


223-224: Replace fmt.Errorf with errors.New

The fmt.Errorf is replaced with errors.New wrapped by errorsmod.Wrapf for better consistency and clarity. The change is correct and aligns with the PR objectives.

telemetry/metrics.go (3)

6-6: Add missing import for errors package

The errors package is imported to replace fmt.Errorf with errors.New. This change is necessary for the new error handling approach.


196-196: Replace fmt.Errorf with errors.New

The fmt.Errorf is replaced with errors.New for better consistency and clarity. The change is correct and aligns with the PR objectives.


222-222: Replace fmt.Errorf with errors.New

The fmt.Errorf is replaced with errors.New for better consistency and clarity. The change is correct and aligns with the PR objectives.

x/authz/client/cli/tx.go (1)

140-140: LGTM! Consistent use of errors.New.

The change from fmt.Errorf to errors.New improves consistency in error handling.

x/auth/client/cli/tx_sign.go (2)

261-261: LGTM! Consistent use of errors.New.

The change from fmt.Errorf to errors.New improves consistency in error handling.


453-453: LGTM! Consistent use of errors.New.

The change from fmt.Errorf to errors.New improves consistency in error handling.

x/protocolpool/keeper/keeper.go (12)

199-199: LGTM! Consistent use of errors.New.

The change from fmt.Errorf to errors.New improves consistency in error handling.


275-275: LGTM! Consistent use of errors.New.

The change from fmt.Errorf to errors.New improves consistency in error handling.


359-359: LGTM! Consistent use of errors.New.

The change from fmt.Errorf to errors.New improves consistency in error handling.


377-377: LGTM! Consistent use of errors.New.

The change from fmt.Errorf to errors.New improves consistency in error handling.


418-418: LGTM! Consistent use of errors.New.

The change from fmt.Errorf to errors.New improves consistency in error handling.


431-431: LGTM! Consistent use of errors.New.

The change from fmt.Errorf to errors.New improves consistency in error handling.


435-435: LGTM! Consistent use of errors.New.

The change from fmt.Errorf to errors.New improves consistency in error handling.


439-439: LGTM! Consistent use of errors.New.

The change from fmt.Errorf to errors.New improves consistency in error handling.


458-458: LGTM! Consistent use of errors.New.

The change from fmt.Errorf to errors.New improves consistency in error handling.


461-461: LGTM! Consistent use of errors.New.

The change from fmt.Errorf to errors.New improves consistency in error handling.


464-464: LGTM! Consistent use of errors.New.

The change from fmt.Errorf to errors.New improves consistency in error handling.


470-470: LGTM! Consistent use of errors.New.

The change from fmt.Errorf to errors.New improves consistency in error handling.

@tac0turtle
Copy link
Member

Hey thanks for opening this or again. I'll sit down on Monday to see what's going on. Thank you for sticking with it

Copy link
Member

@julienrbrt julienrbrt left a comment

Choose a reason for hiding this comment

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

lgtm! could you revert cosmovisor and store/v2 to see if ci passes?
looks like it upsets golangci-lint

@0x2d3c
Copy link
Contributor Author

0x2d3c commented Jul 13, 2024

Hey thanks for opening this or again. I'll sit down on Monday to see what's going on. Thank you for sticking with it

I just happened to have some time recently, and the content is relatively simple. Have a nice weekend

@0x2d3c
Copy link
Contributor Author

0x2d3c commented Jul 13, 2024

lgtm! could you revert cosmovisor and store/v2 to see if ci passes? looks like it upsets golangci-lint

Ok, thanks for the tip, I'll try it.

@tac0turtle tac0turtle merged commit 3304d08 into cosmos:main Jul 18, 2024
64 of 67 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants