1use std::path::PathBuf;
4
5#[derive(thiserror::Error, Debug)]
7pub enum PdfVdiffError {
8 #[error("File not found: {0}")]
9 FileNotFound(PathBuf),
10
11 #[error("Output file '{0}' already exists. Use --force to overwrite.")]
12 OutputFileExists(PathBuf),
13
14 #[error("Failed to open PDF at '{path}': {reason}")]
15 PdfOpen { path: PathBuf, reason: String },
16
17 #[error("PDF '{0}' is password-protected. Please provide an unlocked document.")]
18 PasswordProtected(PathBuf),
19
20 #[error("PDF '{0}' contains no extractable text layer. Text-based diffing requires OCR text.")]
21 NoTextLayer(PathBuf),
22
23 #[error("Page count ({0}) exceeds maximum allowed limit ({1}). Override with --max-pages.")]
24 PageCountExceeded(usize, usize),
25
26 #[error("Invalid page dimensions in '{path}': {reason}")]
27 InvalidDimensions { path: PathBuf, reason: String },
28
29 #[error("Output IO error at '{path}': {source}")]
30 OutputIo {
31 path: PathBuf,
32 #[source]
33 source: std::io::Error,
34 },
35
36 #[error("Rendering engine error: {0}")]
37 Render(String),
38}
39
40#[cfg(test)]
41mod tests {
42 use super::*;
43
44 #[test]
45 fn test_error_display() {
46 let err = PdfVdiffError::FileNotFound(PathBuf::from("test.pdf"));
47 assert_eq!(err.to_string(), "File not found: test.pdf");
48
49 let err = PdfVdiffError::OutputFileExists(PathBuf::from("out.pdf"));
50 assert!(err.to_string().contains("--force"));
51
52 let err = PdfVdiffError::PageCountExceeded(300, 250);
53 assert!(err.to_string().contains("300"));
54 }
55}