use thiserror::Error;
pub type Result<T> = std::result::Result<T, Error>;
#[derive(Debug, Error)]
pub enum Error {
#[error("IO error: {0}")]
IoError(#[from] std::io::Error),
#[error("IO error: {0}")]
Io(String),
#[error("Serialization error: {0}")]
SerializationError(#[from] serde_json::Error),
#[error("Invalid score calculation: {0}")]
InvalidScore(String),
#[error("Validation error: {0}")]
Validation(String),
#[error("Template error: {0}")]
TemplateError(String),
#[error("Gateway {gate} failed: {reason}")]
GatewayFailed {
gate: String,
reason: String,
},
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_error_display() {
let err = Error::GatewayFailed {
gate: "G1".to_string(),
reason: "Model failed to load".to_string(),
};
assert!(err.to_string().contains("G1"));
assert!(err.to_string().contains("Model failed to load"));
}
#[test]
fn test_invalid_score() {
let err = Error::InvalidScore("Negative weight".to_string());
assert!(err.to_string().contains("Negative weight"));
}
#[test]
fn test_io_error() {
let err = Error::Io("File not found".to_string());
assert!(err.to_string().contains("File not found"));
}
#[test]
fn test_validation_error() {
let err = Error::Validation("Invalid CSV field".to_string());
assert!(err.to_string().contains("Invalid CSV field"));
}
#[test]
fn test_template_error() {
let err = Error::TemplateError("Missing variable".to_string());
assert!(err.to_string().contains("Missing variable"));
}
}