Skip to main content

AdkError

Struct AdkError 

Source
pub struct AdkError {
    pub component: ErrorComponent,
    pub category: ErrorCategory,
    pub code: &'static str,
    pub message: String,
    pub retry: RetryHint,
    pub details: Box<ErrorDetails>,
    /* private fields */
}
Expand description

Unified structured error type for all ADK-Rust operations.

§Migration from enum syntax

Before (0.4.x enum):

// Construction
Err(AdkError::Model("rate limited".into()))
// Matching
matches!(err, AdkError::Model(_))

After (0.5.x struct):

use adk_core::{AdkError, ErrorComponent, ErrorCategory};

// Structured construction
let err = AdkError::new(
    ErrorComponent::Model,
    ErrorCategory::RateLimited,
    "model.openai.rate_limited",
    "rate limited",
);
assert!(err.is_retryable()); // RateLimited → should_retry = true

// Backward-compat construction (for migration)
let err = AdkError::model("rate limited");
assert!(err.is_model());

Fields§

§component: ErrorComponent

The subsystem that produced the error.

§category: ErrorCategory

The kind of failure.

§code: &'static str

Machine-readable error code (e.g., “model.openai.rate_limited”).

§message: String

Human-readable error message.

§retry: RetryHint

Retry guidance for this error.

§details: Box<ErrorDetails>

Additional structured metadata.

Implementations§

Source§

impl AdkError

Source

pub fn new( component: ErrorComponent, category: ErrorCategory, code: &'static str, message: impl Into<String>, ) -> Self

Creates a new AdkError with the given component, category, code, and message.

Source

pub fn with_source(self, source: impl Error + Send + Sync + 'static) -> Self

Attaches a source error for error chaining.

Source

pub fn with_retry(self, retry: RetryHint) -> Self

Overrides the default retry hint.

Source

pub fn with_details(self, details: ErrorDetails) -> Self

Replaces the error details.

Source

pub fn with_upstream_status(self, status_code: u16) -> Self

Sets the upstream HTTP status code in details.

Source

pub fn with_request_id(self, request_id: impl Into<String>) -> Self

Sets the upstream request ID in details.

Source

pub fn with_provider(self, provider: impl Into<String>) -> Self

Sets the provider name in details.

Source§

impl AdkError

Source

pub fn not_found( component: ErrorComponent, code: &'static str, message: impl Into<String>, ) -> Self

Creates a NotFound error for the given component.

Source

pub fn rate_limited( component: ErrorComponent, code: &'static str, message: impl Into<String>, ) -> Self

Creates a RateLimited error for the given component.

Source

pub fn unauthorized( component: ErrorComponent, code: &'static str, message: impl Into<String>, ) -> Self

Creates an Unauthorized error for the given component.

Source

pub fn internal( component: ErrorComponent, code: &'static str, message: impl Into<String>, ) -> Self

Creates an Internal error for the given component.

Source

pub fn timeout( component: ErrorComponent, code: &'static str, message: impl Into<String>, ) -> Self

Creates a Timeout error for the given component.

Source

pub fn unavailable( component: ErrorComponent, code: &'static str, message: impl Into<String>, ) -> Self

Creates an Unavailable error for the given component.

Source§

impl AdkError

Source

pub fn agent(message: impl Into<String>) -> Self

Legacy convenience constructor for agent errors.

Source

pub fn model(message: impl Into<String>) -> Self

Legacy convenience constructor for model errors.

Source

pub fn tool(message: impl Into<String>) -> Self

Legacy convenience constructor for tool errors.

Source

pub fn session(message: impl Into<String>) -> Self

Legacy convenience constructor for session errors.

Source

pub fn memory(message: impl Into<String>) -> Self

Legacy convenience constructor for memory errors.

Source

pub fn config(message: impl Into<String>) -> Self

Legacy convenience constructor for configuration errors.

Source

pub fn artifact(message: impl Into<String>) -> Self

Legacy convenience constructor for artifact errors.

Source§

impl AdkError

Source

pub fn is_agent(&self) -> bool

Returns true if this error originated in agent logic.

Source

pub fn is_model(&self) -> bool

Returns true if this error originated in model interaction.

Source

pub fn is_tool(&self) -> bool

Returns true if this error originated in tool execution.

Source

pub fn is_session(&self) -> bool

Returns true if this error originated in session management.

Source

pub fn is_artifact(&self) -> bool

Returns true if this error originated in artifact storage.

Source

pub fn is_memory(&self) -> bool

Returns true if this error originated in memory operations.

Source

pub fn is_config(&self) -> bool

Returns true if this is a configuration error (legacy code path).

Source§

impl AdkError

Source

pub fn is_retryable(&self) -> bool

Returns true if this error should be retried.

Source

pub fn is_not_found(&self) -> bool

Returns true if this is a not-found error.

Source

pub fn is_unauthorized(&self) -> bool

Returns true if this is an unauthorized error.

Source

pub fn is_rate_limited(&self) -> bool

Returns true if this is a rate-limited error.

Source

pub fn is_timeout(&self) -> bool

Returns true if this is a timeout error.

Source§

impl AdkError

Source

pub fn http_status_code(&self) -> u16

Maps the error category to an appropriate HTTP status code.

Source§

impl AdkError

Source

pub fn to_problem_json(&self) -> Value

Serializes the error as a JSON Problem Details object.

Trait Implementations§

Source§

impl Debug for AdkError

Source§

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

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

impl Display for AdkError

Source§

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

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

impl Error for AdkError

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

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<IdentityError> for AdkError

Source§

fn from(err: IdentityError) -> Self

Converts to this type from the input type.
Source§

impl From<SharedStateError> for AdkError

Source§

fn from(err: SharedStateError) -> Self

Converts to this type from the input type.

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
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
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

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

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

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> 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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.
Source§

impl<T> WithSubscriber for T

Source§

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
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

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