-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
Conversation
WalkthroughWalkthroughThe overall change focuses on standardizing the error handling mechanism across various parts of the codebase. This is achieved by replacing the use of Changes
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? TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Additionally, you can add CodeRabbit Configration File (
|
There was a problem hiding this 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
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
toerrors
is appropriate for the context of this PR, focusing on standardizing error handling where formatting is not required.- 20-20: Using
errors.New
for creatingerrAlways
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 usingerrors.New
, which is consistent with the PR's objectives.- 23-23: Replacing
fmt.Errorf
witherrors.New
in bothmarshalTimestamp
andmarshalDuration
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 oferrors.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 offmt.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 usingerrors.New
, which aligns with the PR's goal of standardizing error creation.- 38-38: Replacing
fmt.Errorf
witherrors.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 toerrorsmod
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
witherrorsmod.Wrap
for error creation and wrapping is consistent with the PR's objectives of improving error handling. The use oferrorsmod.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
witherrors.New
for creating theexpErr
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 useerrors.New
in theParse
function ofanyValueRenderer
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 fromfmt.Errorf
toerrors.New
in theTestMarshalDuration
function.- 201-201: Replacing
fmt.Errorf
witherrors.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 fromfmt.Errorf
toerrors.New
in thecoinsValueRenderer
struct's methods.- 36-36: Replacing
fmt.Errorf
witherrors.New
in theFormat
method when the coin metadata querier is nil is a good practice for creating simple error messages.- 62-62: Using
errors.New
instead offmt.Errorf
in theFormatRepeated
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 fromfmt.Errorf
toerrors.New
for error handling messages.- 71-71: Replacing
fmt.Errorf
witherrors.New
when thecoinMetadataQuerier
is nil is a good practice for creating simple error messages without formatting directives.- 138-138: Using
errors.New
instead offmt.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 offmt.Errorf
witherrors.New
for creating error messages without formatting directives.- 142-142: Replacing
fmt.Errorf
witherrors.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 useerrors.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
witherrors.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, makingerrors.New
the preferred method for creating the error.codec/proto_codec.go (1)
- 147-147: Replacing
fmt.Errorf
witherrors.New
in theMarshalJSON
method for the error message "cannot protobuf JSON encode nil" is appropriate. This change is consistent with the PR's objective to useerrors.New
for static error messages, improving error handling consistency.x/tx/signing/context.go (1)
- 224-224: The change from
fmt.Errorf
toerrors.New
correctly aligns with the PR's objective to useerrors.New
for simple error messages without formatting. This enhances code consistency and readability.math/int.go (1)
- 553-553: The replacement of
fmt.Errorf
witherrors.New
for creating a simple error message without formatting is correctly implemented. This change aligns with the PR's objective and enhances code consistency.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you!
Parameterless errors should be using errors.New instead of fmt.Errorf
Summary by CodeRabbit