Skip to main content

a2a_ap2/
error.rs

1/// Errors specific to the AP2 (Agent Payments Protocol) extension.
2#[derive(Debug, thiserror::Error)]
3pub enum Ap2Error {
4    /// A required field is missing or empty.
5    #[error("missing required field: {0}")]
6    MissingField(String),
7
8    /// A field value failed validation.
9    #[error("validation error in `{field}`: {message}")]
10    ValidationError { field: String, message: String },
11
12    /// Failed to serialize or deserialize an AP2 type.
13    #[error("serialization error: {0}")]
14    SerializationError(#[from] serde_json::Error),
15
16    /// Attempted to extract an AP2 type from a non-data part.
17    #[error("extraction error: {0}")]
18    ExtractionError(String),
19}
20
21/// Convenience alias for `Result<T, Ap2Error>`.
22pub type Result<T> = std::result::Result<T, Ap2Error>;