Skip to main content

a2a_ao/
error.rs

1//! A2A Error types.
2
3use thiserror::Error;
4
5/// Errors that can occur when using the A2A protocol.
6#[derive(Debug, Error)]
7pub enum A2AError {
8    /// Failed to discover the agent card at the well-known endpoint.
9    #[error("agent discovery failed: {0}")]
10    DiscoveryFailed(String),
11
12    /// The agent card is invalid or missing required fields.
13    #[error("invalid agent card: {0}")]
14    InvalidAgentCard(String),
15
16    /// HTTP transport error.
17    #[error("transport error: {0}")]
18    Transport(#[from] reqwest::Error),
19
20    /// JSON serialization/deserialization error.
21    #[error("serialization error: {0}")]
22    Serialization(#[from] serde_json::Error),
23
24    /// The remote agent returned a JSON-RPC error.
25    #[error("JSON-RPC error {code}: {message}")]
26    JsonRpc {
27        code: i64,
28        message: String,
29        data: Option<serde_json::Value>,
30    },
31
32    /// The task was not found.
33    #[error("task not found: {0}")]
34    TaskNotFound(String),
35
36    /// The task was rejected by the remote agent.
37    #[error("task rejected: {0}")]
38    TaskRejected(String),
39
40    /// The task failed during execution.
41    #[error("task failed: {0}")]
42    TaskFailed(String),
43
44    /// The task requires authentication.
45    #[error("authentication required: {0}")]
46    AuthRequired(String),
47
48    /// Streaming error (SSE).
49    #[error("streaming error: {0}")]
50    StreamingError(String),
51
52    /// Push notification configuration error.
53    #[error("push notification error: {0}")]
54    PushNotificationError(String),
55
56    /// URL parsing error.
57    #[error("invalid URL: {0}")]
58    InvalidUrl(#[from] url::ParseError),
59
60    /// Timeout waiting for task completion.
61    #[error("timeout after {0:?}")]
62    Timeout(std::time::Duration),
63
64    /// The operation is not supported by the remote agent.
65    #[error("unsupported operation: {0}")]
66    Unsupported(String),
67}
68
69/// A2A Result type alias.
70pub type A2AResult<T> = Result<T, A2AError>;