Skip to main content

hydra_engine_wds/analysis/
errors.rs

1/// Errors returned by analysis computation functions.
2#[derive(Debug)]
3pub enum AnalysisComputeError {
4    /// The simulation (or `.out` file) contains no reporting periods.
5    NoSnapshots,
6    /// Reading results from an in-memory [`crate::simulation::Simulation`] failed.
7    Session(crate::simulation::SessionError),
8    /// Reading or parsing the `.out` binary file failed.
9    OutRead(String),
10    /// The supplied input parameters are inconsistent or out of range.
11    InvalidInput(String),
12}
13
14impl std::fmt::Display for AnalysisComputeError {
15    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
16        match self {
17            Self::NoSnapshots => write!(f, "simulation has no snapshots"),
18            Self::Session(e) => write!(f, "failed to read simulation results: {e}"),
19            Self::OutRead(e) => write!(f, "failed to read output file: {e}"),
20            Self::InvalidInput(e) => write!(f, "invalid analysis input: {e}"),
21        }
22    }
23}
24
25impl std::error::Error for AnalysisComputeError {}
26
27impl From<crate::simulation::SessionError> for AnalysisComputeError {
28    fn from(value: crate::simulation::SessionError) -> Self {
29        Self::Session(value)
30    }
31}