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.
Sourcepub fn is_conflict(&self) -> bool
pub fn is_conflict(&self) -> bool
Returns true if the write lost a race or used a stale version.
Sourcepub fn redacted(&self) -> String
pub fn redacted(&self) -> String
Describes the error by its component, category, and code, without its message.
A message can carry credentials, internal hosts, or upstream response bodies, so this form is what an agent shows a model for a failure whose message stays local. The code is a compile-time constant, never caller data.
§Example
use adk_core::{AdkError, ErrorCategory, ErrorComponent};
let err = AdkError::new(
ErrorComponent::Tool,
ErrorCategory::Unavailable,
"tool.orders_db.unavailable",
"connect postgres://admin:secret@db.internal/prod failed",
);
assert_eq!(err.redacted(), "tool.unavailable (tool.orders_db.unavailable)");Sourcepub fn diagnostics(&self) -> ErrorDiagnostics<'_>
pub fn diagnostics(&self) -> ErrorDiagnostics<'_>
Describes the error for a log line or span field without its message.
The form is redacted followed by the upstream status, provider,
provider error code, and request ID when they are set. A provider error code or
request ID is shown only when it is a short identifier, since both come from the
upstream response.
§Example
use adk_core::{AdkError, ErrorCategory, ErrorComponent};
let err = AdkError::new(
ErrorComponent::Model,
ErrorCategory::InvalidInput,
"model.gemini.bad_request",
"Invalid value at 'contents[0]' (acct-7731)",
)
.with_upstream_status(400)
.with_provider("gemini");
assert_eq!(
err.diagnostics().to_string(),
"model.invalid_input (model.gemini.bad_request); status 400; provider gemini"
);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()
Source§impl From<BudgetExceeded> for AdkError
impl From<BudgetExceeded> for AdkError
Source§fn from(exceeded: BudgetExceeded) -> Self
fn from(exceeded: BudgetExceeded) -> Self
Source§impl From<IdentityError> for AdkError
An identifier that fails validation becomes session.invalid_identifier
(ErrorCategory::InvalidInput, HTTP 400) in the
Session component, the error every session backend
and the runner return for an invalid app name, user ID, or session ID.
impl From<IdentityError> for AdkError
An identifier that fails validation becomes session.invalid_identifier
(ErrorCategory::InvalidInput, HTTP 400) in the
Session component, the error every session backend
and the runner return for an invalid app name, user ID, or session ID.
§Example
use adk_core::identity::UserId;
use adk_core::{AdkError, ErrorCategory};
let error: AdkError = UserId::try_from("").unwrap_err().into();
assert_eq!(error.code, "session.invalid_identifier");
assert_eq!(error.category, ErrorCategory::InvalidInput);