use core::fmt;
use scivex_core::CoreError;
#[cfg_attr(
feature = "serde-support",
derive(serde::Serialize, serde::Deserialize)
)]
#[derive(Debug, Clone, PartialEq)]
#[non_exhaustive]
pub enum SymError {
InvalidExpr { reason: &'static str },
UndefinedVariable { name: String },
DivisionByZero,
UnsupportedOperation { reason: &'static str },
SolveFailure { reason: &'static str },
CoreError(CoreError),
}
impl fmt::Display for SymError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::InvalidExpr { reason } => write!(f, "invalid expression: {reason}"),
Self::UndefinedVariable { name } => write!(f, "undefined variable: {name}"),
Self::DivisionByZero => write!(f, "division by zero"),
Self::UnsupportedOperation { reason } => {
write!(f, "unsupported operation: {reason}")
}
Self::SolveFailure { reason } => write!(f, "solve failure: {reason}"),
Self::CoreError(e) => write!(f, "core error: {e}"),
}
}
}
impl std::error::Error for SymError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
match self {
Self::CoreError(e) => Some(e),
_ => None,
}
}
}
impl From<CoreError> for SymError {
fn from(e: CoreError) -> Self {
Self::CoreError(e)
}
}
pub type Result<T> = std::result::Result<T, SymError>;