Skip to main content

nereids_io/
error.rs

1//! Error types for the nereids-io crate.
2
3/// Errors that can occur during I/O operations.
4#[derive(Debug, thiserror::Error)]
5#[non_exhaustive]
6pub enum IoError {
7    /// File not found or could not be opened.
8    #[error("File not found: {0}: {1}")]
9    FileNotFound(String, #[source] std::io::Error),
10
11    /// Path is not a directory.
12    #[error("Not a directory: {0}")]
13    NotADirectory(String),
14
15    /// TIFF decoding error.
16    #[error("TIFF decode error: {0}")]
17    TiffDecode(String),
18
19    /// Frame dimensions do not match.
20    #[error("Dimension mismatch at frame {frame}: expected ({ew}×{eh}), got ({gw}×{gh})",
21        ew = expected.0, eh = expected.1, gw = got.0, gh = got.1)]
22    DimensionMismatch {
23        expected: (u32, u32),
24        got: (u32, u32),
25        frame: usize,
26    },
27
28    /// Array shape error.
29    #[error("Shape mismatch: {0}")]
30    ShapeMismatch(String),
31
32    /// No files matched the given pattern.
33    #[error("No files matching pattern '{pattern}' in directory: {directory}")]
34    NoMatchingFiles { directory: String, pattern: String },
35
36    /// Invalid parameter.
37    #[error("Invalid parameter: {0}")]
38    InvalidParameter(String),
39
40    /// TIFF encoding/writing error.
41    #[error("TIFF encode error: {0}")]
42    TiffEncode(String),
43
44    /// Generic file write error (not TIFF-specific).
45    #[error("Write error: {0}")]
46    WriteError(String),
47
48    /// HDF5 format or access error.
49    #[error("HDF5 error: {0}")]
50    Hdf5Error(String),
51
52    /// Chunked TIFF folder is internally inconsistent (ragged chunks or
53    /// duplicate (chunk, frame) pairs).  Summing across inconsistent chunks
54    /// would silently corrupt counts, so this is a hard error — never a
55    /// partial sum, never a silent fallback to plain stacking.
56    #[error("Inconsistent DAQ chunks in directory {directory}: {details}")]
57    ChunkMismatch { directory: String, details: String },
58
59    /// A pixel value violates the raw-counts invariant (finite and >= 0).
60    #[error(
61        "Bad pixel value {value} at flat index {index} of frame {frame} in '{file}': \
62         raw counts must be finite and >= 0. For corrupt readout pixels, mask them \
63         per acquisition with detect_bad_pixels(); to clamp negative values to zero \
64         use the clip pixel policy (PixelValuePolicy::ClipToZero); for pre-normalized \
65         transmission data use the allow policy (PixelValuePolicy::Allow)."
66    )]
67    BadPixelValue {
68        file: String,
69        frame: usize,
70        index: usize,
71        value: f64,
72    },
73}