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 #[cfg(feature = "local")]
45 #[error("Llama C++ error: {0}")]
46 LlamaCppError(String),
47}
48
49pub type Result<T> = std::result::Result<T, HeliosError>;
51
52#[cfg(test)]
53mod tests {
54 use super::*;
55
56 #[test]
58 fn test_error_types() {
59 let config_error = HeliosError::ConfigError("Config issue".to_string());
60 assert!(matches!(config_error, HeliosError::ConfigError(_)));
61
62 let llm_error = HeliosError::LLMError("LLM issue".to_string());
63 assert!(matches!(llm_error, HeliosError::LLMError(_)));
64
65 let tool_error = HeliosError::ToolError("Tool issue".to_string());
66 assert!(matches!(tool_error, HeliosError::ToolError(_)));
67
68 let agent_error = HeliosError::AgentError("Agent issue".to_string());
69 assert!(matches!(agent_error, HeliosError::AgentError(_)));
70 }
71
72 #[test]
74 fn test_error_display() {
75 let config_error = HeliosError::ConfigError("Config issue".to_string());
76 assert_eq!(
77 format!("{}", config_error),
78 "Configuration error: Config issue"
79 );
80
81 let llm_error = HeliosError::LLMError("LLM issue".to_string());
82 assert_eq!(format!("{}", llm_error), "LLM error: LLM issue");
83
84 let tool_error = HeliosError::ToolError("Tool issue".to_string());
85 assert_eq!(format!("{}", tool_error), "Tool error: Tool issue");
86
87 let agent_error = HeliosError::AgentError("Agent issue".to_string());
88 assert_eq!(format!("{}", agent_error), "Agent error: Agent issue");
89 }
90}