use toraniko_math::MathError;
use toraniko_traits::EstimatorError;
#[derive(Debug, thiserror::Error)]
pub enum ModelError {
#[error("estimator error: {0}")]
Estimator(#[from] EstimatorError),
#[error("math error: {0}")]
Math(#[from] MathError),
#[error("data processing error: {0}")]
Polars(#[from] polars::error::PolarsError),
#[error("missing required column: {0}")]
MissingColumn(String),
#[error("invalid configuration: {0}")]
InvalidConfig(String),
#[error("no data for date: {0}")]
NoDataForDate(String),
#[error("dimension mismatch: {0}")]
DimensionMismatch(String),
}
impl ModelError {
#[must_use]
pub const fn is_recoverable(&self) -> bool {
matches!(self, Self::NoDataForDate(_))
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn error_display() {
let err = ModelError::MissingColumn("returns".to_string());
assert!(err.to_string().contains("returns"));
}
#[test]
fn error_is_recoverable() {
let err = ModelError::NoDataForDate("2024-01-01".to_string());
assert!(err.is_recoverable());
let err = ModelError::MissingColumn("test".to_string());
assert!(!err.is_recoverable());
}
}