use std::fmt;
use crate::Span;
#[derive(Debug, Clone, PartialEq, Eq, thiserror::Error)]
pub enum EvalError {
InitialStoreUnsatisfiable,
NonLinear { constraint: String },
CyclicAttributeTerm { term: String },
}
impl fmt::Display for EvalError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
EvalError::InitialStoreUnsatisfiable => {
f.write_str("the program's constraint facts are unsatisfiable (no models)")
}
EvalError::NonLinear { constraint } => write!(
f,
"non-linear constraint `{constraint}` is still undetermined; claimr does not approximate (evaluator stage 3 supports linear constraints only)"
),
EvalError::CyclicAttributeTerm { term } => {
write!(f, "cyclic attribute term `{term}` in numeric position is not supported")
}
}
}
}
impl EvalError {
pub fn span(&self) -> Option<Span> {
match self {
EvalError::InitialStoreUnsatisfiable
| EvalError::NonLinear { .. }
| EvalError::CyclicAttributeTerm { .. } => None,
}
}
}