Skip to main content

cleansh_core/
errors.rs

1//! errors.rs - Custom error types for the cleansh-core library.
2//!
3//! This module defines a structured error enum for the library, providing
4//! specific, actionable error types that can be handled programmatically.
5//!
6//! License: MIT OR APACHE 2.0
7
8use thiserror::Error;
9
10/// This enum represents all possible error types in the `cleansh-core` library.
11///
12/// By using `#[non_exhaustive]`, we signal to consumers of this library that
13/// new variants may be added in future versions. This prevents them from
14/// matching all variants exhaustively, thus avoiding breaking changes.
15#[derive(Error, Debug)]
16#[non_exhaustive]
17pub enum CleanshError {
18    #[error("Failed to compile redaction rule '{0}': {1}")]
19    RuleCompilationError(String, regex::Error),
20
21    #[error("Rule '{0}': pattern length ({1}) exceeds maximum allowed ({2})")]
22    PatternLengthExceeded(String, usize, usize),
23
24    #[error("Failed to serialize configuration for hashing: {0}")]
25    SerializationError(String),
26
27    #[error("An unexpected I/O error occurred: {0}")]
28    IoError(#[from] std::io::Error),
29
30    #[error("A critical system error occurred: {0}")]
31    AnyhowWrapper(#[from] anyhow::Error),
32    
33    // Add other specific error types as the project grows
34    #[error("A fatal error occurred: {0}")]
35    Fatal(String),
36}