pub enum ProviderError {
Show 14 variants
Http(Arc<Error>),
Json(Arc<Error>),
Url(ParseError),
Request(SharedError),
Response(String),
Provider(String),
ProviderResponse(ProviderResponseError),
InvalidAuthentication(ProviderResponseError),
CacheExpired {
name: String,
response: ProviderResponseError,
},
MismatchedDimensions {
provider: String,
requested: usize,
returned: usize,
},
MalformedToolInput(MalformedToolInput),
Relayed(Box<ErrorReport>),
Truncated,
DuplicateCallId(CallId),
}Expand description
A failed provider operation: completion, embedding, reranking, transcription, image or audio generation, verification, model listing, or context caching.
The variant is the classification, and each variant maps to one
ErrorKind. A provider’s reply is preserved as a
ProviderResponseError with its status, body, headers, and request ID;
read it through Self::provider_response or the accessors below.
use rig_core::error::ProviderError;
fn log(error: &ProviderError) {
if let Some(status) = error.provider_response_status() {
// Error envelopes can arrive with successful HTTP statuses.
eprintln!("provider returned HTTP {status}");
}
match error.provider_response_json() {
Ok(Some(json)) => eprintln!("provider error payload: {json}"),
Ok(None) => eprintln!("no provider response body: {error}"),
Err(_) => eprintln!("non-JSON body: {:?}", error.provider_response_body()),
}
}Errors are Clone: sources are shared, so a stream that already yielded
an error can hand the same error to a later caller.
Variants§
Http(Arc<Error>)
A transport failure that produced no provider reply: a reset
connection, a timeout, an unreadable response. A reply the server
made is Self::ProviderResponse.
Json(Arc<Error>)
JSON serialization or deserialization failed.
Url(ParseError)
A URL could not be parsed.
Request(SharedError)
The request could not be built.
Response(String)
The reply decoded but does not answer the request.
Provider(String)
The provider reported a failure without a preserved reply.
ProviderResponse(ProviderResponseError)
The provider’s reply, preserved: a non-success status with its body, a 2xx error envelope, or a non-HTTP transport’s error payload.
InvalidAuthentication(ProviderResponseError)
The provider rejected the configured credentials with 401 or 403.
CacheExpired
A request for an existing context-cache handle answered 403 or 404. The reply’s body is the provider’s explanation, which can name a cause other than expiry, such as a credential or quota failure.
Fields
response: ProviderResponseErrorThe provider’s reply.
MismatchedDimensions
The provider returned vectors of a width other than the one the caller
declared through an embedding wire’s ndims argument. Raised only
when the width was set explicitly.
Fields
MalformedToolInput(MalformedToolInput)
A tool block the provider declared complete carried input that is
not valid JSON. Its report carries the input as
ErrorDetail::MalformedToolInput.
Relayed(Box<ErrorReport>)
A failure a relay delivered as its report, such as a stream relayed over the effect bus. It reports as the relayed report, unchanged.
Truncated
The reply stopped before the provider ended it: its frames ran out, or the runtime stopped, without the provider’s end.
DuplicateCallId(CallId)
The provider named two tool calls of one reply with the same id.
Implementations§
Source§impl ProviderError
impl ProviderError
Sourcepub fn request(reason: impl Into<BoxError>) -> Self
pub fn request(reason: impl Into<BoxError>) -> Self
A request that could not be built, for the given reason.
Sourcepub fn from_http_response(status: StatusCode, body: impl Into<String>) -> Self
pub fn from_http_response(status: StatusCode, body: impl Into<String>) -> Self
Preserves the status and verbatim body as Self::ProviderResponse,
including error envelopes returned with 2xx statuses.
Sourcepub fn from_provider_body(body: impl Into<String>) -> Self
pub fn from_provider_body(body: impl Into<String>) -> Self
Preserves a verbatim provider error body with no HTTP status as
Self::ProviderResponse.
Sourcepub fn from_transport_error(error: Error) -> Self
pub fn from_transport_error(error: Error) -> Self
Converts a non-success reply the transport reported as an error to
Self::ProviderResponse, keeping its status, body, and headers.
Other transport errors become Self::Http.
Sourcepub fn is_retryable(&self) -> bool
pub fn is_retryable(&self) -> bool
Classifies transport failures with transient_transport and
preserved replies with ProviderResponseError::is_retryable; a
truncated reply is retryable. Every other failure, rejected
credentials and expired caches included, is not retryable.
Sourcepub fn provider_response(&self) -> Option<&ProviderResponseError>
pub fn provider_response(&self) -> Option<&ProviderResponseError>
The provider’s preserved reply, when this error carries one.
Sourcepub fn provider_response_body(&self) -> Option<&str>
pub fn provider_response_body(&self) -> Option<&str>
The preserved reply’s body. An empty body returns Some(""), while
Self::provider_response_json maps it to Ok(None).
Sourcepub fn provider_response_json(&self) -> Result<Option<Value>, Error>
pub fn provider_response_json(&self) -> Result<Option<Value>, Error>
Parses the preserved reply’s body as JSON: Ok(None) when there is no
body or it is empty, Err when it is not valid JSON.
Sourcepub fn provider_response_status(&self) -> Option<StatusCode>
pub fn provider_response_status(&self) -> Option<StatusCode>
The preserved reply’s HTTP status. It may be 2xx for an error envelope.
Sourcepub fn provider_request_id(&self) -> Option<&str>
pub fn provider_request_id(&self) -> Option<&str>
The provider’s transport request ID, when the reply carried one.
Sourcepub fn provider_response_headers(&self) -> Option<&HeaderMap>
pub fn provider_response_headers(&self) -> Option<&HeaderMap>
The preserved reply’s headers. None means not captured, as for
non-HTTP transports and replies built from only a status and body.
This example reads the seconds form of Retry-After:
fn backoff(error: &ProviderError) -> Option<Duration> {
let seconds = error
.provider_response_headers()?
.get(http::header::RETRY_AFTER)?
.to_str()
.ok()?
.parse()
.ok()?;
Some(Duration::from_secs(seconds))
}Sourcepub fn with_provider_request_id(self, request_id: Option<String>) -> Self
pub fn with_provider_request_id(self, request_id: Option<String>) -> Self
Fills an absent request ID on the preserved reply, ignoring empty strings.
Sourcepub fn with_response_headers(self, headers: Option<HeaderMap>) -> Self
pub fn with_response_headers(self, headers: Option<HeaderMap>) -> Self
Fills absent headers on the preserved reply.
Sourcepub fn with_provider_status(self, status: Option<StatusCode>) -> Self
pub fn with_provider_status(self, status: Option<StatusCode>) -> Self
Attaches the HTTP status a transport reported beside a reply preserved without one, so it classifies by status. A captured status is kept.
Sourcepub fn with_provider_code(self, code: Option<String>) -> Self
pub fn with_provider_code(self, code: Option<String>) -> Self
Attaches the provider’s machine-readable code for the failure, such as a gRPC status name or an AWS exception type.
Sourcepub fn with_transient(self, transient: Option<bool>) -> Self
pub fn with_transient(self, transient: Option<bool>) -> Self
Replaces the preserved reply’s transport retry verdict, used when its status is absent or successful.
Sourcepub fn report(&self) -> ErrorReport
pub fn report(&self) -> ErrorReport
The wire form of this error.
Trait Implementations§
Source§impl Clone for ProviderError
impl Clone for ProviderError
Source§impl Debug for ProviderError
impl Debug for ProviderError
Source§impl Display for ProviderError
impl Display for ProviderError
Source§impl Error for ProviderError
The source is the shared error itself, not its Arc, so callers can
downcast it.
impl Error for ProviderError
The source is the shared error itself, not its Arc, so callers can
downcast it.
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<&ProviderError> for ErrorReport
impl From<&ProviderError> for ErrorReport
Source§fn from(error: &ProviderError) -> Self
fn from(error: &ProviderError) -> Self
Source§impl From<EncodeError> for ProviderError
impl From<EncodeError> for ProviderError
Source§fn from(error: EncodeError) -> Self
fn from(error: EncodeError) -> Self
Source§impl From<Error> for ProviderError
impl From<Error> for ProviderError
Source§impl From<Error> for ProviderError
impl From<Error> for ProviderError
Source§impl From<Error> for ProviderError
impl From<Error> for ProviderError
Source§impl From<MessageError> for ProviderError
impl From<MessageError> for ProviderError
Source§fn from(error: MessageError) -> Self
fn from(error: MessageError) -> Self
Source§impl From<ParseError> for ProviderError
impl From<ParseError> for ProviderError
Source§fn from(error: ParseError) -> Self
fn from(error: ParseError) -> Self
Source§impl From<ProviderError> for ErrorReport
impl From<ProviderError> for ErrorReport
Source§fn from(error: ProviderError) -> Self
fn from(error: ProviderError) -> Self
Source§impl From<ProviderError> for ConformanceError
Available on crate feature test-utils only.
impl From<ProviderError> for ConformanceError
test-utils only.Source§fn from(source: ProviderError) -> Self
fn from(source: ProviderError) -> Self
Source§impl From<ProviderError> for VectorStoreError
impl From<ProviderError> for VectorStoreError
Source§fn from(source: ProviderError) -> Self
fn from(source: ProviderError) -> Self
Auto Trait Implementations§
impl !RefUnwindSafe for ProviderError
impl !UnwindSafe for ProviderError
impl Freeze for ProviderError
impl Send for ProviderError
impl Sync for ProviderError
impl Unpin for ProviderError
impl UnsafeUnpin for ProviderError
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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> Pointable for T
impl<T> Pointable for T
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> 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.