openproteo_core/error.rs
1//! Aggregate error type for the OpenProteo stack.
2//!
3//! Each vendor crate defines its own narrow `Error` enum. When code needs to
4//! handle errors from multiple vendors uniformly - the umbrella `openproteo-io`
5//! crate, the `vendor2mzml` CLI, ProLance ingest - it converts those into
6//! [`Error`] (this aggregate). Downstream users get a single error vocabulary
7//! and `?`-propagates cleanly across vendor boundaries.
8
9use std::io;
10
11/// Stack-wide error type. Vendor errors are erased into a boxed trait object
12/// so this enum stays version-stable as vendor crates evolve.
13#[derive(Debug, thiserror::Error)]
14pub enum Error {
15 /// I/O failure (file not found, permission denied, short read, ...).
16 #[error("I/O error: {0}")]
17 Io(#[from] io::Error),
18
19 /// Vendor parser failed. The inner error is the vendor crate's own error
20 /// type, preserved via `Box<dyn std::error::Error>` so callers can
21 /// downcast if they need vendor-specific context.
22 #[error("vendor parser error: {0}")]
23 Vendor(Box<dyn std::error::Error + Send + Sync + 'static>),
24
25 /// Format detection failed or the input does not match a supported vendor.
26 #[error("unsupported or unrecognized format: {0}")]
27 Format(String),
28
29 /// Conformance harness rejected a record stream.
30 #[error("conformance violation: {0}")]
31 Conformance(String),
32}
33
34/// Convenience alias.
35pub type Result<T> = std::result::Result<T, Error>;
36
37impl Error {
38 /// Wrap a vendor-crate error into [`Error::Vendor`].
39 pub fn vendor<E>(err: E) -> Self
40 where
41 E: std::error::Error + Send + Sync + 'static,
42 {
43 Error::Vendor(Box::new(err))
44 }
45}