Skip to content

fix dead error variable and silent invoice cancel in setStateAbandoned#1177

Open
chandachewe10 wants to merge 2 commits into
lightninglabs:masterfrom
chandachewe10:master
Open

fix dead error variable and silent invoice cancel in setStateAbandoned#1177
chandachewe10 wants to merge 2 commits into
lightninglabs:masterfrom
chandachewe10:master

Conversation

@chandachewe10

Copy link
Copy Markdown

Summary

This change fixes two issues in setStateAbandoned in loopin.go.

1. Removed a misleading <nil> from the returned error

After persistAndAnnounceState succeeds, execution can only reach the final return if err is nil, since any non-nil error returns earlier. The previous implementation still included err in the formatted error:

return fmt.Errorf("swap hash abandoned by client, swap ID: %v, %v", s.hash, err)

As a result, the returned message always ended with , <nil>, adding unnecessary noise to client responses and logs. The error message now only includes the relevant swap information.

2. Handle CancelInvoice errors consistently

Previously, the result of CancelInvoice was ignored, causing unexpected failures to go unnoticed.

The abandon path now follows the same behavior as the timeout handling:

  • Ignore ErrInvoiceAlreadySettled, since the invoice may already have been settled before the swap was abandoned.
  • Log any other unexpected error at Warn level so operators can diagnose the issue without preventing the abandon process from completing.

Testing

  • go build ./...
  • go vet ./...
  • go test -run TestLoopIn ./...

…Abandoned

The err variable is always nil when the final fmt.Errorf is reached
(a non-nil err exits earlier), producing a trailing ', <nil>' in the
error string visible to callers and in logs.

Additionally, CancelInvoice errors were silently swallowed with a
bare '_' assignment. The timeout path in the same file correctly
checks for ErrInvoiceAlreadySettled; this commit makes the abandon
path consistent: ignore already-settled invoices and log any other
unexpected error so operators can diagnose issues without failing
the abandon itself.

Co-authored-by: Chanda Chewe <chandachewe10@users.noreply.github.com>
@gemini-code-assist

Copy link
Copy Markdown

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request improves the robustness and clarity of the swap abandonment process in loopin.go. It ensures that invoice cancellation failures are handled consistently with other parts of the system and cleans up the returned error output to remove unnecessary noise.

Highlights

  • Error Message Cleanup: Removed the redundant and misleading '' suffix from the error message returned by setStateAbandoned.
  • Invoice Cancellation Handling: Updated the invoice cancellation logic to properly handle errors, ignoring ErrInvoiceAlreadySettled while logging other unexpected errors at the Warn level.
New Features

🧠 You can now enable Memory (public preview) to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize the Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counterproductive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Code Review

This pull request updates the setStateAbandoned function in loopin.go to properly handle and log errors when canceling an invoice, and cleans up the returned error message. The reviewer recommends scoping the err variable directly within the if statement block to avoid potential issues with reusing function-scoped variables.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread loopin.go
@hieblmi
hieblmi self-requested a review July 17, 2026 12:10

@hieblmi hieblmi left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Hi @chandachewe10, thank you for the fix!

This LGTM! 💾

@hieblmi
hieblmi requested a review from starius July 17, 2026 14:25
lnd returns ErrInvoiceAlreadySettled from its RPC handler as an
uncoded gRPC error. On the client it is reconstructed as an Unknown
status, so comparing it directly with the Go sentinel never matches.

This made the abandon path log a warning for an expected condition.
The older timeout path had the same comparison and could return the
RPC error instead of finishing normal timeout processing.

Add a shared classifier that accepts the local sentinel and the exact
gRPC status representation, and use it in both cancellation paths.
Add coverage for the classifier and timeout handling.
@starius

starius commented Jul 17, 2026

Copy link
Copy Markdown
Collaborator

I rebased it and fix error classification in another commit.

lnd returns ErrInvoiceAlreadySettled from its RPC handler as an uncoded gRPC error. On the client it is reconstructed as an Unknown status, so comparing it directly with the Go sentinel never matches.

I verified empirically that previous version still produced a warning in this situation, while the fixed one correctly filters out this error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants