Skip to content

Commit 2c3ec47

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 95cee08 commit 2c3ec47

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
@@ -2034,4 +2034,19 @@ pk(03f28773c2d975288bc7d1d205c3748651b075fbc6610e58cddeeddf8f19405aa8))";
20342034
Desc::from_str(&format!("tr({},pk({}))", x_only_key, uncomp_key)).unwrap_err();
20352035
Desc::from_str(&format!("tr({},pk({}))", x_only_key, x_only_key)).unwrap();
20362036
}
2037+
2038+
#[test]
2039+
fn regression_806() {
2040+
let secp = secp256k1::Secp256k1::signing_only();
2041+
type Desc = Descriptor<DescriptorPublicKey>;
2042+
// OK
2043+
Desc::from_str("pkh(111111111111111111111111111111110000008375319363688624584A111111)")
2044+
.unwrap_err();
2045+
// ERR: crashes in translate_pk
2046+
Desc::parse_descriptor(
2047+
&secp,
2048+
"pkh(111111111111111111111111111111110000008375319363688624584A111111)",
2049+
)
2050+
.unwrap_err();
2051+
}
20372052
}

src/lib.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -391,10 +391,11 @@ impl<E> TranslateErr<E> {
391391
///
392392
/// This function will panic if the Error is OutError.
393393
pub fn expect_translator_err(self, msg: &str) -> E {
394-
if let Self::TranslatorErr(v) = self {
395-
v
396-
} else {
397-
panic!("{}", msg)
394+
match self {
395+
Self::TranslatorErr(v) => v,
396+
Self::OuterError(ref e) => {
397+
panic!("Unexpected Miniscript error when translating: {}\nMessage: {}", e, msg)
398+
}
398399
}
399400
}
400401
}

0 commit comments

Comments
 (0)