1use thiserror::Error;
2
3#[derive(Error, Debug)]
4pub enum HeliosError {
5 #[error("Configuration error: {0}")]
6 ConfigError(String),
7
8 #[error("LLM error: {0}")]
9 LLMError(String),
10
11 #[error("Tool error: {0}")]
12 ToolError(String),
13
14 #[error("Agent error: {0}")]
15 AgentError(String),
16
17 #[error("Network error: {0}")]
18 NetworkError(#[from] reqwest::Error),
19
20 #[error("Serialization error: {0}")]
21 SerializationError(#[from] serde_json::Error),
22
23 #[error("IO error: {0}")]
24 IoError(#[from] std::io::Error),
25
26 #[error("TOML parsing error: {0}")]
27 TomlError(#[from] toml::de::Error),
28
29 #[error("Llama C++ error: {0}")]
30 LlamaCppError(String),
31}
32
33pub type Result<T> = std::result::Result<T, HeliosError>;
34
35#[cfg(test)]
36mod tests {
37 use super::*;
38
39 #[test]
40 fn test_error_types() {
41 let config_error = HeliosError::ConfigError("Config issue".to_string());
42 assert!(matches!(config_error, HeliosError::ConfigError(_)));
43
44 let llm_error = HeliosError::LLMError("LLM issue".to_string());
45 assert!(matches!(llm_error, HeliosError::LLMError(_)));
46
47 let tool_error = HeliosError::ToolError("Tool issue".to_string());
48 assert!(matches!(tool_error, HeliosError::ToolError(_)));
49
50 let agent_error = HeliosError::AgentError("Agent issue".to_string());
51 assert!(matches!(agent_error, HeliosError::AgentError(_)));
52 }
53
54 #[test]
55 fn test_error_display() {
56 let config_error = HeliosError::ConfigError("Config issue".to_string());
57 assert_eq!(
58 format!("{}", config_error),
59 "Configuration error: Config issue"
60 );
61
62 let llm_error = HeliosError::LLMError("LLM issue".to_string());
63 assert_eq!(format!("{}", llm_error), "LLM error: LLM issue");
64
65 let tool_error = HeliosError::ToolError("Tool issue".to_string());
66 assert_eq!(format!("{}", tool_error), "Tool error: Tool issue");
67
68 let agent_error = HeliosError::AgentError("Agent issue".to_string());
69 assert_eq!(format!("{}", agent_error), "Agent error: Agent issue");
70 }
71}