Simplify ChannelUnavailable APIError handling with let-else#4736
Conversation
Refactor the nested match statement used during error construction into a more idiomatic let-else construct (stabilised in Rust 1.65). The previous implementation required verbose, nested matching to navigate around borrow checker limitations. By leveraging let-else alongside chaining unwrap_err on handle_error Result, we achieve the same teardown logic (dropping state locks) and error mapping with significantly less boilerplate and nesting.
|
I've assigned @valentinewallace as a reviewer! |
|
The code matches my prior review exactly and remains clean. No issues found. The PR is correct and behavior-preserving:
|
Hamza1610
left a comment
There was a problem hiding this comment.
Test Results: PASS
All tests passed successfully! However, there are a couple of minor warnings to address:
** Redundant Import in channelmanager.rs**
warning: the item Hasher is imported redundantly
--> lightning/src/ln/channelmanager.rs:19832:35
|
177 | use core::hash::{Hash, Hasher};
| ------ the item Hasher is already imported here
19832 | use core::hash::{BuildHasher, Hasher};
| ^^^^^^
Issue: Hasher is imported twice in the same file. Fix: Remove the redundant Hasher from line 19832, keeping only BuildHasher: use core::hash::{BuildHasher};
Overall: Tests pass |Only minor cleanup needed
|
When I was testing I noticed some ignored test. These might be deprecated test that are not in used anymore. I'm suggesting to create a new PR for this. @casey what do you think about that. |
Hi @Hamza1610 I appreciate the review! However, the unused import warning is actually unrelated to the changes in this PR. It looks like it was introduced to Given the ongoing Forgejo migration (#4734), it's probably best to avoid scope creep here to keep this PR clean and prevent untracked changes. |
|
Yes, you are right, PR has be be clean. Thanks for highlighting this. |
valentinewallace
left a comment
There was a problem hiding this comment.
Looks good! Second commit is redundant with #4727
@valentinewallace thanks for the review, I've dropped the commit, and addressed the duplicate import warning. |
|
Looks like the second commit is still there? |
My Bad, it's not anymore; Successfully dropped the commit via rebase. |
1c1a4ad
into
lightningdevkit:main
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #4736 +/- ##
==========================================
+ Coverage 84.54% 86.90% +2.35%
==========================================
Files 137 161 +24
Lines 77617 111680 +34063
Branches 77617 111680 +34063
==========================================
+ Hits 65625 97051 +31426
- Misses 9949 12121 +2172
- Partials 2043 2508 +465
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
e9e3060 Fixes the TODO for the error handling.
3d6a879 Fixes the triggered
manual_str_repeatlint.