Skip to main content

ProviderFailure

Enum ProviderFailure 

Source
#[non_exhaustive]
pub enum ProviderFailure { Transport { url: String, message: String, sent: bool, }, Unauthorized(HttpFailure), InvalidRequest(HttpFailure), Http(HttpFailure), Truncated { message: String, streamed_chars: usize, }, Response { message: String, body: Option<String>, }, Routed { route: String, trail: Vec<Hop>, stop: RouteStop, cause: Box<ProviderFailure>, }, }
Expand description

Which way talking to the model server failed.

Kept as structure rather than a formatted string because two callers need to ask questions about it: the retry loop wants is_retryable(), and the operator wants the status, the body the server actually sent and the id to quote at support.

Variants (Non-exhaustive)§

This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

Transport

No answer at all: DNS, connection refused or reset, TLS, timeout.

sent says whether the request had already gone out when this happened, because that is the difference between a free retry and a billed one: a connect-stage failure never reached the server, while a reset after the body was written may have been read, charged, or half-run.

Fields

§message: String
§sent: bool
§

Unauthorized(HttpFailure)

401 or 403: the key is missing, wrong, or not allowed to use this model.

§

InvalidRequest(HttpFailure)

400, 404, 405, 422: the request is wrong for this server or this model — an option it does not know, a model name it does not serve, a tool schema it cannot parse.

§

Http(HttpFailure)

Any other non-2xx answer.

§

Truncated

The stream ended before the model said it was done. Retryable, but see ProviderFailure::is_retryable and the rule the provider applies: only when nothing has been shown to the reader yet, because replaying text they already read is worse than failing.

Fields

§message: String
§streamed_chars: usize

How much text had arrived before the cut, for the message.

§

Response

A successful-looking answer that is not a chat completion we can read.

Fields

§message: String
§

Routed

A failure that came out of a Router, carrying the route it happened on and the hops taken before it. Every question a caller asks about a failure is answered by cause; this wrapper only adds where.

Fields

§route: String

The route that was being tried when the run stopped.

§trail: Vec<Hop>

The hops made before this failure, oldest first.

§cause: Box<ProviderFailure>

Named cause, not source, so thiserror does not treat it as the error source.

Implementations§

Source§

impl ProviderFailure

Source

pub fn other(message: impl Into<String>) -> Self

A failure with nothing but an explanation: a reply we could not read, a test double, an error the server put inside a stream.

Source

pub fn kind(&self) -> ProviderFailureKind

Source

pub fn short_reason(&self) -> String

A few words for a readout: timeout, HTTP 503, stream cut. The full text is the failure’s Display; this is what fits after an arrow.

Source

pub fn after_send(&self) -> bool

Whether the request had already been written to the socket when this failure happened.

/chat/completions is not idempotent and it is billed, so a drop after the body went out may cost a whole generation that repeating will pay for again. A connect-stage failure costs nothing to repeat. Everything that is not a transport failure answers false: it has its own retry rule.

Source

pub fn is_retryable(&self) -> bool

Whether repeating the request could plausibly work. Deliberately conservative: a wrong key or a rejected option will fail the same way every time, and retrying it only wastes the operator’s morning.

Source

pub fn status(&self) -> Option<u16>

Source

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

The server’s own words, when there were any.

Source

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

Source

pub fn retry_after_secs(&self) -> Option<u64>

How long the server asked us to wait, in seconds.

Source

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

What the operator should do next, when we can say.

Trait Implementations§

Source§

impl Clone for ProviderFailure

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 ProviderFailure

Source§

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

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

impl Display for ProviderFailure

Source§

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

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

impl Eq for ProviderFailure

Source§

impl Error for ProviderFailure

1.30.0 · 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

Replaced by Error::source.
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<&str> for ProviderFailure

Keep a string-to-failure conversion available so a plain message is never a compile error in a hurry — but prefer a real variant where one exists.

Source§

fn from(s: &str) -> Self

Converts to this type from the input type.
Source§

impl From<ProviderFailure> for Error

Source§

fn from(f: ProviderFailure) -> Self

Converts to this type from the input type.
Source§

impl From<String> for ProviderFailure

Source§

fn from(s: String) -> Self

Converts to this type from the input type.
Source§

impl PartialEq for ProviderFailure

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for ProviderFailure

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<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<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
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> 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> 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, 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<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