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

fix(x/staking): avoid overriding error #23076

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions x/staking/keeper/delegation.go
Original file line number Diff line number Diff line change
Expand Up @@ -858,8 +858,8 @@ func (k Keeper) getBeginInfo(
return completionTime, height, false, nil
}
headerInfo := k.HeaderService.HeaderInfo(ctx)
unbondingTime, err := k.UnbondingTime(ctx)
if err != nil {
unbondingTime, err2 := k.UnbondingTime(ctx)
if err2 != nil {
Comment on lines +861 to +862
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Correct the returned error variable to match the renamed one.

Currently, the code captures the error in err2 but returns the outer err, which could be uninitialized or stale. To ensure we return the right error, align the return statement with the newly introduced variable:

- unbondingTime, err2 := k.UnbondingTime(ctx)
- if err2 != nil {
-     return completionTime, height, false, err
- }
+ unbondingTime, err := k.UnbondingTime(ctx)
+ if err != nil {
+     return completionTime, height, false, err
+ }

Committable suggestion skipped: line range outside the PR's diff.

return completionTime, height, false, err
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
return completionTime, height, false, err
return completionTime, height, false, errors.Join(err, err2)

We should error join the two errors, otherwise we miss the second one now.

}

Expand Down
Loading