Skip to main content

A2aError

Struct A2aError 

Source
#[non_exhaustive]
pub struct A2aError { pub code: ErrorCode, pub message: String, pub data: Option<Value>, /* private fields */ }
Expand description

The canonical error type for A2A protocol operations.

Carries an ErrorCode, a human-readable message, and an optional data payload (arbitrary JSON) for additional diagnostics.

Fields (Non-exhaustive)§

This struct is marked as non-exhaustive
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.
§code: ErrorCode

Machine-readable error code.

§message: String

Human-readable error message.

§data: Option<Value>

Optional structured error details.

Implementations§

Source§

impl A2aError

Source

pub const fn metric_label(&self) -> &'static str

A bounded, low-cardinality label for this error, for metric attributes.

Delegates to ErrorCode::metric_label. Never the free-form message, which can carry request-derived text — using that as a metric dimension is how a client turns an error into unbounded cardinality.

Source

pub fn new(code: ErrorCode, message: impl Into<String>) -> A2aError

Creates a new A2aError with the given code and message.

Source

pub fn with_data( code: ErrorCode, message: impl Into<String>, data: Value, ) -> A2aError

Creates a new A2aError with the given code, message, and data.

Source

pub fn unauthenticated( message: impl Into<String>, challenge: impl Into<String>, ) -> A2aError

Refuses a request that carries no usable credential: HTTP 401 with challenge as its WWW-Authenticate header (e.g. Bearer realm="a2a"), gRPC UNAUTHENTICATED. Over JSON-RPC the body is an Invalid Request (-32600), as it was before the refusal had a status of its own.

Return it from an a2a-protocol-server ServerInterceptor that authenticates. message reaches the caller, so it should not say why the credential failed.

Source

pub fn permission_denied(message: impl Into<String>) -> A2aError

Refuses an authenticated caller the operation: HTTP 403, gRPC PERMISSION_DENIED, JSON-RPC Invalid Request (-32600). Spec §3.3.2: it must not reveal whether a resource the caller cannot see exists.

Source

pub fn insufficient_scope<S>( message: impl Into<String>, scopes: impl IntoIterator<Item = S>, ) -> A2aError
where S: AsRef<str>,

permission_denied for a credential that lacks a scope the operation needs, naming the scopes. Spec §3.3.2: servers SHOULD indicate what permission or scope is missing. Every binding carries the RFC 6750 §3 challenge it builds, Bearer error="insufficient_scope", scope="tasks:write": a WWW-Authenticate header beside the HTTP 403, www-authenticate metadata beside gRPC PERMISSION_DENIED.

Name only scopes the caller may know it needs, such as those the card’s securityRequirements declare: the challenge reaches whoever sent the request.

Source

pub fn rate_limited( message: impl Into<String>, retry_after: Duration, ) -> A2aError

Refuses a request because its caller exceeded a rate limit, and may try again after retry_after. Spec §13.4: an agent SHOULD return an appropriate error when a rate limit is exceeded, and §3.3.2 SHOULD tell temporary failures from permanent ones. The code stays InternalError (-32603), the code §3.3.2 gives as the JSON-RPC example for “rate limit exceeded”; what marks it temporary is the binding’s status (HTTP 429 with Retry-After, gRPC RESOURCE_EXHAUSTED) and a google.rpc.RetryInfo detail on every binding.

retry_after is rounded up to whole seconds, at least one (retrying a moment early would only be refused again), and saturates at u32::MAX seconds.

Source

pub fn unavailable(message: impl Into<String>) -> A2aError

Fails a request because something it needs cannot answer for now, such as a database with no free connection or a file another writer holds, so the same request may succeed if retried. Spec §3.3.2: servers SHOULD tell temporary failures from permanent ones, and give HTTP 503 and gRPC UNAVAILABLE as the codes for one. The code stays InternalError (-32603), the JSON-RPC example §3.3.2 gives; what marks it temporary is the binding’s status: HTTP 503 with the AIP-193 status UNAVAILABLE, gRPC UNAVAILABLE.

use a2a_protocol_types::error::{A2aError, ErrorCode};

let busy = A2aError::unavailable("database busy");
assert!(busy.is_unavailable());
assert_eq!(busy.code, ErrorCode::InternalError);
assert!(!A2aError::internal("corrupt row").is_unavailable());
Source

pub fn with_retry_after(self, retry_after: Duration) -> A2aError

Asks the caller to try again after retry_after: a google.rpc.RetryInfo detail on every binding, and Retry-After on HTTP. On an unavailable error it says the request was refused before any work began, so even a send may be repeated; a server going away refuses new work this way. Rounded as rate_limited rounds.

use a2a_protocol_types::error::A2aError;
use std::time::Duration;

