Skip to main content

koth_ms/
error.rs

1use thiserror::Error;
2
3#[derive(Error, Debug)]
4pub enum KothError {
5    #[error("IO error: {0}")]
6    Io(#[from] std::io::Error),
7
8    #[error("Unsupported input format: {0}")]
9    UnsupportedFormat(String),
10
11    #[error("mzML parse error: {0}")]
12    MzmlError(String),
13
14    #[cfg(feature = "tdf")]
15    #[error("Bruker TDF error: {0}")]
16    TdfError(String),
17
18    // Ungated: the `thermo` feature does not enable `tdf`, so the Thermo reader
19    // needs an error variant that exists in a thermo-only build.
20    #[error("Thermo .raw error: {0}")]
21    ThermoError(String),
22
23    #[error("CSV write error: {0}")]
24    CsvError(#[from] csv::Error),
25
26    #[error("JSON error: {0}")]
27    JsonError(#[from] serde_json::Error),
28
29    #[error("Config error: {0}")]
30    ConfigError(String),
31
32    #[error("No spectra found in input file")]
33    NoSpectra,
34
35    #[error("Parquet error: {0}")]
36    ParquetError(String),
37}
38
39/// `koth-core` errors convert one-to-one: its `Io` becomes [`KothError::Io`] and
40/// its `Config` becomes [`KothError::ConfigError`], with the same message.
41impl From<koth_core::Error> for KothError {
42    fn from(e: koth_core::Error) -> Self {
43        match e {
44            koth_core::Error::Io(e) => KothError::Io(e),
45            koth_core::Error::Config(msg) => KothError::ConfigError(msg),
46            other => KothError::ConfigError(other.to_string()),
47        }
48    }
49}