#[non_exhaustive]pub enum ProviderError {
Show 14 variants
Http(Arc<Error>),
Json(Arc<Error>),
Url(ParseError),
Request(Arc<dyn Error + Sync + Send>),
Response(String),
Provider(String),
ProviderResponse(ProviderResponseError),
InvalidAuthentication(ProviderResponseError),
CacheExpired {
name: String,
response: ProviderResponseError,
},
MismatchedDimensions {
provider: String,
requested: usize,
returned: usize,
},
Relayed(Box<ErrorReport>),
Truncated,
Stalled(Duration),
UnsupportedOption(UnsupportedOption),
}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 (Non-exhaustive)§
This enum is marked as non-exhaustive
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(Arc<dyn Error + Sync + Send>)
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: a Rig
diagnostic, never classified as retryable. A provider’s own error
payload belongs in Self::ProviderResponse, whose envelope decides
its code and retry verdict; never put provider JSON here.
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
Relayed(Box<ErrorReport>)
A failure a relay delivered as its report, such as a relayed stream. 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.
Stalled(Duration)
A streamed reply sent no frame for this long, from when it was sent to its first frame or between two, and was dropped. Bytes that are no frame, such as an event stream’s comments, do not count. Retryable.
UnsupportedOption(UnsupportedOption)
A GenerationOptions field
the wire or model cannot honour, under
OnUnsupported::Error.
Implementations§
Source§impl ProviderError
impl ProviderError
Sourcepub fn request(reason: impl Into<Box<dyn Error + Sync + Send>>) -> ProviderError
pub fn request(reason: impl Into<Box<dyn Error + Sync + Send>>) -> ProviderError
A request that could not be built, for the given reason.
Sourcepub fn from_http_response(
status: StatusCode,
body: impl Into<String>,
) -> ProviderError
pub fn from_http_response( status: StatusCode, body: impl Into<String>, ) -> ProviderError
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>) -> ProviderError
pub fn from_provider_body(body: impl Into<String>) -> ProviderError
Preserves a verbatim provider error body with no HTTP status as
Self::ProviderResponse (see ProviderResponseError::from_body).
Sourcepub fn from_transport_error(error: Error) -> ProviderError
pub fn from_transport_error(error: Error) -> ProviderError
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
http_client::Error::is_transient and
preserved replies with ProviderResponseError::is_retryable; a
truncated or stalled 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.
For the wait a provider asked for, use
ErrorReport::retry_after, which reads every form it sends:
fn backoff(error: &ProviderError) -> Option<Duration> {
error.report().retry_after(SystemTime::now())
}Sourcepub fn with_provider_request_id(
self,
request_id: Option<String>,
) -> ProviderError
pub fn with_provider_request_id( self, request_id: Option<String>, ) -> ProviderError
Fills an absent request ID on the preserved reply, ignoring empty strings.
Sourcepub fn with_response_headers(self, headers: Option<HeaderMap>) -> ProviderError
pub fn with_response_headers(self, headers: Option<HeaderMap>) -> ProviderError
Fills absent headers on the preserved reply.
Sourcepub fn with_provider_status(self, status: Option<StatusCode>) -> ProviderError
pub fn with_provider_status(self, status: Option<StatusCode>) -> ProviderError
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>) -> ProviderError
pub fn with_provider_code(self, code: Option<String>) -> ProviderError
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>) -> ProviderError
pub fn with_transient(self, transient: Option<bool>) -> ProviderError
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§fn clone(&self) -> ProviderError
fn clone(&self) -> ProviderError
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§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<EncodeError> for ProviderError
impl From<EncodeError> for ProviderError
Source§fn from(error: EncodeError) -> ProviderError
fn from(error: EncodeError) -> ProviderError
Source§impl From<Error> for ProviderError
impl From<Error> for ProviderError
Source§fn from(error: Error) -> ProviderError
fn from(error: Error) -> ProviderError
Source§impl From<Error> for ProviderError
impl From<Error> for ProviderError
Source§fn from(error: Error) -> ProviderError
fn from(error: Error) -> ProviderError
Source§impl From<Error> for ProviderError
impl From<Error> for ProviderError
Source§fn from(error: Error) -> ProviderError
fn from(error: Error) -> ProviderError
Source§impl From<ParseError> for ProviderError
impl From<ParseError> for ProviderError
Source§fn from(error: ParseError) -> ProviderError
fn from(error: ParseError) -> ProviderError
Source§impl From<ProviderError> for ConformanceError
impl From<ProviderError> for ConformanceError
Source§fn from(source: ProviderError) -> ConformanceError
fn from(source: ProviderError) -> ConformanceError
Source§impl From<ProviderError> for PromptError
A relayed failure is the report the origin sent.
impl From<ProviderError> for PromptError
A relayed failure is the report the origin sent.
Source§fn from(error: ProviderError) -> Self
fn from(error: ProviderError) -> Self
Source§impl From<ProviderError> for ScenarioError
Available on crate feature test-utils only.
impl From<ProviderError> for ScenarioError
test-utils only.