let leaving = A2aError::unavailable("shutting down").with_retry_after(Duration::from_millis(1));
assert!(leaving.is_unavailable());
assert_eq!(leaving.retry_after(), Some(Duration::from_secs(1)));
Source

pub const fn is_unavailable(&self) -> bool

Whether this error is a temporary failure built with unavailable. Never read from the wire: a client sees the binding’s status instead.

Source

pub const fn retry_after(&self) -> Option<Duration>

How long a caller refused by rate_limited should wait before retrying, or the delay a received error’s RetryInfo detail asked for (see with_retry_info_from_details); None for any other error.

Source

pub fn with_retry_info_from_details(self) -> A2aError

Records the delay a received error’s google.rpc.RetryInfo detail asks for, so that retry_after answers for an error that came over the wire as it does for one built with rate_limited.

Reads data as the typed-details array error_info_data writes (a single detail object is accepted too) and takes the first RetryInfo whose retryDelay is a ProtoJSON duration: whole seconds with an optional fraction and an s suffix, as in "12s" or "1.5s". Rounded up to whole seconds, at least one, as rate_limited rounds. Anything else, or a delay already recorded, leaves the error as it was.

Source

pub const fn auth_rejection(&self) -> Option<&AuthRejection>

The credential refusal this error carries, if it is one. Set only by unauthenticated and permission_denied, and never read from the wire.

Source

pub fn task_not_found(task_id: impl Display) -> A2aError

Creates a “Task not found” error for the given task ID string.

Source

pub fn task_not_cancelable(task_id: impl Display) -> A2aError

Creates a “Task not cancelable” error.

Source

pub fn internal(msg: impl Into<String>) -> A2aError

Creates an internal error with the provided message.

Source

pub fn invalid_params(msg: impl Into<String>) -> A2aError

Creates an “Invalid params” error.

Source

pub fn is_stream_lagged(&self) -> bool

Returns true when this error is the recoverable consumer-lag signal a server emits on a streaming subscription.

It says events were dropped for this consumer, not that the task failed: the task goes on, and GetTask shows its state. This SDK’s servers send it only when the task’s event log cannot replay what the consumer missed (spec §3.5.2). On the JSON-RPC, HTTP+JSON, WebSocket and gRPC bindings it is the stream’s last frame; a SLIMRPC server sends the error’s text without the marker, so this returns false there, though a SLIMRPC multicast member that falls behind on the client side is handed this signal. To resynchronize, subscribe again: the new stream begins with a fresh Task snapshot, and over SSE a Last-Event-ID resumes it after the last position seen, while the log still holds it.

It is detected by the STREAM_LAGGED_MARKER key in A2aError::data rather than by code or message, because the code is a generic InternalError and the message is human-facing prose.

use a2a_protocol_types::error::{A2aError, ErrorCode};

let lag = A2aError::stream_lagged(7);
assert!(lag.is_stream_lagged());
assert_eq!(lag.dropped_event_count(), Some(7));

// An ordinary internal error is not a lag signal.
assert!(!A2aError::internal("boom").is_stream_lagged());
assert!(!A2aError::new(ErrorCode::TaskNotFound, "gone").is_stream_lagged());
Source

pub fn dropped_event_count(&self) -> Option<u64>

Returns how many events were dropped, when this is a consumer-lag signal (see A2aError::is_stream_lagged); None otherwise.

Source

pub fn stream_lagged(dropped: u64) -> A2aError

Builds the consumer-lag signal carrying dropped.

Servers emit this; consumers identify it with A2aError::is_stream_lagged. It lives here rather than in the server crate so that both sides — and any third-party client — agree on one definition of the marker.

Source

pub fn unsupported_operation(msg: impl Into<String>) -> A2aError

Creates an “Unsupported operation” error.

Source

pub fn parse_error(msg: impl Into<String>) -> A2aError

Creates a “Parse error” error.

Source

pub fn invalid_agent_response(msg: impl Into<String>) -> A2aError

Creates an “Invalid agent response” error.

Source

pub fn extended_card_not_configured(msg: impl Into<String>) -> A2aError

Creates an “Extended agent card not configured” error.

Source

pub fn push_not_supported(msg: impl Into<String>) -> A2aError

Creates a “Push notification not supported” error.

Source

pub fn content_type_not_supported(msg: impl Into<String>) -> A2aError

Creates a “Content type not supported” error.

Source

pub fn extension_support_required(msg: impl Into<String>) -> A2aError

Creates an “Extension support required” error.

Source

pub fn version_not_supported(msg: impl Into<String>) -> A2aError

Creates a “Version not supported” error.

Source

pub fn error_info_data(&self, metadata: Option<Value>) -> Value

Builds the typed error-details array the bindings send: error.data on JSON-RPC, error.details on HTTP+JSON. Value::Null when there is nothing to send.

