aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/mozart-core/src/dependency_resolver/error.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/mozart-core/src/dependency_resolver/error.rs')
-rw-r--r--crates/mozart-core/src/dependency_resolver/error.rs50
1 files changed, 50 insertions, 0 deletions
diff --git a/crates/mozart-core/src/dependency_resolver/error.rs b/crates/mozart-core/src/dependency_resolver/error.rs
new file mode 100644
index 0000000..e4b9841
--- /dev/null
+++ b/crates/mozart-core/src/dependency_resolver/error.rs
@@ -0,0 +1,50 @@
+use std::fmt;
+
+/// A bug in the solver itself (should never happen in normal operation).
+/// Equivalent to Composer's SolverBugException.
+#[derive(Debug, Clone)]
+pub struct SolverBugError {
+ pub message: String,
+}
+
+impl fmt::Display for SolverBugError {
+ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+ write!(f, "Solver bug: {}", self.message)
+ }
+}
+
+impl std::error::Error for SolverBugError {}
+
+/// Errors produced by the SAT solver.
+#[derive(Debug)]
+pub enum SolverError {
+ /// Internal solver bug (should never happen).
+ Bug(SolverBugError),
+ /// The dependency set is unsolvable. Contains problem descriptions.
+ Unsolvable(Vec<String>),
+}
+
+impl fmt::Display for SolverError {
+ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+ match self {
+ SolverError::Bug(e) => write!(f, "{e}"),
+ SolverError::Unsolvable(problems) => {
+ for (i, problem) in problems.iter().enumerate() {
+ if i > 0 {
+ writeln!(f)?;
+ }
+ write!(f, " Problem {}: {problem}", i + 1)?;
+ }
+ Ok(())
+ }
+ }
+ }
+}
+
+impl std::error::Error for SolverError {}
+
+impl From<SolverBugError> for SolverError {
+ fn from(e: SolverBugError) -> Self {
+ SolverError::Bug(e)
+ }
+}