Skip to main content

vtcode_acp_client/
error.rs

1//! Error types for ACP operations
2
3/// Result type for ACP operations
4pub type AcpResult<T> = Result<T, AcpError>;
5
6/// Errors that can occur during ACP communication
7#[derive(Debug, thiserror::Error)]
8pub enum AcpError {
9    /// Agent not found or unavailable
10    #[error("Agent not found: {0}")]
11    AgentNotFound(String),
12
13    /// Network/HTTP error
14    #[error("Network error: {0}")]
15    NetworkError(String),
16
17    /// Message serialization/deserialization error
18    #[error("Serialization error: {0}")]
19    SerializationError(String),
20
21    /// Invalid request format
22    #[error("Invalid request: {0}")]
23    InvalidRequest(String),
24
25    /// Remote agent returned an error
26    #[error("Remote error from {agent_id}: {message}{code}", code = if let Some(code) = code { format!(" (code: {})", code) } else { String::new() })]
27    RemoteError {
28        agent_id: String,
29        message: String,
30        code: Option<i32>,
31    },
32
33    /// Request timeout
34    #[error("Timeout: {0}")]
35    Timeout(String),
36
37    /// Configuration error
38    #[error("Configuration error: {0}")]
39    ConfigError(String),
40
41    /// Generic internal error
42    #[error("Internal error: {0}")]
43    Internal(String),
44}
45
46impl From<reqwest::Error> for AcpError {
47    fn from(err: reqwest::Error) -> Self {
48        AcpError::NetworkError(err.to_string())
49    }
50}
51
52impl From<serde_json::Error> for AcpError {
53    fn from(err: serde_json::Error) -> Self {
54        AcpError::SerializationError(err.to_string())
55    }
56}
57
58impl From<anyhow::Error> for AcpError {
59    fn from(err: anyhow::Error) -> Self {
60        AcpError::Internal(err.to_string())
61    }
62}