1use thiserror::Error;
4
5pub type Result<T> = std::result::Result<T, Error>;
7
8#[derive(Debug, Error)]
10pub enum Error {
11 #[error("IO error: {0}")]
13 IoError(#[from] std::io::Error),
14
15 #[error("IO error: {0}")]
17 Io(String),
18
19 #[error("Serialization error: {0}")]
21 SerializationError(#[from] serde_json::Error),
22
23 #[error("Invalid score calculation: {0}")]
25 InvalidScore(String),
26
27 #[error("Validation error: {0}")]
29 Validation(String),
30
31 #[error("Template error: {0}")]
33 TemplateError(String),
34
35 #[error("Gateway {gate} failed: {reason}")]
37 GatewayFailed {
38 gate: String,
40 reason: String,
42 },
43}
44
45#[cfg(test)]
46mod tests {
47 use super::*;
48
49 #[test]
50 fn test_error_display() {
51 let err = Error::GatewayFailed {
52 gate: "G1".to_string(),
53 reason: "Model failed to load".to_string(),
54 };
55 assert!(err.to_string().contains("G1"));
56 assert!(err.to_string().contains("Model failed to load"));
57 }
58
59 #[test]
60 fn test_invalid_score() {
61 let err = Error::InvalidScore("Negative weight".to_string());
62 assert!(err.to_string().contains("Negative weight"));
63 }
64
65 #[test]
66 fn test_io_error() {
67 let err = Error::Io("File not found".to_string());
68 assert!(err.to_string().contains("File not found"));
69 }
70
71 #[test]
72 fn test_validation_error() {
73 let err = Error::Validation("Invalid CSV field".to_string());
74 assert!(err.to_string().contains("Invalid CSV field"));
75 }
76
77 #[test]
78 fn test_template_error() {
79 let err = Error::TemplateError("Missing variable".to_string());
80 assert!(err.to_string().contains("Missing variable"));
81 }
82}