use saorsa_ai::SaorsaAiError;
#[derive(Debug, thiserror::Error)]
pub enum SaorsaAgentError {
#[error("tool error: {0}")]
Tool(String),
#[error("session error: {0}")]
Session(String),
#[error("context error: {0}")]
Context(String),
#[error("provider error: {0}")]
Provider(#[from] SaorsaAiError),
#[error("cancelled: {0}")]
Cancelled(String),
#[error("I/O error: {0}")]
Io(#[from] std::io::Error),
#[error("JSON error: {0}")]
Json(#[from] serde_json::Error),
#[error("internal error: {0}")]
Internal(String),
#[error("extension error: {0}")]
Extension(String),
#[error("could not determine home directory")]
HomeDirectory,
#[error("config I/O error: {0}")]
ConfigIo(std::io::Error),
#[error("config parse error: {0}")]
ConfigParse(serde_json::Error),
#[error("environment variable not found: {name}")]
EnvVarNotFound {
name: String,
},
#[error("command execution failed: {0}")]
CommandFailed(String),
}
pub type Result<T> = std::result::Result<T, SaorsaAgentError>;
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn tool_error_display() {
let err = SaorsaAgentError::Tool("command failed".into());
assert_eq!(err.to_string(), "tool error: command failed");
}
#[test]
fn provider_error_converts() {
let ai_err = SaorsaAiError::Auth("bad key".into());
let err: SaorsaAgentError = ai_err.into();
assert!(matches!(err, SaorsaAgentError::Provider(_)));
}
}