#[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
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
RateLimited
HTTP 429. Split out because callers back off rather than fail.
Fields
InsufficientCredits
HTTP 402. Split out because callers stop rather than back off.
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.
AnswerType
A question answer had the wrong primitive type for the accessor used.
Fields
UnknownChoice
A choice answer named an option outside the caller’s crate::typed::ChoiceOptions.
Fields
ScoreRange
A score answer fell outside 0.0..=(levels - 1) for the caller’s
crate::typed::ScoreLevels.
Fields
Invalid
A caller-supplied value failed validation before it reached the network.
Fields
StateTooLarge
The serialized state exceeded the model’s estimated context window.
Fields
MissingApiKey
No API key was configured for the selected provider.
Timeout
The overall per-request deadline elapsed, including any retries.
Implementations§
Source§impl Error
impl Error
Sourcepub fn is_retryable(&self) -> bool
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());Trait Implementations§
Source§impl Error for Error
impl Error for Error
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()