Skip to main content

rusty_pdfgrep/
error.rs

1//! Public error type for the rusty-pdfgrep library API (FR-041).
2
3use std::path::PathBuf;
4
5/// Error type returned by [`PdfGrep`](crate::PdfGrep) operations.
6///
7/// `#[non_exhaustive]` allows additive variants in SemVer-minor releases.
8/// Downstream code MUST use a wildcard `_` arm when matching.
9#[non_exhaustive]
10#[derive(Debug, thiserror::Error)]
11pub enum PdfGrepError {
12    /// I/O failure for a specific path.
13    #[error("rusty-pdfgrep: {path}: {source}")]
14    Io {
15        /// Path being operated on when the error occurred.
16        path: PathBuf,
17        /// Underlying `std::io::Error`.
18        #[source]
19        source: std::io::Error,
20    },
21
22    /// PDF parser error from `lopdf`.
23    #[error("rusty-pdfgrep: {path}: PDF parse error: {message}")]
24    Pdf {
25        /// Path of the PDF that failed to parse.
26        path: PathBuf,
27        /// Human-readable explanation from the parser.
28        message: String,
29    },
30
31    /// PDF is encrypted and no `--password` succeeded.
32    #[error("rusty-pdfgrep: {path}: encrypted; skipping")]
33    Encrypted {
34        /// Path of the encrypted PDF.
35        path: PathBuf,
36    },
37
38    /// Regex compilation failed (invalid pattern).
39    #[error("rusty-pdfgrep: invalid regex '{pattern}': {message}")]
40    RegexCompile {
41        /// The offending pattern string.
42        pattern: String,
43        /// Compiler diagnostic.
44        message: String,
45    },
46
47    /// Invalid page-range value (e.g., reverse range or non-numeric).
48    #[error("rusty-pdfgrep: invalid page range '{value}'")]
49    PageRange {
50        /// The offending input value.
51        value: String,
52    },
53}