Skip to main content

mentedb_extraction/
error.rs

1use thiserror::Error;
2
3/// Errors that can occur during memory extraction.
4#[derive(Debug, Error)]
5pub enum ExtractionError {
6    /// The LLM provider returned an error or was unreachable.
7    #[error("provider error: {0}")]
8    ProviderError(String),
9
10    /// Authentication failed — wrong or missing API key.
11    #[error("authentication failed: {0}")]
12    AuthError(String),
13
14    /// The requested model was not found.
15    #[error("model not found: {0}")]
16    ModelNotFound(String),
17
18    /// The LLM response could not be parsed as valid extraction output.
19    #[error("parse error: {0}")]
20    ParseError(String),
21
22    /// The extraction configuration is invalid.
23    #[error("config error: {0}")]
24    ConfigError(String),
25
26    /// An HTTP request failed.
27    #[error("http error: {0}")]
28    HttpError(String),
29
30    /// An embedding operation failed.
31    #[error("embedding error: {0}")]
32    EmbeddingError(String),
33
34    /// The model stopped at the output token limit before finishing its answer.
35    #[error(
36        "{model} hit the output limit of {max_output_tokens} tokens before finishing; \
37         raise max_output_tokens (MENTEDB_LLM_MAX_OUTPUT_TOKENS) or lower effort"
38    )]
39    Truncated {
40        model: String,
41        max_output_tokens: u32,
42    },
43
44    /// Rate limit exceeded after all retry attempts.
45    #[error("rate limit exceeded after {attempts} attempts")]
46    RateLimitExceeded { attempts: usize },
47}
48
49impl From<reqwest::Error> for ExtractionError {
50    fn from(e: reqwest::Error) -> Self {
51        ExtractionError::HttpError(e.to_string())
52    }
53}
54
55impl From<serde_json::Error> for ExtractionError {
56    fn from(e: serde_json::Error) -> Self {
57        ExtractionError::ParseError(e.to_string())
58    }
59}