From 8f53c37fbd429dcc4b6706989fde297d7b5c4c48 Mon Sep 17 00:00:00 2001 From: konstin Date: Mon, 27 Jan 2025 16:26:47 +0100 Subject: [PATCH] Remove failure branch with panic When the user's implementation breaks the contract about choose version, we now panic. This contract is trivial to enforce (`vs.contains(v)`), so an error path does not make sense. Fixes #239 --- src/error.rs | 5 ----- src/solver.rs | 7 ++++--- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/src/error.rs b/src/error.rs index ce193766..d784ed0a 100644 --- a/src/error.rs +++ b/src/error.rs @@ -42,10 +42,6 @@ pub enum PubGrubError { /// returned an error in the method [should_cancel](DependencyProvider::should_cancel). #[error("We should cancel")] ErrorInShouldCancel(#[source] DP::Err), - - /// Something unexpected happened. - #[error("{0}")] - Failure(String), } impl From> for PubGrubError { @@ -78,7 +74,6 @@ where Self::ErrorInShouldCancel(arg0) => { f.debug_tuple("ErrorInShouldCancel").field(arg0).finish() } - Self::Failure(arg0) => f.debug_tuple("Failure").field(arg0).finish(), } } } diff --git a/src/solver.rs b/src/solver.rs index f30e6cba..eb09371b 100644 --- a/src/solver.rs +++ b/src/solver.rs @@ -188,9 +188,10 @@ pub fn resolve( }; if !term_intersection.contains(&v) { - return Err(PubGrubError::Failure( - "choose_package_version picked an incompatible version".into(), - )); + panic!( + "`choose_version` picked an incompatible version for package {}, {} is not in {}", + state.package_store[next], v, term_intersection + ); } let is_new_dependency = added_dependencies