Skip to main content

sdsforge_core/
error.rs

1use thiserror::Error;
2
3#[derive(Debug, Error)]
4pub enum SdsError {
5    #[error("IO error: {0}")]
6    Io(#[from] std::io::Error),
7
8    #[error("JSON error: {0}")]
9    Json(#[from] serde_json::Error),
10
11    #[error("HTTP error: {0}")]
12    Http(#[from] reqwest::Error),
13
14    #[error("Extraction failed: {0}")]
15    Extract(String),
16
17    #[error("DOCX error: {0}")]
18    Docx(String),
19
20    #[error("Unsupported file format: {0}")]
21    UnsupportedFormat(String),
22
23    #[error("Configuration error: {0}")]
24    Config(String),
25
26    #[error("LLM API error: {status} - {message}")]
27    LlmApi { status: u16, message: String },
28
29    #[error("LLM response parse error: {0}")]
30    LlmParse(String),
31
32    #[error("PDF appears to be image-only (OCR unavailable): {0}")]
33    ImageOnlyPdf(String),
34}
35
36impl SdsError {
37    /// Returns a sanitized error message safe for external/client display.
38    /// Strips verbose provider error bodies to avoid information disclosure.
39    pub fn display_safe(&self) -> String {
40        match self {
41            SdsError::LlmApi { status, .. } => {
42                format!("LLM request failed (HTTP {})", status)
43            }
44            other => other.to_string(),
45        }
46    }
47}