#[non_exhaustive]pub enum Error {
#[non_exhaustive] Api {
status: StatusCode,
request_id: Option<String>,
kind: ApiErrorKind,
message: String,
retry_after: Option<Duration>,
},
Network(Error),
Decode(Error),
Stream(StreamError),
InvalidConfig(String),
Io(Error),
MaxIterationsExceeded {
max: u32,
},
CostBudgetExceeded {
budget_usd: f64,
spent_usd: f64,
},
Cancelled,
ToolApprovalStopped {
tool_name: String,
reason: String,
},
Signing(Box<dyn Error + Send + Sync + 'static>),
}Expand description
Errors returned by this crate.
Variants tied to optional features (async/sync for Error::Network,
streaming for Error::Stream) are conditionally compiled out when
those features are disabled. Use Error::is_retryable to decide
whether to retry; the crate::retry layer uses the same logic.
Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
#[non_exhaustive]Api
The Anthropic API returned an error response.
Fields
This variant is marked as non-exhaustive
status: StatusCodeHTTP status code returned by the API.
request_id: Option<String>request-id header from the response, if present. Critical for
support tickets.
kind: ApiErrorKindDecoded error category from the response body.
Network(Error)
async or sync only.Underlying HTTP transport failed (timeout, connection refused, DNS, etc.).
Decode(Error)
Response body could not be parsed as JSON.
Stream(StreamError)
streaming only.Streaming error (parse, connection lost, server-emitted error event).
InvalidConfig(String)
The crate::ClientBuilder was misconfigured.
Io(Error)
Local I/O failed (e.g. reading a file to upload).
MaxIterationsExceeded
The agent loop runner reached its iteration limit without the model
producing a non-tool_use stop reason.
CostBudgetExceeded
The agent loop’s configured cost budget was exceeded after a turn.
spent_usd reflects the cumulative cost recorded on the conversation
at the moment the budget check fired.
Cancelled
A cancellation token signaled abort between iterations.
ToolApprovalStopped
A ToolApprover returned ApprovalDecision::Stop, ending the loop
before the named tool could run.
Fields
Signing(Box<dyn Error + Send + Sync + 'static>)
async only.A RequestSigner returned an error
while signing an outbound request.
Implementations§
Source§impl Error
impl Error
Sourcepub fn is_retryable(&self) -> bool
pub fn is_retryable(&self) -> bool
Returns true if the error represents a transient failure worth retrying.
Single source of truth used by both crate::retry::RetryPolicy and
callers handling retries themselves.
Sourcepub fn request_id(&self) -> Option<&str>
pub fn request_id(&self) -> Option<&str>
request-id header from the API response, if this is an Error::Api.
Sourcepub fn retry_after(&self) -> Option<Duration>
pub fn retry_after(&self) -> Option<Duration>
Retry-After value from the API response, if any.
Sourcepub fn status(&self) -> Option<StatusCode>
pub fn status(&self) -> Option<StatusCode>
HTTP status code, if this is an Error::Api.
Trait Implementations§
Source§impl Error for Error
impl Error for Error
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<StreamError> for Error
impl From<StreamError> for Error
Source§fn from(source: StreamError) -> Self
fn from(source: StreamError) -> Self
Auto Trait Implementations§
impl Freeze for Error
impl !RefUnwindSafe for Error
impl Send for Error
impl Sync for Error
impl Unpin for Error
impl UnsafeUnpin for Error
impl !UnwindSafe for Error
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
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> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<T> ToStringFallible for Twhere
T: Display,
impl<T> ToStringFallible for Twhere
T: Display,
Source§fn try_to_string(&self) -> Result<String, TryReserveError>
fn try_to_string(&self) -> Result<String, TryReserveError>
ToString::to_string, but without panic on OOM.