1
2
3
4
5
6
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
// src/error.rs
use std::fmt;
/// Result type alias used throughout the sanos crate.
pub type SanosResult<T> = Result<T, SanosError>;
#[derive(Debug, Clone)]
pub enum SanosError {
/// A floating-point input is NaN or infinite.
NonFinite {
field: &'static str,
value: f64,
},
/// A value violates inclusive bounds [min, max].
InvalidBound {
field: &'static str,
value: f64,
min: f64,
max: f64,
},
/// A monotonicity or ordering constraint is violated.
InvalidOrdering {
msg: &'static str,
},
/// A required collection is empty.
EmptyCollection {
what: &'static str,
},
/// A duplicate key/value was detected where uniqueness is required.
DuplicateKey {
what: &'static str,
value: f64,
},
/// ATM mid-price could not be computed for a given maturity.
AtmNotComputable {
maturity: f64,
reason: &'static str,
},
/// Feature / component not implemented yet.
NotImplemented {
what: &'static str,
},
/// Error coming from an external backend (solver, etc.)
External {
msg: String,
},
}
impl fmt::Display for SanosError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
SanosError::NonFinite { field, value } => {
write!(f, "Non-finite value for {field}: {value}")
}
SanosError::InvalidBound { field, value, min, max } => {
write!(f, "Invalid {field}: {value} not in [{min}, {max}]")
}
SanosError::InvalidOrdering { msg } => {
write!(f, "Invalid ordering: {msg}")
}
SanosError::EmptyCollection { what } => {
write!(f, "Empty collection: {what}")
}
SanosError::DuplicateKey { what, value } => {
write!(f, "Duplicate {what}: {value}")
}
SanosError::AtmNotComputable { maturity, reason } => {
write!(f, "ATM mid not computable for maturity {maturity}: {reason}")
}
SanosError::NotImplemented { what } => {
write!(f, "Not implemented: {what}")
}
SanosError::External { msg } => {
write!(f, "External error: {msg}")
}
}
}
}
impl std::error::Error for SanosError {}