Skip to main content

invoice_parser/
error.rs

1use thiserror::Error;
2
3#[derive(Error, Debug)]
4pub enum InvoiceParserError {
5    #[error("Failed to read file: {0}")]
6    FileReadError(#[from] std::io::Error),
7
8    #[error("PDF extraction failed: {0}")]
9    PdfExtractionError(String),
10
11    #[error("XLSX parsing failed: {0}")]
12    XlsxParsingError(String),
13
14    #[error("Invalid file format: expected {expected}, got {actual}")]
15    InvalidFileFormat { expected: String, actual: String },
16
17    #[error("Failed to parse date: {0}")]
18    DateParseError(String),
19
20    #[error("Failed to parse amount: {0}")]
21    AmountParseError(String),
22
23    #[error("Missing required field: {0}")]
24    MissingField(String),
25
26    #[error("Regex pattern error: {0}")]
27    RegexError(#[from] regex::Error),
28
29    #[error("JSON serialization error: {0}")]
30    JsonError(#[from] serde_json::Error),
31
32    #[error("Unsupported file type: {0}")]
33    UnsupportedFileType(String),
34
35    #[error("Empty document: no content found")]
36    EmptyDocument,
37
38    #[error("Parse error: {0}")]
39    ParseError(String),
40}
41
42pub type Result<T> = std::result::Result<T, InvoiceParserError>;