Skip to main content

UsageError

Enum UsageError 

Source
#[non_exhaustive]
pub enum UsageError { NoCredentials, Credentials(CredentialError), Timeout, RateLimited { retry_after: Option<Duration>, }, NetworkError, ParseError, Unauthorized, Jsonl(JsonlError), }
Expand description

Errors from the OAuth /api/oauth/usage endpoint plus the cache stack, credential, and JSONL-fallback layers that feed it. Rendered to the user via the segment error table in docs/specs/rate-limit-segments.md.

PartialEq is not derived: inner types (io::Error, serde_json::Error) don’t support it. CredentialError has a lossy Clone impl so the cascade can preserve variant-level detail across Arc<Result<_, CredentialError>> boundaries; UsageError itself isn’t Clone because DataContext memoizes it behind Arc<Result<_, UsageError>> and cross-segment sharing clones the Arc.

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

NoCredentials

No OAuth token reachable from any cascade path. Rendered [No credentials].

§

Credentials(CredentialError)

Credentials-layer failure. Segment code matches on the inner variant to render [Keychain error] / [Credentials unreadable] / [No credentials] per the error table.

§

Timeout

Endpoint took longer than the configured timeout. Rendered [Timeout].

§

RateLimited

Endpoint returned 429 Too Many Requests. retry_after is the parsed Retry-After header (integer seconds or HTTP-date per ADR-0011 §Cache stack); None means the header was absent and the default 300s backoff applies. Rendered [Rate limited].

Fields

§retry_after: Option<Duration>
§

NetworkError

Connection failed, DNS failure, TLS failure, or any other network-level error. Rendered [Network error].

§

ParseError

Endpoint returned malformed JSON. Rendered [Parse error].

§

Unauthorized

Endpoint returned 401 Unauthorized. Token is expired or revoked; Claude Code refreshes on its next request. Rendered [Unauthorized].

§

Jsonl(JsonlError)

JSONL-fallback-layer failure. Surfaces when the endpoint path recorded an error AND the JSONL aggregator also yielded nothing.

Implementations§

Source§

impl UsageError

Source

pub fn code(&self) -> &'static str

Short plugin-facing error tag per docs/specs/plugin-api.md §ctx shape exposed to rhai. Rendered in the rhai tagged-map mirror as error: "<code>". Wrapping variants (Credentials, Jsonl) delegate to the inner error’s code() so plugins see a flat taxonomy. Today those inner types are stubs that return "NotImplemented"; once the credential and JSONL layers land the delegation surfaces the full spec set ("NoCredentials", "SubprocessFailed", "IoError", "ParseError", etc.).

Trait Implementations§

Source§

impl Debug for UsageError

Source§

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

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

impl Display for UsageError

Source§

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

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

impl Error for UsageError

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

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> ErrorExt for T
where T: Error + Send + Sync + 'static,

Source§

fn raise(self) -> Exn<Self>
where Self: Sized,

Raise this error as a new exception.
Source§

fn and_raise<T>(self, context: T) -> Exn<T>
where T: Error + Send + Sync + 'static, Self: Sized,

Raise this error as a child of a new exception with the given context error. Read more
Source§

fn raise_erased(self) -> Exn
where Self: Sized,

Raise this error as a new exception, with type erasure.
Source§

fn raise_all<T, I>(self, sources: I) -> Exn<Self>
where Self: Sized, T: Error + Send + Sync + 'static, I: IntoIterator, <I as IntoIterator>::Item: Into<Exn<T>>,

Raise this error as a new exception, with sources as causes.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> Same for T

Source§

type Output = T

Should always be Self
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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.