imp_llm/error.rs
1/// Errors that can occur within the imp-llm crate.
2#[derive(Debug, thiserror::Error)]
3pub enum Error {
4 /// A provider-specific error (e.g. invalid request).
5 #[error("Provider error: {0}")]
6 Provider(String),
7
8 /// Authentication failure (missing key, expired token, etc.).
9 #[error("Auth error: {0}")]
10 Auth(String),
11
12 /// Error during response streaming.
13 #[error("Stream error: {0}")]
14 Stream(String),
15
16 /// JSON serialization / deserialization failure.
17 #[error("Serialization error: {0}")]
18 Serialization(#[from] serde_json::Error),
19
20 /// HTTP transport error.
21 #[error("HTTP error: {0}")]
22 Http(#[from] reqwest::Error),
23
24 /// File system I/O error.
25 #[error("IO error: {0}")]
26 Io(#[from] std::io::Error),
27
28 /// Provider is rate-limiting requests.
29 #[error("Rate limited: retry after {retry_after_secs:?}s")]
30 RateLimited {
31 /// Suggested wait time before retrying, if the provider reported one.
32 retry_after_secs: Option<u64>,
33 },
34
35 /// The conversation exceeds the model's context window.
36 #[error("Context too long: {used} tokens exceeds {limit}")]
37 ContextTooLong {
38 /// Tokens used by the current conversation.
39 used: u32,
40 /// Maximum tokens the model supports.
41 limit: u32,
42 },
43}
44
45/// Convenience alias used throughout the crate.
46pub type Result<T> = std::result::Result<T, Error>;