Skip to content

Commit 6bff186

Browse files
committed
add regression test for #806
When parsing a descriptor with `Descriptor::parse_descriptor`, we first parse as a string and then parse the keys. We fail to consider parsing errors in the keys, resulting in a panic. Also, clean up the panic message so it's clearer what's going on.
1 parent 05d3cc2 commit 6bff186

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

src/descriptor/mod.rs

+15
Original file line numberDiff line numberDiff line change
@@ -2168,4 +2168,19 @@ pk(03f28773c2d975288bc7d1d205c3748651b075fbc6610e58cddeeddf8f19405aa8))";
21682168
Desc::from_str(&format!("tr({},pk({}))", x_only_key, uncomp_key)).unwrap_err();
21692169
Desc::from_str(&format!("tr({},pk({}))", x_only_key, x_only_key)).unwrap();
21702170
}
2171+
2172+
#[test]
2173+
fn regression_806() {
2174+
let secp = secp256k1::Secp256k1::signing_only();
2175+
type Desc = Descriptor<DescriptorPublicKey>;
2176+
// OK
2177+
Desc::from_str("pkh(111111111111111111111111111111110000008375319363688624584A111111)")
2178+
.unwrap_err();
2179+
// ERR: crashes in translate_pk
2180+
Desc::parse_descriptor(
2181+
&secp,
2182+
"pkh(111111111111111111111111111111110000008375319363688624584A111111)",
2183+
)
2184+
.unwrap_err();
2185+
}
21712186
}

src/lib.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -356,10 +356,11 @@ impl<E> TranslateErr<E> {
356356
///
357357
/// This function will panic if the Error is OutError.
358358
pub fn expect_translator_err(self, msg: &str) -> E {
359-
if let Self::TranslatorErr(v) = self {
360-
v
361-
} else {
362-
panic!("{}", msg)
359+
match self {
360+
Self::TranslatorErr(v) => v,
361+
Self::OuterError(ref e) => {
362+
panic!("Unexpected Miniscript error when translating: {}\nMessage: {}", e, msg)
363+
}
363364
}
364365
}
365366
}

0 commit comments

Comments
 (0)