sciforge_hub/domain/common/
errors.rs1#[derive(Debug, Clone)]
8pub enum HubError {
9 InvalidInput(String),
10 ComputationFailed(String),
11 OutOfRange {
12 name: String,
13 min: f64,
14 max: f64,
15 got: f64,
16 },
17 DimensionMismatch {
18 expected: usize,
19 got: usize,
20 },
21 NotConverged {
22 iterations: usize,
23 },
24 EmptyData,
25 Overflow,
26 Underflow,
27}
28
29impl core::fmt::Display for HubError {
30 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
31 match self {
32 Self::InvalidInput(msg) => write!(f, "invalid input: {msg}"),
33 Self::ComputationFailed(msg) => write!(f, "computation failed: {msg}"),
34 Self::OutOfRange {
35 name,
36 min,
37 max,
38 got,
39 } => write!(f, "{name} out of range [{min}, {max}]: {got}"),
40 Self::DimensionMismatch { expected, got } => {
41 write!(f, "dimension mismatch: expected {expected}, got {got}")
42 }
43 Self::NotConverged { iterations } => {
44 write!(f, "not converged after {iterations} iterations")
45 }
46 Self::EmptyData => write!(f, "empty data"),
47 Self::Overflow => write!(f, "numeric overflow"),
48 Self::Underflow => write!(f, "numeric underflow"),
49 }
50 }
51}
52
53impl std::error::Error for HubError {}
54
55pub type HubResult<T> = Result<T, HubError>;