Skip to main content

a2a/
error.rs

1//! Errors that may cross an a2a boundary.
2
3use thiserror::Error;
4
5/// Errors produced by wire-schema validation.
6#[derive(Debug, Error)]
7pub enum A2aError {
8    /// A lifecycle transition was rejected by the FSM.
9    #[error("invalid state transition: {from:?} -> {to:?}")]
10    InvalidTransition {
11        /// State we attempted to move away from.
12        from: crate::task::TaskState,
13        /// State we attempted to move to.
14        to: crate::task::TaskState,
15    },
16
17    /// A message-state transition was rejected.
18    #[error("invalid message-state transition: {from:?} -> {to:?}")]
19    InvalidMessageTransition {
20        /// State we attempted to move away from.
21        from: crate::message::MsgState,
22        /// State we attempted to move to.
23        to: crate::message::MsgState,
24    },
25
26    /// A message could not be claimed (already held).
27    #[error("claim conflict: {0}")]
28    ClaimConflict(String),
29
30    /// Serialization / deserialization failed.
31    #[error("serde error: {0}")]
32    Serde(String),
33}
34
35impl From<serde_json::Error> for A2aError {
36    fn from(e: serde_json::Error) -> Self {
37        A2aError::Serde(e.to_string())
38    }
39}
40
41/// Convenience result alias.
42pub type A2aResult<T> = std::result::Result<T, A2aError>;