#[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
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.
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
Response
A successful-looking answer that is not a chat completion we can read.
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.
Implementations§
Source§impl ProviderFailure
impl ProviderFailure
Sourcepub fn other(message: impl Into<String>) -> Self
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.
pub fn kind(&self) -> ProviderFailureKind
Sourcepub fn short_reason(&self) -> String
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.
Sourcepub fn after_send(&self) -> bool
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.
Sourcepub fn is_retryable(&self) -> bool
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.
pub fn status(&self) -> Option<u16>
pub fn request_id(&self) -> Option<&str>
Sourcepub fn retry_after_secs(&self) -> Option<u64>
pub fn retry_after_secs(&self) -> Option<u64>
How long the server asked us to wait, in seconds.
Trait Implementations§
Source§impl Clone for ProviderFailure
impl Clone for ProviderFailure
Source§impl Debug for ProviderFailure
impl Debug for ProviderFailure
Source§impl Display for ProviderFailure
impl Display for ProviderFailure
impl Eq for ProviderFailure
Source§impl Error for ProviderFailure
impl Error for ProviderFailure
1.30.0 · 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<&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.
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§impl From<ProviderFailure> for Error
impl From<ProviderFailure> for Error
Source§fn from(f: ProviderFailure) -> Self
fn from(f: ProviderFailure) -> Self
Source§impl From<String> for ProviderFailure
impl From<String> for ProviderFailure
Source§impl PartialEq for ProviderFailure
impl PartialEq for ProviderFailure
impl StructuralPartialEq for ProviderFailure
Auto Trait Implementations§
impl Forget for ProviderFailure
impl Freeze for ProviderFailurewhere
*const u8 is !null: Freeze,
PhantomData<u8>: Freeze,
PhantomData<Hop>: Freeze,
*const ProviderFailure is !null: Freeze,
PhantomData<ProviderFailure>: Freeze,
impl Move for ProviderFailure
impl RefUnwindSafe for ProviderFailure
impl Send for ProviderFailure
impl Sync for ProviderFailure
impl Unpin for ProviderFailure
impl UnsafeUnpin for ProviderFailurewhere
*const u8 is !null: UnsafeUnpin,
PhantomData<u8>: UnsafeUnpin,
PhantomData<Hop>: UnsafeUnpin,
*const ProviderFailure is !null: UnsafeUnpin,
PhantomData<ProviderFailure>: UnsafeUnpin,
impl UnwindSafe for ProviderFailure
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.