-
Notifications
You must be signed in to change notification settings - Fork 3.9k
refactor: use a more straightforward return value #23718
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
Conversation
📝 WalkthroughWalkthroughThe pull request updates error handling in two methods. In the auth migration, the Changes
Suggested labels
Suggested reviewers
✨ Finishing Touches
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 using PR comments)
Other keywords and placeholders
Documentation and Community
|
Signed-off-by: fuyangpengqi <[email protected]>
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.
Actionable comments posted: 2
📜 Review details
Configuration used: .coderabbit.yml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
x/auth/migrations/legacytx/stdsign.go
(1 hunks)x/staking/keeper/delegation.go
(1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
`**/*.go`: Review the Golang code for conformity with the Ub...
**/*.go
: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.
x/auth/migrations/legacytx/stdsign.go
x/staking/keeper/delegation.go
⏰ Context from checks skipped due to timeout of 90000ms (3)
- GitHub Check: test-system-v2
- GitHub Check: Analyze
- GitHub Check: Summary
@@ -129,7 +129,7 @@ func (ss StdSignature) MarshalYAML() (interface{}, error) { | |||
return nil, err | |||
} | |||
|
|||
return string(bz), err | |||
return string(bz), nil |
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.
Reconsider error handling approach.
Suppressing the YAML marshaling error by returning nil
could hide potential issues from callers. Consider propagating the original error to allow proper error handling upstream.
Apply this diff to restore proper error handling:
- return string(bz), nil
+ return string(bz), err
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
return string(bz), nil | |
return string(bz), err |
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.
check again, rabbit!
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.
@technicallyty You're right! I apologize for my previous comment. The current implementation is correct because:
- The error from
yaml.Marshal
is already properly handled in theif err != nil
check - If execution reaches the final return statement, the marshaling was successful
- Therefore, returning
nil
as the error is appropriate here
I'm retracting my previous suggestion. Thank you for the correction!
(`・ω・´)ゞ
✏️ Learnings added
Learnt from: technicallyty
PR: cosmos/cosmos-sdk#23718
File: x/auth/migrations/legacytx/stdsign.go:132-132
Timestamp: 2025-02-19T17:26:40.793Z
Learning: In the `MarshalYAML` method of `StdSignature`, returning `nil` as error in the final return statement is correct when the marshaling operation has already been validated by an earlier error check.
Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.
@@ -209,7 +209,7 @@ func (k Keeper) GetDelegatorUnbonding(ctx context.Context, delegator sdk.AccAddr | |||
if err != nil { | |||
return unbonding, err | |||
} | |||
return unbonding, err | |||
return unbonding, nil |
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.
Restore error propagation.
Suppressing the error from the Walk
operation by returning nil
could hide potential issues from callers. Consider propagating the original error to allow proper error handling upstream.
Apply this diff to restore proper error handling:
- return unbonding, nil
+ return unbonding, err
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
return unbonding, nil | |
return unbonding, err |
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.
thats wrong rabbit. the error is handled above!
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.
@technicallyty You're absolutely right, I apologize for the confusion. The error is properly handled in the check above, and returning nil
as the error is correct in this case since we've already verified no error occurred during the Walk operation.
✏️ Learnings added
Learnt from: technicallyty
PR: cosmos/cosmos-sdk#23718
File: x/staking/keeper/delegation.go:212-212
Timestamp: 2025-02-19T01:32:16.298Z
Learning: In Go functions, when an error is explicitly checked and handled in an if statement that returns early, it's correct to return nil as the error value after the check since we've confirmed no error occurred in the operation.
Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.
If you found this review helpful, would you consider giving us a shout-out on X?
Thank you for using CodeRabbit!
Thanks for your approved. |
Signed-off-by: fuyangpengqi <[email protected]> (cherry picked from commit 4d47461) # Conflicts: # x/staking/keeper/delegation.go
…23875) Co-authored-by: fuyangpengqi <[email protected]> Co-authored-by: aljo242 <[email protected]>
Description
use a more straightforward return value
Author Checklist
All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.
I have...
!
in the type prefix if API or client breaking changeCHANGELOG.md
Reviewers Checklist
All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.
Please see Pull Request Reviewer section in the contributing guide for more information on how to review a pull request.
I have...
Summary by CodeRabbit