1use std::fmt;
2
3use crate::MolRsError;
4
5#[derive(Debug)]
7pub enum ComputeError {
8 MissingBlock { name: &'static str },
10
11 MissingColumn {
13 block: &'static str,
14 col: &'static str,
15 },
16
17 MissingSimBox,
19
20 DimensionMismatch { expected: usize, got: usize },
22
23 NoFrames,
25
26 MolRs(MolRsError),
28}
29
30impl fmt::Display for ComputeError {
31 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
32 match self {
33 Self::MissingBlock { name } => {
34 write!(f, "missing block '{name}' in Frame")
35 }
36 Self::MissingColumn { block, col } => {
37 write!(f, "missing column '{col}' in block '{block}'")
38 }
39 Self::MissingSimBox => write!(f, "Frame has no SimBox"),
40 Self::DimensionMismatch { expected, got } => {
41 write!(f, "dimension mismatch: expected {expected}, got {got}")
42 }
43 Self::NoFrames => write!(f, "no frames have been fed to the reducer"),
44 Self::MolRs(e) => write!(f, "{e}"),
45 }
46 }
47}
48
49impl std::error::Error for ComputeError {
50 fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
51 match self {
52 Self::MolRs(e) => Some(e),
53 _ => None,
54 }
55 }
56}
57
58impl From<MolRsError> for ComputeError {
59 fn from(err: MolRsError) -> Self {
60 Self::MolRs(err)
61 }
62}