Per Section 9.5, 10.6, and 11.6, A2A-specific errors MUST include an ErrorInfo entry with @type, reason, domain, and optional metadata. A rate_limited error also carries a google.rpc.RetryInfo entry, the well-known type (§3.3.2) that says the failure is temporary and when to retry.

Trait Implementations§

Source§

impl Clone for A2aError

Source§

fn clone(&self) -> A2aError

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for A2aError

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for A2aError

Source§

fn deserialize<__D>( __deserializer: __D, ) -> Result<A2aError, <__D as Deserializer<'de>>::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Display for A2aError

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl Error for A2aError

1.30.0 · Source§

fn source(&self) -> Option<&(dyn Error + 'static)>

Returns the lower-level source of this error, if any. Read more
1.0.0 · Source§

fn description(&self) -> &str

👎Deprecated since 1.42.0:

use the Display impl or to_string()

1.0.0 · Source§

fn cause(&self) -> Option<&dyn Error>

👎Deprecated since 1.33.0:

replaced by Error::source, which can support downcasting

Replaced by Error::source.
Source§

fn provide<'a>(&'a self, request: &mut Request<'a>)

🔬This is a nightly-only experimental API. (error_generic_member_access)
Provides type-based access to context intended for error reports. Read more
Source§

impl From<A2aError> for ClientError

Source§

fn from(e: A2aError) -> ClientError

Converts to this type from the input type.
Source§

impl From<A2aError> for ServerError

Source§

fn from(e: A2aError) -> ServerError

Converts to this type from the input type.
Source§

impl From<ClaimLost> for A2aError

Source§

fn from(lost: ClaimLost) -> A2aError

Converts to this type from the input type.
Source§

impl From<ClientError> for A2aError

Lets an executor that delegates to another agent use ? on client calls.

An AgentExecutor returns A2aResult, so without this every delegated call had to be flattened to a string, losing whether it was worth retrying. The conversion keeps what the server needs to classify the failed task (see a2a_protocol_types::failure::error_class):

ClientErrorA2aError codeFailure class
Protocol(e)e.code, with e.message and e.data unchangedfrom the code
Protocol(e) naming a retry delay (a downstream rate limit)as above, with its delayTransient
anything is_retryable — timeouts, connection failures, 429/502/503/504, TooManyPendingRequestsInternalErrorTransient
Serialization or InvalidAgentResponse (the peer sent something unreadable, or missing a REQUIRED field)InvalidAgentResponseInternal
everything else (bad endpoint, binding mismatch, other statuses, auth required)InternalErrorInternal

“Transient exactly when the client would retry” is deliberate: the client’s retry policy and the caller’s are then the same judgement. The class rides in data under the failure key; the server never sends data to its caller as-is, so it does not leak. The message is downstream A2A call failed: followed by this error’s text and its source chain, so nothing the client knew is lost.

use a2a_protocol_client::ClientBuilder;
use a2a_protocol_types::error::A2aResult;
use a2a_protocol_types::params::TaskQueryParams;

// The shape of an `AgentExecutor::execute` body that delegates.
async fn delegate(downstream: &str, task_id: &str) -> A2aResult<String> {
    let client = ClientBuilder::new(downstream).build()?;
    let task = client
        .get_task(TaskQueryParams::new(task_id))
        .await?; // a timeout here fails the task as `Transient`
    Ok(task.text().unwrap_or_default().to_owned())
}
Source§

fn from(e: ClientError) -> A2aError

Converts to this type from the input type.
Source§

impl From<TerminalStateConflict> for A2aError

Source§

fn from(conflict: TerminalStateConflict) -> A2aError

Converts to this type from the input type.
Source§

impl Serialize for A2aError

Source§

fn serialize<__S>( &self, __serializer: __S, ) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<'a, T, E> AsTaggedExplicit<'a, E> for T
where T: 'a,

§

fn explicit(self, class: Class, tag: u32) -> TaggedParser<'a, Explicit, Self, E>

§

impl<'a, T, E> AsTaggedImplicit<'a, E> for T
where T: 'a,

§

fn implicit( self, class: Class, constructed: bool, tag: u32, ) -> TaggedParser<'a, Implicit, Self, E>

Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> FromRef<T> for T
where T: Clone,

§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
§

impl<T> FutureExt for T

§

fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ

Attaches the provided Context to this type, returning a WithContext wrapper. Read more
§

fn with_current_context(self) -> WithContext<Self> ⓘ

Attaches the current Context to this type, returning a WithContext wrapper. Read more
§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
§

impl<T> IntoRequest<T> for T

§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
§

impl<L> LayerExt<L> for L

§

fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>
where L: Layer<S>,

Applies the layer to a service and wraps it in [Layered].
§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more