Skip to main content

ProviderError

Struct ProviderError 

Source
pub struct ProviderError { /* private fields */ }
Expand description

A normalized provider failure.

Built with the constructors below and enriched with with_model once the caller knows which candidate produced it. Display and Debug are safe to log: the endpoint’s own sentence is carried but rendered by neither, and is read deliberately through detail. See ProviderDetail.

Implementations§

Source§

impl ProviderError

Source

pub const fn new(kind: ProviderErrorKind) -> Self

Builds an error from a kind.

Source

pub const fn timeout() -> Self

The call did not complete in time.

Source

pub const fn rate_limited(retry_after: Option<Duration>) -> Self

The provider rate-limited the request.

Source

pub const fn authentication() -> Self

The credentials were rejected.

Source

pub const fn authorization() -> Self

The credentials are not entitled to this model.

Source

pub const fn credential_expired() -> Self

A credential that was valid has expired and must be refreshed.

Use this, not authentication, whenever the provider distinguishes the two — a rejected key and an expired token call for opposite reactions from whatever holds the credential.

Source

pub fn quota_exhausted(scope: Option<&str>) -> Self

The account’s quota or credit balance is exhausted.

scope names the quota when the provider names one. Use this, not rate_limited, even when the provider reports it with HTTP 429.

Source

pub fn invalid_request(code: impl AsRef<str>) -> Self

The provider rejected our request shape.

Source

pub const fn context_overflow( needed_tokens: Option<u64>, limit_tokens: Option<u64>, ) -> Self

The prompt did not fit the context window.

Source

pub const fn model_not_found() -> Self

The configured model does not exist at this provider.

Source

pub const fn refusal() -> Self

The model declined to answer.

Source

pub const fn content_filter() -> Self

The provider’s safety filter blocked the exchange.

Source

pub fn malformed(code: impl AsRef<str>) -> Self

The response could not be normalized. code says which step failed.

Source

pub fn transport(code: impl AsRef<str>) -> Self

The network call did not complete.

Source

pub const fn server(status: Option<u16>) -> Self

The provider failed on its side.

Source

pub const fn cancelled() -> Self

The caller cancelled the call.

Source

pub fn capability_mismatch(mismatch: CapabilityMismatch) -> Self

The provider-model pair does not satisfy the stage’s requirements.

Source

pub fn unsupported(feature: impl AsRef<str>) -> Self

The adapter cannot serve a requested feature.

Source

pub fn other(code: impl AsRef<str>) -> Self

An unclassified failure. Treated as RetryClass::Fatal.

Source

pub fn with_detail(self, detail: impl AsRef<str>) -> Self

Attaches the endpoint’s own sentence, sanitized.

Pass it through the adapter’s Redactor first, the way a code is. Nothing is attached when nothing survives sanitizing.

Source

pub fn detail(&self) -> Option<&ProviderDetail>

The endpoint’s own sentence, when the adapter had one.

Deliberately not in Display: see ProviderDetail.

Source

pub fn with_code(self, code: impl AsRef<str>) -> Self

Attaches a sanitized adapter code.

Source

pub fn with_provider(self, provider: impl Into<ProviderKey>) -> Self

Attaches the provider key.

Source

pub fn with_model(self, model: &ModelRef) -> Self

Attaches provider and model keys at once.

Source

pub fn kind(&self) -> &ProviderErrorKind

The failure family.

Source

pub fn provider(&self) -> Option<&ProviderKey>

The provider key, when known.

Source

pub fn model(&self) -> Option<&ModelKey>

The model key, when known.

Source

pub fn code(&self) -> Option<&ErrorCode>

The adapter’s sanitized code, when it supplied one.

Source

pub const fn retry_class(&self) -> RetryClass

How the caller may proceed.

Source

pub const fn retry_after(&self) -> Option<Duration>

The delay the provider asked for, when it supplied one.

Source

pub const fn is_retryable(&self) -> bool

Returns true when the same provider may be called again.

Source

pub fn to_core_failure(&self) -> ProviderFailure

Converts into the normalized failure the core error family stores.

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

Renders everything Display does, and says only whether an endpoint sentence is attached.

Hand-written rather than derived because a derived one would print the sentence, and {:?} on an error is the most common way a body reaches a log by accident. The value is still there for a caller that asks for it.

Source§

impl Display for ProviderError

Source§

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

Renders kind, keys and code — never a body, a header or user text.

Source§

impl Eq for ProviderError

Source§

impl Error for ProviderError

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

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<CapabilityMismatch> for ProviderError

Source§

fn from(value: CapabilityMismatch) -> Self

Converts to this type from the input type.
Source§

impl From<DialectError> for ProviderError

Source§

fn from(value: DialectError) -> Self

A schema the dialect cannot carry is an Unsupported feature, whose retry class is Fallback.

The capability declaration stays true: this provider does enforce schemas, it just cannot enforce this one. So the router may offer the turn to another profile, and must not re-roll against the same one.

Source§

impl From<ProviderError> for ProviderFailure

Source§

fn from(value: ProviderError) -> Self

Converts to this type from the input type.
Source§

impl From<StructuredOutputError> for ProviderError

Source§

fn from(value: StructuredOutputError) -> Self

A rejected structured response is a Refusal when the model declined, and Malformed otherwise — so a re-roll is the classified remedy.

Source§

impl PartialEq for ProviderError

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 ProviderError

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<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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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