Newer
Older
//! Opossum specfic error structures
use std::{error::Error, fmt::Display};
/// Opossum application specific Result type
pub type OpmResult<T> = std::result::Result<T, OpossumError>;
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/// Errors that can be returned by various OPOSSUM functions.
#[derive(Debug, Clone)]
pub enum OpossumError {
/// error while setting up an `OpticScenery`
OpticScenery(String),
/// error while setting up an `OpticGroup`. The reasons are similar to [`OpossumError::OpticScenery`]
OpticGroup(String),
/// (mostly internal) errors while dealing with optical ports.
OpticPort(String),
/// mostly runtime errors occuring during the analysis of a scenery
Analysis(String),
/// errors while handling optical spectra
Spectrum(String),
/// errors console io
Console(String),
/// errors not falling in one of the categories above
Other(String),
}
impl Display for OpossumError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
OpossumError::OpticScenery(m) => {
write!(f, "Opossum Error::OpticScenery::{}", m)
}
OpossumError::OpticGroup(m) => {
write!(f, "Opossum Error::OpticGroup::{}", m)
}
OpossumError::OpticPort(m) => {
write!(f, "Opossum Error::OpticPort::{}", m)
}
OpossumError::Analysis(m) => {
write!(f, "Opossum Error::Analysis::{}", m)
}
OpossumError::Spectrum(m) => {
write!(f, "Opossum Spectrum::{}", m)
}
OpossumError::Console(m) => {
write!(f, "Opossum Console::{}", m)
}
OpossumError::Other(m) => write!(f, "Opossum Error::Other::{}", m),
}
}
}
impl Error for OpossumError {}
impl std::convert::From<String> for OpossumError {
fn from(msg: String) -> Self {
Self::Other(msg)
}
}