naluacq/
error.rs

1/// Errors used when accessing an [`Acquisition`](crate::acquisition::Acquisition).
2#[derive(thiserror::Error, Debug, Clone)]
3pub enum AcquisitionError {
4    /// An acquisition could not be read from/written to the given path
5    #[error("invalid path")]
6    InvalidPath,
7    /// The acquisition could not be created because it already exists.
8    #[error("already exists")]
9    AlreadyExists,
10    /// Failed to create the acquisition
11    #[error("cannot create acquisition")]
12    CreationError,
13    /// Failed to access some portion of the acquisition
14    #[error("cannot access some portion of the acquisition")]
15    AccessError(String),
16    /// Attempted to access an event at an index which is out of bounds.
17    #[error("bad event index")]
18    IndexOutOfBounds,
19    /// Could not write an event to the chunk because it is full.
20    #[error("chunk is full")]
21    FullChunk,
22    /// Failed to write data to the chunk.
23    #[error("failed to write data")]
24    WriteError,
25    /// An event was written before the metadata.
26    #[error("metadata must be written before events")]
27    MetadataMissing,
28    /// Metadata was already written.
29    #[error("cannot write metadata twice")]
30    MetadataAlreadyWritten,
31    /// The metadata is in an invalid structure.
32    #[error("invalid metadata")]
33    InvalidMetadata,
34    /// Calibration type does not exist
35    #[error("invalid calibration type")]
36    NoSuchMiscData,
37    /// Unknown error
38    #[error("unknown")]
39    Unknown,
40}
41
42/// Errors used when metadata access fails
43#[derive(thiserror::Error, Debug)]
44pub enum MetadataError {
45    #[error("invalid metadata format")]
46    InvalidFormat,
47    #[error("invalid metadata format")]
48    InvalidName,
49    #[error("failed to serialized")]
50    SerializationError(#[from] serde_yaml::Error),
51}
52
53/// Errors used when parsing events.
54#[derive(Debug, thiserror::Error)]
55pub enum ParsingError {
56    #[error("provided parameters are invalid")]
57    InvalidParameters,
58    #[error("unexpected length of data")]
59    UnexpectedLength,
60    #[error("invalid channel number")]
61    InvalidChannel,
62    #[error("invalid window label")]
63    InvalidWindow,
64    #[error("required data missing when parsing")]
65    MissingData,
66    #[error("Encountered an empty Package which can't be parsed")]
67    PackageEmpty,
68    #[error("data is from an unsupported board model")]
69    UnsupportedModel,
70    #[error("unknown")]
71    Other,
72}
73
74/// Errors used when exporting data.
75#[derive(Debug, thiserror::Error)]
76pub enum ExportError {
77    #[error("invalid path")]
78    InvalidPath,
79    #[error("file access was denied")]
80    AccessDenied,
81    #[error("invalid format")]
82    InvalidFormat,
83    #[error("specified options are invalid for the data being exported")]
84    InvalidOptions,
85    #[error("error occurred while exporting as csv")]
86    CsvError(#[from] csv::Error),
87    #[error("error occurred while parsing")]
88    ParsingError(#[from] ParsingError),
89    #[error("error occurred while accessing acquisition")]
90    MetadataError(#[from] MetadataError),
91    #[error("unknown")]
92    Unknown,
93}
94
95impl From<std::io::Error> for ExportError {
96    fn from(e: std::io::Error) -> Self {
97        match e {
98            e if e.kind() == std::io::ErrorKind::NotFound => Self::InvalidPath,
99            e if e.kind() == std::io::ErrorKind::PermissionDenied => Self::AccessDenied,
100            _ => ExportError::Unknown,
101        }
102    }
103}
104
105/// Errors used when accessing miscellaneous data fails.
106#[derive(Debug, thiserror::Error)]
107pub enum MiscDataError {
108    #[error("invalid path")]
109    InvalidPath,
110    #[error("file access was denied")]
111    AccessDenied,
112    #[error("the misc data is invalid")]
113    InvalidMiscData,
114    #[error("serialization or deserialization failed")]
115    SerializationError(#[from] serde_pickle::Error),
116    #[error("unknown")]
117    Unknown,
118}
119
120impl From<std::io::Error> for MiscDataError {
121    fn from(e: std::io::Error) -> Self {
122        match e {
123            e if e.kind() == std::io::ErrorKind::NotFound => Self::InvalidPath,
124            e if e.kind() == std::io::ErrorKind::PermissionDenied => Self::AccessDenied,
125            e if e.kind() == std::io::ErrorKind::InvalidData => Self::InvalidMiscData,
126            e if e.kind() == std::io::ErrorKind::UnexpectedEof => Self::InvalidMiscData,
127            _ => MiscDataError::Unknown,
128        }
129    }
130}
131
132/// Errors used when accessing correcting events fails.
133#[derive(Debug, thiserror::Error)]
134pub enum CalibrationError {
135    #[error("pedestals correction failed")]
136    PedestalsCorrectionFailed,
137    #[error("invalid data shape")]
138    InvalidDataShape,
139}