Skip to main content

Error

Enum Error 

Source
#[non_exhaustive]
pub enum Error {
Show 14 variants Http(Error), Io(Error), Api { status: u16, message: String, body: String, }, RateLimited { retry_after_secs: Option<u64>, }, InsufficientCredits { message: String, }, Parse(String), MissingAnswer { key: String, }, AnswerType { key: String, expected: &'static str, actual: String, }, UnknownChoice { key: String, choice: String, expected: String, }, ScoreRange { key: String, score: f64, levels: usize, }, Invalid { field: String, reason: String, }, StateTooLarge { estimated: usize, limit: usize, }, MissingApiKey, Timeout { elapsed_ms: u64, },
}
Expand description

Everything that can go wrong calling Jev, in one non-exhaustive enum.

Variants are chosen so callers can act on the kind of failure without parsing error strings: Error::is_retryable and Error::status cover the two most common branches (back off and try again, or surface the HTTP status).

No variant embeds request state or question criteria text: those may contain PII and are never placed in an error message or a tracing field.

§Examples

use jev::Error;

let err = Error::RateLimited { retry_after_secs: Some(2) };
assert!(err.is_retryable());
assert_eq!(err.status(), Some(429));

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

Http(Error)

The underlying HTTP transport failed (connect, timeout, TLS, decoding, …).

§

Io(Error)

Reading a case file (see crate::CaseSet::from_file) failed.

§

Api

The API responded with a non-2xx status carrying a {"error": {...}} envelope.

Fields

§status: u16

HTTP status code returned by the API.

§message: String

Human-readable message extracted from the error envelope, if present.

§body: String

Raw response body, truncated to 4 KiB on a UTF-8 character boundary.

§

RateLimited

HTTP 429. Split out because callers back off rather than fail.

Fields

§retry_after_secs: Option<u64>

Seconds to wait before retrying, parsed from Retry-After, when present.

§

InsufficientCredits

HTTP 402. Split out because callers stop rather than back off.

Fields

§message: String

Human-readable message extracted from the error envelope, if present.

§

Parse(String)

The response body did not match the expected shape.

§

MissingAnswer

A crate::typed::Decision field had no corresponding entry in the answer map.

Fields

§key: String

The question key that was expected but absent.

§

AnswerType

A question answer had the wrong primitive type for the accessor used.

Fields

§key: String

The question key being read.

§expected: &'static str

The primitive the caller expected ("noul", "choice", or "score").

§actual: String

The primitive actually present, or "other(<type>)" for an unknown one.

§

UnknownChoice

A choice answer named an option outside the caller’s crate::typed::ChoiceOptions.

Fields

§key: String

The question key being read.

§choice: String

The option key the server returned.

§expected: String

A comma-separated list of the option keys the caller declared.

§

ScoreRange

A score answer fell outside 0.0..=(levels - 1) for the caller’s crate::typed::ScoreLevels.

Fields

§key: String

The question key being read.

§score: f64

The out-of-range score returned by the server.

§levels: usize

The number of levels the caller’s enum declares.

§

Invalid

A caller-supplied value failed validation before it reached the network.

Fields

§field: String

The name of the field or configuration key that failed validation.

§reason: String

A human-readable reason, safe to log (never echoes the offending value when the value itself might be sensitive).

§

StateTooLarge

The serialized state exceeded the model’s estimated context window.

Fields

§estimated: usize

The estimated token count of the serialized request.

§limit: usize

The model’s context window, in tokens.

§

MissingApiKey

No API key was configured for the selected provider.

§

Timeout

The overall per-request deadline elapsed, including any retries.

Fields

§elapsed_ms: u64

Milliseconds elapsed before the deadline fired.

Implementations§

Source§

impl Error

Source

pub fn is_retryable(&self) -> bool

Whether retrying the request that produced this error could plausibly succeed.

Deterministic client errors (400, 401, 402, 403, 404, 413, and any caller-side validation failure) are never retryable; transport-level timeouts, 429, and 5xx are.

§Examples
use jev::Error;

assert!(Error::RateLimited { retry_after_secs: None }.is_retryable());
assert!(!Error::InsufficientCredits { message: "no credits".into() }.is_retryable());
Source

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

The HTTP status code this error carries, when it originated from the API.

§Examples
use jev::Error;

assert_eq!(Error::RateLimited { retry_after_secs: None }.status(), Some(429));
assert_eq!(Error::MissingApiKey.status(), None);

Trait Implementations§

Source§

impl Debug for Error

Source§

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

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

impl Display for Error

Source§

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

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

impl Error for Error

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<Error> for Error

Source§

fn from(source: Error) -> Self

Converts to this type from the input type.
Source§

impl From<Error> for Error

Source§

fn from(source: Error) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

§

impl !RefUnwindSafe for Error

§

impl !UnwindSafe for Error

§

impl Freeze for Error

§

impl Send for Error

§

impl Sync for Error

§

impl Unpin for Error

§

impl UnsafeUnpin for Error

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