Skip to main content

synwire_core/error/
model.rs

1//! Errors specific to language model invocations.
2
3use std::time::Duration;
4
5/// Errors specific to language model invocations.
6#[derive(Debug, thiserror::Error)]
7#[non_exhaustive]
8pub enum ModelError {
9    /// Rate limit exceeded.
10    #[error("rate limit exceeded{}", .retry_after.map(|d| format!(", retry after {d:?}")).unwrap_or_default())]
11    RateLimit {
12        /// Optional duration to wait before retrying.
13        retry_after: Option<Duration>,
14    },
15    /// Authentication failed.
16    #[error("authentication failed: {message}")]
17    AuthenticationFailed {
18        /// Error message.
19        message: String,
20    },
21    /// Invalid request.
22    #[error("invalid request: {message}")]
23    InvalidRequest {
24        /// Error message.
25        message: String,
26    },
27    /// Content filtered by safety system.
28    #[error("content filtered: {message}")]
29    ContentFiltered {
30        /// Error message.
31        message: String,
32    },
33    /// Request timed out.
34    #[error("request timed out")]
35    Timeout,
36    /// Connection error.
37    #[error("connection error: {source}")]
38    Connection {
39        /// Underlying error.
40        source: Box<dyn std::error::Error + Send + Sync>,
41    },
42    /// Other model error.
43    #[error("model error: {message}")]
44    Other {
45        /// Error message.
46        message: String,
47    },
48}