fix(descriptor): propagate threshold errors instead of panicking - #533
fix(descriptor): propagate threshold errors instead of panicking#533busayo-OD wants to merge 1 commit into
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #533 +/- ##
==========================================
+ Coverage 81.84% 81.92% +0.08%
==========================================
Files 25 25
Lines 6487 6541 +54
Branches 296 302 +6
==========================================
+ Hits 5309 5359 +50
+ Misses 1078 1075 -3
- Partials 100 107 +7
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:
|
There was a problem hiding this comment.
I pulled this branch and ran all three tests locally. The fix correctly stops the fragment! macro from panicking on invalid thresholds and returns Err(DescriptorError::Miniscript(miniscript::Error::Threshold(_))) instead, routing errors through the existing Result channel rather than bypassing it with .expect().
d031217 to
7e1782a
Compare
hash-ty
left a comment
There was a problem hiding this comment.
This looks great. The implementation could be cleaned up slightly by implementing From<ThresholdError> for DescriptorError, wrapping it in the Miniscript variant, and propagating the result of Threshold::new directly using ?.
thresh_vec, multi_vec, and multi_a_vec panicked via .expect() on Threshold::new whenever k/n were invalid at runtime, even though the surrounding macros return Result<_, DescriptorError>. Adds From<miniscript::ThresholdError> for DescriptorError, reusing the existing miniscript::Error::Threshold case, and propagates it directly via ? in all three fragments. keys::make_multi's closure now returns Result<Terminal<DescriptorPublicKey, Ctx>, DescriptorError> instead of Terminal<...> directly.
7e1782a to
c53b9d9
Compare
Thanks for the review. Done! |
Fixes #532
Description
thresh_vec,multi_vec, andmulti_a_vecused.expect(...)onThreshold::new, causing invalid runtime-supplied thresholds to panic instead of returning through the macros' usualResult<_, DescriptorError>.For
thresh_vec, the error is propagated through its existingResultchain. Formulti_vecandmulti_a_vec,keys::make_multinow accepts a closure returningResult<Terminal<...>, DescriptorError>, matching the existingmake_sortedmultipattern and removing the need for.expect(...).Notes to the reviewers
miniscriptalready providesError::Thresholdfor invalid thresholds, andDescriptorErroralready wrapsminiscript::Error, so I reused the existing error path rather than introducing a new variant.Added
From<miniscript::ThresholdError> for DescriptorErrorand simplified all three fragments to propagate the error via?directly.Changelog notice
Checklists
All Submissions
just pbefore pushingBugfixes