ag_ui/error.rs
1//! Error and result types shared by the whole crate.
2
3use thiserror::Error;
4
5/// Everything that can go wrong while producing or consuming AG-UI values.
6///
7/// The variant list is `#[non_exhaustive]`: new transports and validation rules
8/// are expected to add variants without a breaking release.
9#[derive(Debug, Error)]
10#[non_exhaustive]
11pub enum Error {
12 /// A value could not be converted to or from its JSON wire representation.
13 #[error("JSON conversion failed: {0}")]
14 Json(#[from] serde_json::Error),
15
16 /// The `type` discriminator on an event was not a known AG-UI event type.
17 #[error("unknown event type: {0:?}")]
18 UnknownEventType(String),
19
20 /// Content negotiation produced no media type this build can emit.
21 ///
22 /// Carries the offending `Accept` header value.
23 #[error("no supported media type in Accept header: {0:?}")]
24 UnsupportedMediaType(String),
25
26 /// A payload parsed as JSON but broke a rule the protocol requires and the
27 /// Rust type system cannot express (for example an `interrupt` outcome that
28 /// carries an empty `interrupts` array).
29 #[error("protocol violation: {0}")]
30 Protocol(String),
31
32 /// A transport was requested that this build cannot serve.
33 #[error("unsupported transport: {0}")]
34 UnsupportedTransport(&'static str),
35}
36
37/// Result alias used throughout this crate.
38pub type Result<T, E = Error> = core::result::Result<T, E>;