use std::io;
use thiserror::Error;
#[derive(Error, Debug)]
pub enum AgentError {
#[error("I/O error: {0}")]
Io(#[from] io::Error),
#[error("Transport error: {0}")]
Transport(String),
#[error("Invalid argument: {0}")]
InvalidArgument(String),
#[error("Serialization error: {0}")]
Serialization(#[from] serde_json::Error),
#[error("Parse error: {0}")]
ParseInt(#[from] std::num::ParseIntError),
#[error("Configuration error: {0}")]
Config(String),
#[error("Command execution error: {0}")]
Command(String),
#[error("Operation timed out after {0}s")]
Timeout(u64),
#[error("HTTP error: {0}")]
Http(#[from] reqwest::Error),
#[error("Internal error: {0}")]
Internal(String),
}
pub type Result<T> = std::result::Result<T, AgentError>;
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_error_display() {
let err = AgentError::InvalidArgument("test error".to_string());
assert_eq!(err.to_string(), "Invalid argument: test error");
}
#[test]
fn test_io_error_conversion() {
let io_err = io::Error::new(io::ErrorKind::NotFound, "file not found");
let agent_err = AgentError::from(io_err);
assert!(matches!(agent_err, AgentError::Io(_)));
}
#[test]
fn test_serialization_error_conversion() {
let serde_err = serde_json::from_str::<serde_json::Value>("invalid json").unwrap_err();
let agent_err = AgentError::from(serde_err);
assert!(matches!(agent_err, AgentError::Serialization(_)));
}
}