1use saorsa_ai::SaorsaAiError;
4
5#[derive(Debug, thiserror::Error)]
7pub enum SaorsaAgentError {
8 #[error("tool error: {0}")]
10 Tool(String),
11
12 #[error("session error: {0}")]
14 Session(String),
15
16 #[error("context error: {0}")]
18 Context(String),
19
20 #[error("provider error: {0}")]
22 Provider(#[from] SaorsaAiError),
23
24 #[error("cancelled: {0}")]
26 Cancelled(String),
27
28 #[error("I/O error: {0}")]
30 Io(#[from] std::io::Error),
31
32 #[error("JSON error: {0}")]
34 Json(#[from] serde_json::Error),
35
36 #[error("internal error: {0}")]
38 Internal(String),
39
40 #[error("extension error: {0}")]
42 Extension(String),
43
44 #[error("could not determine home directory")]
46 HomeDirectory,
47
48 #[error("config I/O error: {0}")]
50 ConfigIo(std::io::Error),
51
52 #[error("config parse error: {0}")]
54 ConfigParse(serde_json::Error),
55
56 #[error("environment variable not found: {name}")]
58 EnvVarNotFound {
59 name: String,
61 },
62
63 #[error("command execution failed: {0}")]
65 CommandFailed(String),
66}
67
68pub type Result<T> = std::result::Result<T, SaorsaAgentError>;
70
71#[cfg(test)]
72mod tests {
73 use super::*;
74
75 #[test]
76 fn tool_error_display() {
77 let err = SaorsaAgentError::Tool("command failed".into());
78 assert_eq!(err.to_string(), "tool error: command failed");
79 }
80
81 #[test]
82 fn provider_error_converts() {
83 let ai_err = SaorsaAiError::Auth("bad key".into());
84 let err: SaorsaAgentError = ai_err.into();
85 assert!(matches!(err, SaorsaAgentError::Provider(_)));
86 }
87}