diff --git a/src/descriptors/analysis.rs b/src/descriptors/analysis.rs index e840002d..dbedc421 100644 --- a/src/descriptors/analysis.rs +++ b/src/descriptors/analysis.rs @@ -25,6 +25,7 @@ pub enum LianaPolicyError { /// The spending policy is not a valid Miniscript policy: it may for instance be malleable, or /// overflow some limit. InvalidPolicy(compiler::CompilerError), + PolicyAnalysis(miniscript::Error), } impl std::fmt::Display for LianaPolicyError { @@ -54,6 +55,7 @@ impl std::fmt::Display for LianaPolicyError { "Descriptor is not compatible with a Liana spending policy." ), Self::InvalidPolicy(e) => write!(f, "Invalid Miniscript policy: {}", e), + Self::PolicyAnalysis(e) => write!(f, "Analyzing the policy of the miniscript: {}", e), } } } @@ -452,7 +454,7 @@ impl LianaPolicy { }; let policy = ms .lift() - .expect("Lifting can't fail on a Miniscript") + .map_err(LianaPolicyError::PolicyAnalysis)? .normalized(); // The policy must always be "1 of N spending paths" with at least an always-available diff --git a/src/descriptors/mod.rs b/src/descriptors/mod.rs index cc886457..2d249b54 100644 --- a/src/descriptors/mod.rs +++ b/src/descriptors/mod.rs @@ -1405,5 +1405,10 @@ mod tests { )); } + #[test] + fn unliftable_miniscript() { + LianaDescriptor::from_str("wsh(0)").unwrap_err(); + } + // TODO: test error conditions of deserialization. }