Skip to main content

nereids_pipeline/
error.rs

1//! Error types for the nereids-pipeline crate.
2
3use nereids_fitting::error::FittingError;
4use nereids_physics::flight_time_grid::FlightTimeGridError;
5use nereids_physics::transmission::TransmissionError;
6
7/// Errors that can occur during pipeline operations.
8#[derive(Debug, thiserror::Error)]
9pub enum PipelineError {
10    /// Array shape or length mismatch between inputs.
11    #[error("Shape mismatch: {0}")]
12    ShapeMismatch(String),
13
14    /// Invalid parameter value.
15    #[error("Invalid parameter: {0}")]
16    InvalidParameter(String),
17
18    /// Operation was cancelled via the cancellation token.
19    #[error("Operation cancelled")]
20    Cancelled,
21
22    /// Error from the transmission forward model (e.g. unsorted energy grid).
23    #[error("Transmission error: {0}")]
24    Transmission(TransmissionError),
25
26    /// Error from the fitting engine (e.g. empty data, length mismatch).
27    #[error("Fitting error: {0}")]
28    Fitting(FittingError),
29
30    /// The flight-time grid refused the window or the pulse.
31    #[error("Flight-time grid: {0}")]
32    FlightTimeGrid(FlightTimeGridError),
33
34    /// The model predicts a bin negative or non-finite counts, or almost none
35    /// of the counts it holds.
36    #[error(
37        "bin {bin} of the {run} run holds {counts} counts where the model predicts {predicted}"
38    )]
39    UnmodelledCounts {
40        run: &'static str,
41        bin: usize,
42        counts: f64,
43        predicted: f64,
44    },
45}
46
47impl From<TransmissionError> for PipelineError {
48    fn from(e: TransmissionError) -> Self {
49        match e {
50            TransmissionError::Cancelled => PipelineError::Cancelled,
51            other => PipelineError::Transmission(other),
52        }
53    }
54}
55
56impl From<FittingError> for PipelineError {
57    fn from(e: FittingError) -> Self {
58        PipelineError::Fitting(e)
59    }
60}
61
62impl From<FlightTimeGridError> for PipelineError {
63    fn from(e: FlightTimeGridError) -> Self {
64        PipelineError::FlightTimeGrid(e)
65    }
66}