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>,
) -> AdkError
pub fn new( component: ErrorComponent, category: ErrorCategory, code: &'static str, message: impl Into<String>, ) -> AdkError
Creates a new AdkError with the given component, category, code, and message.
Sourcepub fn with_source(self, source: impl Error + Send + Sync + 'static) -> AdkError
pub fn with_source(self, source: impl Error + Send + Sync + 'static) -> AdkError
Attaches a source error for error chaining.
Sourcepub fn with_retry(self, retry: RetryHint) -> AdkError
pub fn with_retry(self, retry: RetryHint) -> AdkError
Overrides the default retry hint.
Sourcepub fn with_details(self, details: ErrorDetails) -> AdkError
pub fn with_details(self, details: ErrorDetails) -> AdkError
Replaces the error details.
Sourcepub fn with_upstream_status(self, status_code: u16) -> AdkError
pub fn with_upstream_status(self, status_code: u16) -> AdkError
Sets the upstream HTTP status code in details.
Sourcepub fn with_request_id(self, request_id: impl Into<String>) -> AdkError
pub fn with_request_id(self, request_id: impl Into<String>) -> AdkError
Sets the upstream request ID in details.
Sourcepub fn with_provider(self, provider: impl Into<String>) -> AdkError
pub fn with_provider(self, provider: impl Into<String>) -> AdkError
Sets the provider name in details.
Source§impl AdkError
impl AdkError
Sourcepub fn not_found(
component: ErrorComponent,
code: &'static str,
message: impl Into<String>,
) -> AdkError
pub fn not_found( component: ErrorComponent, code: &'static str, message: impl Into<String>, ) -> AdkError
Creates a NotFound error for the given component.
Sourcepub fn rate_limited(
component: ErrorComponent,
code: &'static str,
message: impl Into<String>,
) -> AdkError
pub fn rate_limited( component: ErrorComponent, code: &'static str, message: impl Into<String>, ) -> AdkError
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>,
) -> AdkError
pub fn internal( component: ErrorComponent, code: &'static str, message: impl Into<String>, ) -> AdkError
Creates an Internal error for the given component.
Sourcepub fn timeout(
component: ErrorComponent,
code: &'static str,
message: impl Into<String>,
) -> AdkError
pub fn timeout( component: ErrorComponent, code: &'static str, message: impl Into<String>, ) -> AdkError
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>) -> AdkError
pub fn agent(message: impl Into<String>) -> AdkError
Legacy convenience constructor for agent errors.
Sourcepub fn model(message: impl Into<String>) -> AdkError
pub fn model(message: impl Into<String>) -> AdkError
Legacy convenience constructor for model errors.
Sourcepub fn tool(message: impl Into<String>) -> AdkError
pub fn tool(message: impl Into<String>) -> AdkError
Legacy convenience constructor for tool errors.
Sourcepub fn session(message: impl Into<String>) -> AdkError
pub fn session(message: impl Into<String>) -> AdkError
Legacy convenience constructor for session errors.
Sourcepub fn memory(message: impl Into<String>) -> AdkError
pub fn memory(message: impl Into<String>) -> AdkError
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) -> AdkError
fn from(exceeded: BudgetExceeded) -> AdkError
Source§impl From<ExecutionError> for AdkError
impl From<ExecutionError> for AdkError
Source§fn from(err: ExecutionError) -> AdkError
fn from(err: ExecutionError) -> AdkError
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);Source§fn from(err: IdentityError) -> AdkError
fn from(err: IdentityError) -> AdkError
Source§impl From<PrincipalError> for AdkError
impl From<PrincipalError> for AdkError
Source§fn from(error: PrincipalError) -> AdkError
fn from(error: PrincipalError) -> AdkError
Source§impl From<SandboxError> for AdkError
impl From<SandboxError> for AdkError
Source§fn from(err: SandboxError) -> AdkError
fn from(err: SandboxError) -> AdkError
Source§fn from(err: SharedStateError) -> AdkError
fn from(err: SharedStateError) -> AdkError
Source§impl From<SpendError> for AdkError
impl From<SpendError> for AdkError
Source§fn from(error: SpendError) -> AdkError
fn from(error: SpendError) -> AdkError
Auto Trait Implementations§
impl !RefUnwindSafe for AdkError
impl !UnwindSafe for AdkError
impl Forget for AdkError
impl Freeze for AdkErrorwhere
&'static str: Freeze,
*const u8 is !null: Freeze,
PhantomData<u8>: Freeze,
*const ErrorDetails is !null: Freeze,
PhantomData<ErrorDetails>: Freeze,
*const dyn Error + Sync + Send is !null: Freeze,
PhantomData<dyn Error + Sync + Send>: Freeze,
impl Move for AdkError
impl Send for AdkError
impl Sync for AdkError
impl Unpin for AdkError
impl UnsafeUnpin for AdkErrorwhere
&'static str: UnsafeUnpin,
*const u8 is !null: UnsafeUnpin,
PhantomData<u8>: UnsafeUnpin,
*const ErrorDetails is !null: UnsafeUnpin,
PhantomData<ErrorDetails>: UnsafeUnpin,
*const dyn Error + Sync + Send is !null: UnsafeUnpin,
PhantomData<dyn Error + Sync + Send>: UnsafeUnpin,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
impl<T> ErasedDestructor for Twhere
T: 'static,
Source§impl<T> FmtForward for T
impl<T> FmtForward for T
Source§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self to use its Binary implementation when Debug-formatted.Source§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self to use its Display implementation when
Debug-formatted.Source§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self to use its LowerExp implementation when
Debug-formatted.Source§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self to use its LowerHex implementation when
Debug-formatted.Source§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self to use its Octal implementation when Debug-formatted.Source§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self to use its Pointer implementation when
Debug-formatted.Source§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self to use its UpperExp implementation when
Debug-formatted.Source§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self to use its UpperHex implementation when
Debug-formatted.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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 moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::RequestSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Requestimpl<T> MaybeSendSync for T
Source§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
Source§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
Source§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
Source§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
Source§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self, then passes self.as_ref() into the pipe function.Source§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self, then passes self.as_mut() into the pipe
function.Source§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self, then passes self.deref() into the pipe function.Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<T> Tap for T
impl<T> Tap for T
Source§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B> of a value. Read moreSource§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B> of a value. Read moreSource§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R> view of a value. Read moreSource§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R> view of a value. Read moreSource§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap() only in debug builds, and is erased in release builds.Source§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut() only in debug builds, and is erased in release
builds.Source§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref() only in debug builds, and is erased in release
builds.Source§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut() only in debug builds, and is erased in release
builds.Source§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref() only in debug builds, and is erased in release
builds.Source§impl<T> ToCompactString for Twhere
T: Display,
impl<T> ToCompactString for Twhere
T: Display,
Source§fn try_to_compact_string(&self) -> Result<CompactString, ToCompactStringError>
fn try_to_compact_string(&self) -> Result<CompactString, ToCompactStringError>
ToCompactString::to_compact_string() Read moreSource§fn to_compact_string(&self) -> CompactString
fn to_compact_string(&self) -> CompactString
CompactString. Read more