Skip to main content

datasynth_fingerprint/
error.rs

1//! Error types for the fingerprint crate.
2
3use thiserror::Error;
4
5/// Result type for fingerprint operations.
6pub type FingerprintResult<T> = Result<T, FingerprintError>;
7
8/// Errors that can occur during fingerprint operations.
9#[derive(Debug, Error)]
10pub enum FingerprintError {
11    /// I/O error during file operations.
12    #[error("I/O error: {0}")]
13    Io(#[from] std::io::Error),
14
15    /// Error during ZIP archive operations.
16    #[error("ZIP archive error: {0}")]
17    Zip(#[from] zip::result::ZipError),
18
19    /// Error during JSON serialization/deserialization.
20    #[error("JSON error: {0}")]
21    Json(#[from] serde_json::Error),
22
23    /// Error during YAML serialization/deserialization.
24    #[error("YAML error: {0}")]
25    Yaml(#[from] serde_yaml::Error),
26
27    /// Error during CSV parsing.
28    #[error("CSV error: {0}")]
29    Csv(#[from] csv::Error),
30
31    /// Error during Parquet operations.
32    #[error("Parquet error: {0}")]
33    Parquet(#[from] parquet::errors::ParquetError),
34
35    /// Error during Arrow operations.
36    #[error("Arrow error: {0}")]
37    Arrow(#[from] arrow::error::ArrowError),
38
39    /// Invalid fingerprint format.
40    #[error("Invalid fingerprint format: {0}")]
41    InvalidFormat(String),
42
43    /// Missing required component in fingerprint.
44    #[error("Missing required component: {0}")]
45    MissingComponent(String),
46
47    /// Checksum mismatch.
48    #[error("Checksum mismatch for {file}: expected {expected}, got {actual}")]
49    ChecksumMismatch {
50        file: String,
51        expected: String,
52        actual: String,
53    },
54
55    /// Version mismatch.
56    #[error("Unsupported fingerprint version: {0}")]
57    UnsupportedVersion(String),
58
59    /// Privacy budget exhausted.
60    #[error("Privacy budget exhausted: epsilon={spent}, limit={limit}")]
61    PrivacyBudgetExhausted { spent: f64, limit: f64 },
62
63    /// Insufficient data for extraction.
64    #[error("Insufficient data: need at least {required} rows, got {actual}")]
65    InsufficientData { required: usize, actual: usize },
66
67    /// Statistical computation error.
68    #[error("Statistical error: {0}")]
69    StatisticalError(String),
70
71    /// Data validation error.
72    #[error("Validation error: {0}")]
73    ValidationError(String),
74
75    /// Configuration synthesis error.
76    #[error("Config synthesis error: {0}")]
77    SynthesisError(String),
78
79    /// Extraction error.
80    #[error("Extraction error in {extractor}: {message}")]
81    ExtractionError { extractor: String, message: String },
82
83    /// Privacy constraint violation.
84    #[error("Privacy constraint violated: {0}")]
85    PrivacyViolation(String),
86
87    /// Matrix operation error.
88    #[error("Matrix operation error: {0}")]
89    MatrixError(String),
90
91    /// Distribution fitting error.
92    #[error("Distribution fitting error: {0}")]
93    DistributionFitError(String),
94
95    /// PII denylist load or parse error (SP6 Phase B).
96    #[error("pii denylist: {0}")]
97    PiiDenylist(String),
98}
99
100impl FingerprintError {
101    /// Create an extraction error.
102    pub fn extraction(extractor: &str, message: impl Into<String>) -> Self {
103        Self::ExtractionError {
104            extractor: extractor.to_string(),
105            message: message.into(),
106        }
107    }
108}