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
impl ProviderError
Sourcepub const fn new(kind: ProviderErrorKind) -> Self
pub const fn new(kind: ProviderErrorKind) -> Self
Builds an error from a kind.
Sourcepub const fn rate_limited(retry_after: Option<Duration>) -> Self
pub const fn rate_limited(retry_after: Option<Duration>) -> Self
The provider rate-limited the request.
Sourcepub const fn authentication() -> Self
pub const fn authentication() -> Self
The credentials were rejected.
The credentials are not entitled to this model.
Sourcepub const fn credential_expired() -> Self
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.
Sourcepub fn quota_exhausted(scope: Option<&str>) -> Self
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.
Sourcepub fn invalid_request(code: impl AsRef<str>) -> Self
pub fn invalid_request(code: impl AsRef<str>) -> Self
The provider rejected our request shape.
Sourcepub const fn context_overflow(
needed_tokens: Option<u64>,
limit_tokens: Option<u64>,
) -> Self
pub const fn context_overflow( needed_tokens: Option<u64>, limit_tokens: Option<u64>, ) -> Self
The prompt did not fit the context window.
Sourcepub const fn model_not_found() -> Self
pub const fn model_not_found() -> Self
The configured model does not exist at this provider.
Sourcepub const fn content_filter() -> Self
pub const fn content_filter() -> Self
The provider’s safety filter blocked the exchange.
Sourcepub fn malformed(code: impl AsRef<str>) -> Self
pub fn malformed(code: impl AsRef<str>) -> Self
The response could not be normalized. code says which step failed.
Sourcepub fn capability_mismatch(mismatch: CapabilityMismatch) -> Self
pub fn capability_mismatch(mismatch: CapabilityMismatch) -> Self
The provider-model pair does not satisfy the stage’s requirements.
Sourcepub fn unsupported(feature: impl AsRef<str>) -> Self
pub fn unsupported(feature: impl AsRef<str>) -> Self
The adapter cannot serve a requested feature.
Sourcepub fn other(code: impl AsRef<str>) -> Self
pub fn other(code: impl AsRef<str>) -> Self
An unclassified failure. Treated as RetryClass::Fatal.
Sourcepub fn with_detail(self, detail: impl AsRef<str>) -> Self
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.
Sourcepub fn detail(&self) -> Option<&ProviderDetail>
pub fn detail(&self) -> Option<&ProviderDetail>
The endpoint’s own sentence, when the adapter had one.
Deliberately not in Display: see ProviderDetail.
Sourcepub fn with_provider(self, provider: impl Into<ProviderKey>) -> Self
pub fn with_provider(self, provider: impl Into<ProviderKey>) -> Self
Attaches the provider key.
Sourcepub fn with_model(self, model: &ModelRef) -> Self
pub fn with_model(self, model: &ModelRef) -> Self
Attaches provider and model keys at once.
Sourcepub fn kind(&self) -> &ProviderErrorKind
pub fn kind(&self) -> &ProviderErrorKind
The failure family.
Sourcepub fn provider(&self) -> Option<&ProviderKey>
pub fn provider(&self) -> Option<&ProviderKey>
The provider key, when known.
Sourcepub const fn retry_class(&self) -> RetryClass
pub const fn retry_class(&self) -> RetryClass
How the caller may proceed.
Sourcepub const fn retry_after(&self) -> Option<Duration>
pub const fn retry_after(&self) -> Option<Duration>
The delay the provider asked for, when it supplied one.
Sourcepub const fn is_retryable(&self) -> bool
pub const fn is_retryable(&self) -> bool
Returns true when the same provider may be called again.
Sourcepub fn to_core_failure(&self) -> ProviderFailure
pub fn to_core_failure(&self) -> ProviderFailure
Converts into the normalized failure the core error family stores.
Trait Implementations§
Source§impl Clone for ProviderError
impl Clone for ProviderError
Source§impl Debug for ProviderError
impl Debug for ProviderError
Source§fn fmt(&self, f: &mut Formatter<'_>) -> Result
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
impl Display for ProviderError
impl Eq for ProviderError
Source§impl Error for ProviderError
impl Error for ProviderError
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<CapabilityMismatch> for ProviderError
impl From<CapabilityMismatch> for ProviderError
Source§fn from(value: CapabilityMismatch) -> Self
fn from(value: CapabilityMismatch) -> Self
Source§impl From<DialectError> for ProviderError
impl From<DialectError> for ProviderError
Source§fn from(value: DialectError) -> Self
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
impl From<ProviderError> for ProviderFailure
Source§fn from(value: ProviderError) -> Self
fn from(value: ProviderError) -> Self
Source§impl From<StructuredOutputError> for ProviderError
impl From<StructuredOutputError> for ProviderError
Source§impl PartialEq for ProviderError
impl PartialEq for ProviderError
impl StructuralPartialEq for ProviderError
Auto Trait Implementations§
impl Freeze for ProviderError
impl RefUnwindSafe for ProviderError
impl Send for ProviderError
impl Sync for ProviderError
impl Unpin for ProviderError
impl UnsafeUnpin for ProviderError
impl UnwindSafe for ProviderError
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
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§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.