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

Merged
merged 1 commit into from
Feb 24, 2024
Merged

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

merged 1 commit into from
Feb 24, 2024

Conversation

0x2d3c
Copy link
Contributor

@0x2d3c 0x2d3c commented Feb 24, 2024

Parameterless errors should be using errors.New instead of fmt.Errorf

Summary by CodeRabbit

  • Refactor
    • Improved error handling mechanism across the application by standardizing error message creation for enhanced consistency and clarity.

@0x2d3c 0x2d3c requested a review from a team as a code owner February 24, 2024 18:14
Copy link
Contributor

coderabbitai bot commented Feb 24, 2024

Walkthrough

Walkthrough

The overall change focuses on standardizing the error handling mechanism across various parts of the codebase. This is achieved by replacing the use of fmt.Errorf with errors.New for creating error messages. This modification ensures consistency in error handling and potentially improves the clarity of error messages by enforcing a simpler creation pattern that doesn't involve formatting directives.

Changes

Files Change Summary
codec/proto_codec.go, codec/types/interface_registry.go, codec/types/any_test.go, math/int.go Replaced fmt.Errorf with errors.New for error creation. Added errors package import where necessary.
x/tx/.../decode.go, x/tx/signing/aminojson/..., x/tx/signing/directaux/direct_aux.go, x/tx/signing/textual/... Updated error handling by importing errors package and switching from fmt.Errorf to errors.New for error messages. Grouped due to similar changes across various files in the x/tx/signing directory and its subdirectories.

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-tests for this file.
  • 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 tests 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 from git and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit tests.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

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 a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

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

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • 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/coderabbit-overrides.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

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.

Review Status

Actionable comments generated: 0

Configuration used: .coderabbit.yml

Commits Files that changed from the base of the PR and between ccd8d5e and 4d2f0a7.
Files selected for processing (14)
  • codec/proto_codec.go (1 hunks)
  • codec/types/any_test.go (2 hunks)
  • codec/types/interface_registry.go (4 hunks)
  • math/int.go (1 hunks)
  • x/tx/decode/decode.go (6 hunks)
  • x/tx/signing/aminojson/aminojson.go (2 hunks)
  • x/tx/signing/aminojson/json_marshal_test.go (2 hunks)
  • x/tx/signing/aminojson/time.go (4 hunks)
  • x/tx/signing/context.go (1 hunks)
  • x/tx/signing/directaux/direct_aux.go (3 hunks)
  • x/tx/signing/textual/any.go (2 hunks)
  • x/tx/signing/textual/coin_test.go (2 hunks)
  • x/tx/signing/textual/coins.go (3 hunks)
  • x/tx/signing/textual/handler.go (3 hunks)
Additional comments: 28
codec/types/any_test.go (2)
  • 4-4: The change from importing fmt to errors is appropriate for the context of this PR, focusing on standardizing error handling where formatting is not required.
  • 20-20: Using errors.New for creating errAlways is a good practice when the error message does not require dynamic data or formatting. This aligns with the PR's objective of enhancing code quality and consistency.
x/tx/signing/aminojson/time.go (2)
  • 4-4: Adding the errors package is necessary for the new error handling approach using errors.New, which is consistent with the PR's objectives.
  • 23-23: Replacing fmt.Errorf with errors.New in both marshalTimestamp and marshalDuration functions is appropriate for error messages that do not require formatting. This change enhances consistency and readability in error handling.

Also applies to: 28-28, 57-57, 69-69

x/tx/signing/aminojson/aminojson.go (2)
  • 5-5: The addition of the errors package supports the use of errors.New for creating error messages, aligning with the PR's objectives of improving error handling consistency.
  • 82-82: Changing the error creation to use errors.New instead of fmt.Errorf for a static error message is a good practice, enhancing code readability and consistency.
x/tx/signing/directaux/direct_aux.go (2)
  • 5-5: Adding the errors package is necessary for the new approach to error handling using errors.New, which aligns with the PR's goal of standardizing error creation.
  • 38-38: Replacing fmt.Errorf with errors.New for creating error messages without formatting requirements is a good practice, enhancing the consistency and readability of error handling.

Also applies to: 64-64

x/tx/decode/decode.go (2)
  • 4-4: The change from importing the standard errors package to errorsmod suggests the introduction of a custom error handling package, which could offer additional functionality such as error wrapping. This aligns with the PR's goal of enhancing error handling consistency but introduces a custom approach.

