Skip to main content

ProviderError

Enum ProviderError 

Source
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

§name: String

The cache handle the request named.

§response: ProviderResponseError

The 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

§provider: String

Provider whose response disagreed with the declared width.

§requested: usize

Width the caller declared.

§returned: usize

Width the provider actually returned.

§

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

Source

pub fn request(reason: impl Into<BoxError>) -> Self

A request that could not be built, for the given reason.

Source

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.

Source

pub fn from_provider_body(body: impl Into<String>) -> Self

Preserves a verbatim provider error body with no HTTP status as Self::ProviderResponse.

Source

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.

Source

pub fn kind(&self) -> ErrorKind

The classification this error reports as.

Source

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.

Source

pub fn provider_response(&self) -> Option<&ProviderResponseError>

The provider’s preserved reply, when this error carries one.

Source

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).

Source

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.

Source

pub fn provider_response_status(&self) -> Option<StatusCode>

The preserved reply’s HTTP status. It may be 2xx for an error envelope.

Source

pub fn provider_request_id(&self) -> Option<&str>

The provider’s transport request ID, when the reply carried one.

Source

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))
}
Source

pub fn with_provider_request_id(self, request_id: Option<String>) -> Self

Fills an absent request ID on the preserved reply, ignoring empty strings.

Source

pub fn with_response_headers(self, headers: Option<HeaderMap>) -> Self

Fills absent headers on the preserved reply.

Source

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.

Source

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.

Source

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.

Source

pub fn report(&self) -> ErrorReport

The wire form of this error.

Trait Implementations§

Source§

impl Clone for ProviderError

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ProviderError

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for ProviderError

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

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)>

Returns the lower-level source of this error, if any. Read more
1.0.0 · Source§

fn description(&self) -> &str

👎Deprecated since 1.42.0:

use the Display impl or to_string()

1.0.0 · Source§

fn cause(&self) -> Option<&dyn Error>

👎Deprecated since 1.33.0:

replaced by Error::source, which can support downcasting

Source§

fn provide<'a>(&'a self, request: &mut Request<'a>)

🔬This is a nightly-only experimental API. (error_generic_member_access)
Provides type-based access to context intended for error reports. Read more
Source§

impl From<&ProviderError> for ErrorReport

Source§

fn from(error: &ProviderError) -> Self

Converts to this type from the input type.
Source§

impl From<Box<dyn Error + Send + Sync>> for ProviderError

Source§

fn from(error: BoxError) -> Self

Converts to this type from the input type.
Source§

impl From<EncodeError> for ProviderError

Source§

fn from(error: EncodeError) -> Self

Converts to this type from the input type.
Source§

impl From<Error> for ProviderError

Source§

fn from(error: Error) -> Self

Converts to this type from the input type.
Source§

impl From<Error> for ProviderError

Source§

fn from(error: Error) -> Self

Converts to this type from the input type.
Source§

impl From<Error> for ProviderError

Source§

fn from(error: Error) -> Self

Converts to this type from the input type.
Source§

impl From<MessageError> for ProviderError

Source§

fn from(error: MessageError) -> Self

Converts to this type from the input type.
Source§

impl From<ParseError> for ProviderError

Source§

fn from(error: ParseError) -> Self

Converts to this type from the input type.
Source§

impl From<ProviderError> for ErrorReport

Source§

fn from(error: ProviderError) -> Self

Converts to this type from the input type.
Source§

impl From<ProviderError> for ConformanceError

Available on crate feature test-utils only.
Source§

fn from(source: ProviderError) -> Self

Converts to this type from the input type.
Source§

impl From<ProviderError> for VectorStoreError

Source§

fn from(source: ProviderError) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts 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 more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T> ToStringFallible for T
where T: Display,

Source§

fn try_to_string(&self) -> Result<String, TryReserveError>

ToString::to_string, but without panic on OOM.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WasmCompatSend for T
where T: Send,

Source§

impl<T> WasmCompatSync for T
where T: Sync,

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more