pub enum Error {
Show 25 variants
MissingApiKey(String),
Http(Error),
Cancelled,
Timeout(String),
Json(Error),
StreamProtocol(String),
ProviderStream(String),
ResponseLimit {
resource: &'static str,
limit: usize,
},
Api {
provider: &'static str,
status: u16,
body: String,
retry_after: Option<Duration>,
retry_source: Option<RetrySource>,
request_id: Option<String>,
},
MissingModel(&'static str),
InvalidRequest(String),
Unsupported(String),
ToolNotFound(String),
ToolFailed {
tool: String,
message: String,
},
MaxSteps(usize),
Normalize(String),
InvalidRetryPolicy(String),
HeaderValue(InvalidHeaderValue),
HeaderName(InvalidHeaderName),
ProtectedHeader(String),
NonAsciiHeaderValue {
name: String,
},
ReservedExtraBodyField {
protocol: &'static str,
field: String,
},
ReservedExtraQuery {
protocol: &'static str,
parameter: String,
},
InvalidEndpoint(String),
InvalidProfile(String),
}Expand description
The error type returned by this crate’s public API.
Its Display output is safe to log: the Api
variant never embeds the raw provider response body, and the Debug
output redacts it. Use Error::kind for stable classification and
Error::raw_body when you explicitly need the provider body.
Variants§
MissingApiKey(String)
No API key was configured for the provider.
Http(Error)
The HTTP request to the provider failed at the transport level.
Cancelled
The request was cancelled before it completed.
Timeout(String)
The request exceeded its configured timeout.
Json(Error)
A response body was not valid JSON.
StreamProtocol(String)
The provider’s stream emitted a malformed or unexpected event.
ProviderStream(String)
The provider reported an error inside a stream.
ResponseLimit
A decoded response exceeded its configured resource budget.
Fields
Api
Fields
body: StringRaw response body. Excluded from log-safe output; see
Error::raw_body.
retry_source: Option<RetrySource>Which header produced retry_after.
MissingModel(&'static str)
A provider was configured without a model.
InvalidRequest(String)
The request could not be built as specified.
Unsupported(String)
The selected provider does not support the requested operation.
ToolNotFound(String)
The model requested a tool that was never registered.
ToolFailed
A registered tool returned an error while executing.
Fields
MaxSteps(usize)
The agent loop exceeded its configured step budget.
Normalize(String)
A request could not be normalized for the target protocol.
InvalidRetryPolicy(String)
A retry policy configuration was invalid.
HeaderValue(InvalidHeaderValue)
An HTTP header value was invalid.
HeaderName(InvalidHeaderName)
An HTTP header name was invalid.
ProtectedHeader(String)
An attempt was made to override a header the SDK manages itself.
NonAsciiHeaderValue
A header value contained non-ASCII characters.
ReservedExtraBodyField
An extra body field collided with a canonical SDK field.
Fields
ReservedExtraQuery
An extra query parameter collided with an endpoint-reserved name.
Fields
InvalidEndpoint(String)
A base URL or endpoint could not be parsed.
InvalidProfile(String)
A provider profile configuration was invalid.
Implementations§
Source§impl Error
impl Error
Sourcepub fn status(&self) -> Option<u16>
pub fn status(&self) -> Option<u16>
Provider HTTP status, when this error came from an API response.
Sourcepub fn provider(&self) -> Option<&str>
pub fn provider(&self) -> Option<&str>
Provider name, when this error came from an API response.
Sourcepub fn request_id(&self) -> Option<&str>
pub fn request_id(&self) -> Option<&str>
Provider request id, when the response exposed one.
Sourcepub fn raw_body(&self) -> Option<&str>
pub fn raw_body(&self) -> Option<&str>
Return the raw provider error body.
This is intentionally opt-in because provider errors can echo request
content, account data, or other sensitive values. Prefer
Self::body_bytes, Self::status, and Self::request_id for
logs and metrics.
Sourcepub fn body_bytes(&self) -> Option<usize>
pub fn body_bytes(&self) -> Option<usize>
Decoded provider error-body size in bytes, without exposing the body.
Sourcepub fn provider_error(&self) -> Option<ProviderErrorInfo>
pub fn provider_error(&self) -> Option<ProviderErrorInfo>
Parse a safe, provider-neutral summary of a structured API error.
Provider messages are never included. Codes, types, and status tokens are only returned when they are short, ASCII machine tokens.
Sourcepub fn retry_after(&self) -> Option<Duration>
pub fn retry_after(&self) -> Option<Duration>
Return the parsed Retry-After duration, if this error came from an
HTTP response that supplied one.
Sourcepub fn retry_source(&self) -> Option<RetrySource>
pub fn retry_source(&self) -> Option<RetrySource>
Return which response header produced the retry delay.
Sourcepub fn is_retryable(&self) -> bool
pub fn is_retryable(&self) -> bool
Whether this error is normally safe to retry.
This is a conservative classification. Callers should still avoid retrying non-idempotent operations unless they have an idempotency key.
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()