Also applies to: 10-10

  • 36-36: Replacing fmt.Errorf with errorsmod.Wrap for error creation and wrapping is consistent with the PR's objectives of improving error handling. The use of errorsmod.Wrap indicates a move towards more detailed error handling, potentially offering better error context and traceability.

Also applies to: 49-49, 58-58, 71-71, 76-76, 84-84, 89-89, 104-104, 109-109

x/tx/signing/textual/coin_test.go (1)
  • 6-6: Replacing fmt.Errorf with errors.New for creating the expErr variable is appropriate for static error messages, enhancing the consistency and readability of error handling.

Also applies to: 59-59

x/tx/signing/textual/any.go (1)
  • 5-5: Adding the errors package and changing error creation to use errors.New in the Parse function of anyValueRenderer is consistent with the PR's goal of enhancing error handling consistency. This approach is appropriate for static error messages.

Also applies to: 78-78

x/tx/signing/aminojson/json_marshal_test.go (2)
  • 5-5: The addition of the errors package import is appropriate given the change from fmt.Errorf to errors.New in the TestMarshalDuration function.
  • 201-201: Replacing fmt.Errorf with errors.New for creating simple error messages without formatting directives aligns with the PR's objective and is a good practice for error handling in Go.
x/tx/signing/textual/coins.go (3)
  • 5-5: The addition of the errors package import is appropriate given the changes from fmt.Errorf to errors.New in the coinsValueRenderer struct's methods.
  • 36-36: Replacing fmt.Errorf with errors.New in the Format method when the coin metadata querier is nil is a good practice for creating simple error messages.
  • 62-62: Using errors.New instead of fmt.Errorf in the FormatRepeated method for the same reason as above is consistent with the PR's objective and improves code readability.
x/tx/signing/textual/handler.go (3)
  • 6-6: The addition of the errors package import is appropriate given the change from fmt.Errorf to errors.New for error handling messages.
  • 71-71: Replacing fmt.Errorf with errors.New when the coinMetadataQuerier is nil is a good practice for creating simple error messages without formatting directives.
  • 138-138: Using errors.New instead of fmt.Errorf for indicating that value renderers cannot format values of type map aligns with the PR's objective and improves code readability.
codec/types/interface_registry.go (5)
  • 4-4: The addition of the errors package import is appropriate given the replacement of fmt.Errorf with errors.New for creating error messages without formatting directives.
  • 142-142: Replacing fmt.Errorf with errors.New for the error message "proto files must be provided" is correct since the message does not require any dynamic data or formatting. This aligns with the PR's objective to use errors.New for simple error messages.
  • 288-288: The use of errors.New for the error message "UnpackAny expects a pointer" is appropriate as the message is static and does not involve variable data. This change enhances consistency in error handling.
  • 370-370: The replacement of fmt.Errorf with errors.New for the error message related to the requirement of a proper address codec implementation is suitable since the message is static. This change is in line with the PR's goal of standardizing error creation.
  • 374-374: Using errors.New for the error message about the need for a proper address codec implementation for address conversion is correct. This message is static and does not require formatting, making errors.New the preferred method for creating the error.
codec/proto_codec.go (1)
  • 147-147: Replacing fmt.Errorf with errors.New in the MarshalJSON method for the error message "cannot protobuf JSON encode nil" is appropriate. This change is consistent with the PR's objective to use errors.New for static error messages, improving error handling consistency.
x/tx/signing/context.go (1)
  • 224-224: The change from fmt.Errorf to errors.New correctly aligns with the PR's objective to use errors.New for simple error messages without formatting. This enhances code consistency and readability.
math/int.go (1)
  • 553-553: The replacement of fmt.Errorf with errors.New for creating a simple error message without formatting is correctly implemented. This change aligns with the PR's objective and enhances code consistency.

@julienrbrt julienrbrt changed the title improve: use errors.New to replace fmt.Errorf with no parameters refactor: use errors.New to replace fmt.Errorf with no parameters Feb 24, 2024
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.

Thank you!

@julienrbrt julienrbrt added this pull request to the merge queue Feb 24, 2024
Merged via the queue into cosmos:main with commit aa9ff3d Feb 24, 2024
56 of 61 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants