use pyo3::PyErr;
use pyo3::create_exception;
use pyo3::exceptions::PyException;
use crate::error::CspError;
create_exception!(
csp_solver,
UnsatisfiableError,
PyException,
"No solution exists under the given constraints."
);
create_exception!(
csp_solver,
BudgetExceededError,
PyException,
"The search aborted after exhausting its node budget; results (if any) are best-so-far."
);
create_exception!(
csp_solver,
InvalidInputError,
PyException,
"A caller-supplied argument was structurally invalid."
);
create_exception!(
csp_solver,
CspTimeoutError,
PyException,
"The search exceeded its wall-clock deadline. Distinct from BudgetExceededError \
(node-count budget) — reserved for the cooperative wall-clock cancellation path."
);
impl CspError {
fn to_pyerr(&self) -> PyErr {
let msg = self.to_string();
match self {
CspError::Unsatisfiable => UnsatisfiableError::new_err(msg),
CspError::BudgetExceeded => BudgetExceededError::new_err(msg),
CspError::InvalidInput { .. } => InvalidInputError::new_err(msg),
CspError::Timeout => CspTimeoutError::new_err(msg),
}
}
}
impl From<CspError> for PyErr {
fn from(e: CspError) -> PyErr {
e.to_pyerr()
}
}