Skip to main content

sanitize_engine/
error.rs

1//! Unified error types for the sanitization engine.
2//!
3//! All fallible operations in the crate return [`Result<T>`], which is an
4//! alias for `std::result::Result<T, SanitizeError>`.
5//!
6//! Errors are categorised by subsystem (`IoError`, `SecretsError`,
7//! `ArchiveError`, …) so callers can match on the variant to decide
8//! whether to retry, skip, or abort. The [`thiserror`] derive keeps
9//! display messages actionable and grep-friendly.
10
11use thiserror::Error;
12
13/// All errors that can occur within the sanitization engine.
14#[derive(Debug, Error)]
15#[non_exhaustive]
16pub enum SanitizeError {
17    #[error("replacement store capacity exceeded: {current} mappings (limit: {limit})")]
18    CapacityExceeded { current: usize, limit: usize },
19
20    #[error("invalid seed length: expected 32 bytes, got {0}")]
21    InvalidSeedLength(usize),
22
23    #[error("replacement generator error: {0}")]
24    GeneratorError(String),
25
26    #[error("I/O error: {0}")]
27    IoError(String),
28
29    #[error("parse error ({format}): {message}")]
30    ParseError { format: String, message: String },
31
32    #[error("recursion depth exceeded: {0}")]
33    RecursionDepthExceeded(String),
34
35    #[error("input too large: {size} bytes (limit: {limit})")]
36    InputTooLarge { size: usize, limit: usize },
37
38    #[error("pattern compilation error: {0}")]
39    PatternCompileError(String),
40
41    #[error("invalid configuration: {0}")]
42    InvalidConfig(String),
43
44    #[error("secrets error: {0}")]
45    SecretsError(String),
46
47    #[error("archive error: {0}")]
48    ArchiveError(String),
49}
50
51impl From<std::io::Error> for SanitizeError {
52    fn from(e: std::io::Error) -> Self {
53        SanitizeError::IoError(e.to_string())
54    }
55}
56
57pub type Result<T> = std::result::Result<T, SanitizeError>;