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, in a bin it
35    /// does not leave out, almost none of the counts it holds.
36    #[error(
37        "bin {bin} of the {run} run in region {region} holds {counts} counts where the model \
38         predicts {predicted}"
39    )]
40    UnmodelledCounts {
41        region: usize,
42        run: &'static str,
43        bin: usize,
44        counts: f64,
45        predicted: f64,
46    },
47}
48
49impl From<TransmissionError> for PipelineError {
50    fn from(e: TransmissionError) -> Self {
51        match e {
52            TransmissionError::Cancelled => PipelineError::Cancelled,
53            other => PipelineError::Transmission(other),
54        }
55    }
56}
57
58impl From<FittingError> for PipelineError {
59    fn from(e: FittingError) -> Self {
60        PipelineError::Fitting(e)
61    }
62}
63
64impl From<FlightTimeGridError> for PipelineError {
65    fn from(e: FlightTimeGridError) -> Self {
66        PipelineError::FlightTimeGrid(e)
67    }
68}