Skip to main content

fpm_rs/
error.rs

1use thiserror::Error;
2
3pub type Result<T> = std::result::Result<T, Error>;
4
5#[derive(Debug, Error)]
6pub enum Error {
7    #[error("invalid shape: {0}")]
8    InvalidShape(String),
9    #[error("invalid parameter `{name}`: {reason}")]
10    InvalidParameter { name: &'static str, reason: String },
11    #[error("model validation failed: {0}")]
12    InvalidModel(String),
13    #[error("measurement validation failed: {0}")]
14    InvalidMeasurements(String),
15    #[error("array length {actual} does not match shape {shape:?} (expected {expected})")]
16    LengthMismatch {
17        actual: usize,
18        expected: usize,
19        shape: (usize, usize),
20    },
21    #[error("frame index {index} is out of range for {frames} frames")]
22    FrameOutOfRange { index: usize, frames: usize },
23    #[error("numerical error: {0}")]
24    Numerical(String),
25    #[error("unsupported operation: {0}")]
26    Unsupported(String),
27    #[error("dataset error: {0}")]
28    Dataset(String),
29    #[error("I/O error: {0}")]
30    Io(#[from] std::io::Error),
31    #[error("CSV error: {0}")]
32    Csv(#[from] csv::Error),
33    #[error("image error: {0}")]
34    Image(#[from] image::ImageError),
35    #[error("TIFF error: {0}")]
36    Tiff(#[from] tiff::TiffError),
37    #[error("serialization error: {0}")]
38    Serialization(#[from] serde_json::Error),
39}