uni_xervo/error.rs
1//! Error types for the Uni-Xervo runtime.
2
3use thiserror::Error;
4
5/// Convenience alias used throughout the crate.
6pub type Result<T> = std::result::Result<T, RuntimeError>;
7
8/// Unified error type covering configuration, loading, inference, and transport
9/// failures.
10///
11/// Variants are intentionally coarse-grained so that callers can match on error
12/// *category* (e.g. retryable vs permanent) rather than on provider-specific
13/// details.
14#[derive(Debug, Error)]
15pub enum RuntimeError {
16 /// Invalid or missing configuration (bad alias format, unknown option, etc.).
17 #[error("Configuration error: {0}")]
18 Config(String),
19
20 /// The requested provider ID is not registered with the runtime.
21 #[error("Provider not found: {0}")]
22 ProviderNotFound(String),
23
24 /// A model was requested for a task the provider does not support.
25 #[error("Capability mismatch: {0}")]
26 CapabilityMismatch(String),
27
28 /// Model loading or initialization failed (download, weight parsing, etc.).
29 #[error("Load error: {0}")]
30 Load(String),
31
32 /// An HTTP or transport-level error from a remote provider.
33 #[error("API error: {0}")]
34 ApiError(String),
35
36 /// An error during model inference (tokenization, forward pass, etc.).
37 #[error("Inference error: {0}")]
38 InferenceError(String),
39
40 /// The remote API returned HTTP 429 (too many requests).
41 #[error("Rate limited")]
42 RateLimited,
43
44 /// The remote API returned HTTP 401/403 (bad or missing credentials).
45 #[error("Unauthorized")]
46 Unauthorized,
47
48 /// The operation exceeded its configured timeout.
49 #[error("Timeout")]
50 Timeout,
51
52 /// The service is currently unavailable (HTTP 5xx, circuit breaker open, etc.).
53 #[error("Unavailable")]
54 Unavailable,
55}
56
57impl RuntimeError {
58 /// Returns `true` for transient errors that may succeed on retry:
59 /// [`RateLimited`](Self::RateLimited), [`Timeout`](Self::Timeout), and
60 /// [`Unavailable`](Self::Unavailable).
61 pub fn is_retryable(&self) -> bool {
62 matches!(self, Self::RateLimited | Self::Timeout | Self::Unavailable)
63 }
64}