vtcode_acp_client/
error.rs1use std::fmt;
4
5pub type AcpResult<T> = std::result::Result<T, AcpError>;
7
8#[derive(Debug)]
10pub enum AcpError {
11 AgentNotFound(String),
13
14 NetworkError(String),
16
17 SerializationError(String),
19
20 InvalidRequest(String),
22
23 RemoteError {
25 agent_id: String,
26 message: String,
27 code: Option<i32>,
28 },
29
30 Timeout(String),
32
33 ConfigError(String),
35
36 Internal(String),
38}
39
40impl fmt::Display for AcpError {
41 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
42 match self {
43 AcpError::AgentNotFound(id) => write!(f, "Agent not found: {}", id),
44 AcpError::NetworkError(e) => write!(f, "Network error: {}", e),
45 AcpError::SerializationError(e) => write!(f, "Serialization error: {}", e),
46 AcpError::InvalidRequest(e) => write!(f, "Invalid request: {}", e),
47 AcpError::RemoteError {
48 agent_id,
49 message,
50 code,
51 } => {
52 write!(f, "Remote error from {}: {}", agent_id, message)?;
53 if let Some(code) = code {
54 write!(f, " (code: {})", code)?;
55 }
56 Ok(())
57 }
58 AcpError::Timeout(e) => write!(f, "Timeout: {}", e),
59 AcpError::ConfigError(e) => write!(f, "Configuration error: {}", e),
60 AcpError::Internal(e) => write!(f, "Internal error: {}", e),
61 }
62 }
63}
64
65impl std::error::Error for AcpError {}
66
67impl From<reqwest::Error> for AcpError {
68 fn from(err: reqwest::Error) -> Self {
69 AcpError::NetworkError(err.to_string())
70 }
71}
72
73impl From<serde_json::Error> for AcpError {
74 fn from(err: serde_json::Error) -> Self {
75 AcpError::SerializationError(err.to_string())
76 }
77}
78
79impl From<anyhow::Error> for AcpError {
80 fn from(err: anyhow::Error) -> Self {
81 AcpError::Internal(err.to_string())
82 }
83}