1use thiserror::Error;
7
8#[derive(Error, Debug)]
10pub enum HeliosError {
11 #[error("Configuration error: {0}")]
13 ConfigError(String),
14
15 #[error("LLM error: {0}")]
17 LLMError(String),
18
19 #[error("Tool error: {0}")]
21 ToolError(String),
22
23 #[error("Agent error: {0}")]
25 AgentError(String),
26
27 #[error("Network error: {0}")]
29 NetworkError(#[from] reqwest::Error),
30
31 #[error("Serialization error: {0}")]
33 SerializationError(#[from] serde_json::Error),
34
35 #[error("IO error: {0}")]
37 IoError(#[from] std::io::Error),
38
39 #[error("TOML parsing error: {0}")]
41 TomlError(#[from] toml::de::Error),
42
43 #[error("Llama C++ error: {0}")]
45 LlamaCppError(String),
46}
47
48pub type Result<T> = std::result::Result<T, HeliosError>;
50
51#[cfg(test)]
52mod tests {
53 use super::*;
54
55 #[test]
57 fn test_error_types() {
58 let config_error = HeliosError::ConfigError("Config issue".to_string());
59 assert!(matches!(config_error, HeliosError::ConfigError(_)));
60
61 let llm_error = HeliosError::LLMError("LLM issue".to_string());
62 assert!(matches!(llm_error, HeliosError::LLMError(_)));
63
64 let tool_error = HeliosError::ToolError("Tool issue".to_string());
65 assert!(matches!(tool_error, HeliosError::ToolError(_)));
66
67 let agent_error = HeliosError::AgentError("Agent issue".to_string());
68 assert!(matches!(agent_error, HeliosError::AgentError(_)));
69 }
70
71 #[test]
73 fn test_error_display() {
74 let config_error = HeliosError::ConfigError("Config issue".to_string());
75 assert_eq!(
76 format!("{}", config_error),
77 "Configuration error: Config issue"
78 );
79
80 let llm_error = HeliosError::LLMError("LLM issue".to_string());
81 assert_eq!(format!("{}", llm_error), "LLM error: LLM issue");
82
83 let tool_error = HeliosError::ToolError("Tool issue".to_string());
84 assert_eq!(format!("{}", tool_error), "Tool error: Tool issue");
85
86 let agent_error = HeliosError::AgentError("Agent issue".to_string());
87 assert_eq!(format!("{}", agent_error), "Agent error: Agent issue");
88 }
89}