Skip to main content

rustpix_core/
error.rs

1//! Error types for rustpix.
2
3use thiserror::Error;
4
5/// Errors during clustering operations.
6#[derive(Error, Debug)]
7pub enum ClusteringError {
8    /// No hits provided for clustering.
9    #[error("empty input: cannot cluster zero hits")]
10    EmptyInput,
11
12    /// Invalid clustering configuration.
13    #[error("invalid configuration: {0}")]
14    InvalidConfig(String),
15
16    /// Internal state error while clustering.
17    #[error("state error: {0}")]
18    StateError(String),
19}
20
21/// Errors during extraction operations.
22#[derive(Error, Debug)]
23pub enum ExtractionError {
24    /// Cluster is empty when extraction is attempted.
25    #[error("empty cluster: cannot extract from zero hits")]
26    EmptyCluster,
27
28    /// Invalid extraction configuration.
29    #[error("invalid configuration: {0}")]
30    InvalidConfig(String),
31}
32
33/// Errors during I/O operations.
34#[derive(Error, Debug)]
35pub enum IoError {
36    /// File path does not exist.
37    #[error("file not found: {0}")]
38    FileNotFound(String),
39
40    /// File data did not match expected format.
41    #[error("invalid file format: {0}")]
42    InvalidFormat(String),
43
44    /// Memory-mapped file failed to initialize.
45    #[error("memory mapping failed: {0}")]
46    MmapError(String),
47
48    /// Underlying I/O error.
49    #[error("I/O error: {0}")]
50    Io(#[from] std::io::Error),
51}
52
53/// Errors during TPX3 processing.
54#[derive(Error, Debug)]
55pub enum ProcessingError {
56    /// Underlying I/O error during processing.
57    #[error("I/O error: {0}")]
58    Io(#[from] IoError),
59
60    /// Packet failed validation.
61    #[error("invalid packet at offset {offset}: {message}")]
62    InvalidPacket {
63        /// Byte offset where the invalid packet was detected.
64        offset: usize,
65        /// Validation error description.
66        message: String,
67    },
68
69    /// TDC reference missing for a data section.
70    #[error("missing TDC reference for section starting at offset {0}")]
71    MissingTdc(usize),
72
73    /// Invalid or inconsistent processing configuration.
74    #[error("configuration error: {0}")]
75    Config(String),
76}
77
78/// Combined error type for the library.
79#[derive(Error, Debug)]
80pub enum Error {
81    /// Error from clustering stage.
82    #[error("clustering error: {0}")]
83    Clustering(#[from] ClusteringError),
84
85    /// Error from extraction stage.
86    #[error("extraction error: {0}")]
87    Extraction(#[from] ExtractionError),
88
89    /// Error from I/O operations.
90    #[error("I/O error: {0}")]
91    Io(#[from] IoError),
92
93    /// Error from TPX3 processing pipeline.
94    #[error("processing error: {0}")]
95    Processing(#[from] ProcessingError),
96}
97
98/// Result type alias using the combined Error.
99pub type Result<T> = std::result::Result<T, Error>;