Skip to main content

llm_kernel/
error.rs

1//! Error types for llm-kernel.
2
3use thiserror::Error;
4
5/// Errors that can occur when using llm-kernel.
6#[derive(Debug, Error)]
7pub enum KernelError {
8    /// An LLM API returned an error response.
9    #[error("LLM API error: {0}")]
10    LlmApi(String),
11
12    /// The LLM API rate-limited the request.
13    #[error("LLM rate limited: retry after {0}s")]
14    RateLimited(u64),
15
16    /// An HTTP error occurred (non-200 status with code).
17    #[error("HTTP {status}: {message}")]
18    Http {
19        /// HTTP status code.
20        status: u16,
21        /// Error message from the response body.
22        message: String,
23    },
24
25    /// A request timed out.
26    #[error("Request timed out after {0}s")]
27    Timeout(u64),
28
29    /// A configuration error (missing field, bad format, etc.).
30    #[error("Config error: {0}")]
31    Config(String),
32
33    /// A store (SQLite) error.
34    #[error("Store error: {0}")]
35    Store(String),
36
37    /// A secrets vault error.
38    #[error("Vault error: {0}")]
39    Vault(String),
40
41    /// An I/O error.
42    #[error("IO error: {0}")]
43    Io(#[from] std::io::Error),
44
45    /// A serialization/deserialization error.
46    #[cfg(feature = "provider")]
47    #[error("Serialization error: {0}")]
48    Serialization(#[from] serde_json::Error),
49}
50
51/// Alias for `Result<T, KernelError>`.
52pub type Result<T> = std::result::Result<T, KernelError>;