use std::fmt;
#[derive(Debug, Clone, PartialEq)]
pub enum InsightError {
CsvParse { line: usize, message: String },
JsonParse { message: String },
MissingValues { column: String, count: usize },
InsufficientData { min_required: usize, actual: usize },
InvalidParameter { name: String, message: String },
DegenerateData { reason: String },
ComputationFailed { operation: String, detail: String },
ColumnNotFound { name: String },
DimensionMismatch { expected: usize, actual: usize },
Io(String),
}
impl fmt::Display for InsightError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::CsvParse { line, message } => {
write!(f, "CSV parse error at line {line}: {message}")
}
Self::JsonParse { message } => {
write!(f, "JSON parse error: {message}")
}
Self::MissingValues { column, count } => {
write!(f, "column '{column}' has {count} missing values")
}
Self::InsufficientData {
min_required,
actual,
} => {
write!(f, "need at least {min_required} rows, got {actual}")
}
Self::InvalidParameter { name, message } => {
write!(f, "invalid parameter '{name}': {message}")
}
Self::DegenerateData { reason } => {
write!(f, "degenerate data: {reason}")
}
Self::ComputationFailed { operation, detail } => {
write!(f, "{operation} failed: {detail}")
}
Self::ColumnNotFound { name } => {
write!(f, "column '{name}' not found")
}
Self::DimensionMismatch { expected, actual } => {
write!(f, "expected {expected} elements, got {actual}")
}
Self::Io(msg) => write!(f, "I/O error: {msg}"),
}
}
}
impl std::error::Error for InsightError {}
impl From<std::io::Error> for InsightError {
fn from(e: std::io::Error) -> Self {
Self::Io(e.to_string())
}
}