Skip to main content

cloakrs_core/
error.rs

1//! Error types returned by cloakrs.
2
3/// Convenient result alias for cloakrs operations.
4pub type Result<T> = std::result::Result<T, CloakError>;
5
6/// Errors produced by cloakrs core APIs.
7#[derive(Debug, thiserror::Error)]
8pub enum CloakError {
9    /// A confidence score was outside the inclusive `0.0..=1.0` range.
10    #[error("invalid confidence score: {0} (must be 0.0-1.0)")]
11    InvalidConfidence(f64),
12
13    /// A scanner was built or used without any recognizers.
14    #[error("no recognizers registered")]
15    NoRecognizers,
16
17    /// A span does not point at valid UTF-8 character boundaries in the source text.
18    #[error("invalid span {start}..{end} for text length {len}")]
19    InvalidSpan {
20        /// Start byte offset.
21        start: usize,
22        /// End byte offset.
23        end: usize,
24        /// Source text length in bytes.
25        len: usize,
26    },
27
28    /// Regex compilation failed.
29    #[error("regex compilation error: {0}")]
30    RegexError(#[from] regex::Error),
31
32    /// IO failed.
33    #[error("io error: {0}")]
34    IoError(#[from] std::io::Error),
35
36    /// JSON parsing or serialization failed.
37    #[error("json error: {0}")]
38    JsonError(#[from] serde_json::Error),
39
40    /// CSV parsing or serialization failed.
41    #[error("csv error: {0}")]
42    CsvError(#[from] csv::Error),
43
44    /// Encryption failed.
45    #[error("encryption error: {0}")]
46    EncryptionError(String),
47
48    /// Configuration is invalid.
49    #[error("invalid configuration: {0}")]
50    ConfigError(String),
51}