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: ErrorComponentThe subsystem that produced the error.
category: ErrorCategoryThe kind of failure.
code: &'static strMachine-readable error code (e.g., “model.openai.rate_limited”).
message: StringHuman-readable error message.
retry: RetryHintRetry guidance for this error.
details: Box<ErrorDetails>Additional structured metadata.
Implementations§
Source§impl AdkError
impl AdkError
Sourcepub fn new(
component: ErrorComponent,
category: ErrorCategory,
code: &'static str,
message: impl Into<String>,
) -> Self
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.
Sourcepub fn with_source(self, source: impl Error + Send + Sync + 'static) -> Self
pub fn with_source(self, source: impl Error + Send + Sync + 'static) -> Self
Attaches a source error for error chaining.
Sourcepub fn with_retry(self, retry: RetryHint) -> Self
pub fn with_retry(self, retry: RetryHint) -> Self
Overrides the default retry hint.
Sourcepub fn with_details(self, details: ErrorDetails) -> Self
pub fn with_details(self, details: ErrorDetails) -> Self
Replaces the error details.
Sourcepub fn with_upstream_status(self, status_code: u16) -> Self
pub fn with_upstream_status(self, status_code: u16) -> Self
Sets the upstream HTTP status code in details.
Sourcepub fn with_request_id(self, request_id: impl Into<String>) -> Self
pub fn with_request_id(self, request_id: impl Into<String>) -> Self
Sets the upstream request ID in details.
Sourcepub fn with_provider(self, provider: impl Into<String>) -> Self
pub fn with_provider(self, provider: impl Into<String>) -> Self
Sets the provider name in details.
Source§impl AdkError
impl AdkError
Sourcepub fn not_found(
component: ErrorComponent,
code: &'static str,
message: impl Into<String>,
) -> Self
pub fn not_found( component: ErrorComponent, code: &'static str, message: impl Into<String>, ) -> Self
Creates a NotFound error for the given component.
Sourcepub fn rate_limited(
component: ErrorComponent,
code: &'static str,
message: impl Into<String>,
) -> Self
pub fn rate_limited( component: ErrorComponent, code: &'static str, message: impl Into<String>, ) -> Self
Creates a RateLimited error for the given component.
Creates an Unauthorized error for the given component.
Sourcepub fn internal(
component: ErrorComponent,
code: &'static str,
message: impl Into<String>,
) -> Self
pub fn internal( component: ErrorComponent, code: &'static str, message: impl Into<String>, ) -> Self
Creates an Internal error for the given component.
Sourcepub fn timeout(
component: ErrorComponent,
code: &'static str,
message: impl Into<String>,
) -> Self
pub fn timeout( component: ErrorComponent, code: &'static str, message: impl Into<String>, ) -> Self
Creates a Timeout error for the given component.
Creates an Unavailable error for the given component.
Source§impl AdkError
impl AdkError
Sourcepub fn agent(message: impl Into<String>) -> Self
pub fn agent(message: impl Into<String>) -> Self
Legacy convenience constructor for agent errors.
Sourcepub fn model(message: impl Into<String>) -> Self
pub fn model(message: impl Into<String>) -> Self
Legacy convenience constructor for model errors.
Sourcepub fn tool(message: impl Into<String>) -> Self
pub fn tool(message: impl Into<String>) -> Self
Legacy convenience constructor for tool errors.
Sourcepub fn session(message: impl Into<String>) -> Self
pub fn session(message: impl Into<String>) -> Self
Legacy convenience constructor for session errors.
Sourcepub fn memory(message: impl Into<String>) -> Self
pub fn memory(message: impl Into<String>) -> Self
Legacy convenience constructor for memory errors.
Source§impl AdkError
impl AdkError
Sourcepub fn is_session(&self) -> bool
pub fn is_session(&self) -> bool
Returns true if this error originated in session management.
Sourcepub fn is_artifact(&self) -> bool
pub fn is_artifact(&self) -> bool
Returns true if this error originated in artifact storage.
Source§impl AdkError
impl AdkError
Sourcepub fn is_retryable(&self) -> bool
pub fn is_retryable(&self) -> bool
Returns true if this error should be retried.
Sourcepub fn is_not_found(&self) -> bool
pub fn is_not_found(&self) -> bool
Returns true if this is a not-found error.
Returns true if this is an unauthorized error.
Sourcepub fn is_rate_limited(&self) -> bool
pub fn is_rate_limited(&self) -> bool
Returns true if this is a rate-limited error.
Sourcepub fn is_timeout(&self) -> bool
pub fn is_timeout(&self) -> bool
Returns true if this is a timeout error.
Trait Implementations§
Source§impl Error for AdkError
impl Error for AdkError
Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
use the Display impl or to_string()