1use thiserror::Error;
2
3#[derive(Error, Debug, Clone, PartialEq)]
8pub enum SvdLibError {
9 #[error("invalid argument: {0}")]
11 InvalidArgument(String),
12
13 #[error("shape mismatch: {0}")]
15 ShapeMismatch(String),
16
17 #[error("{stage}: no convergence after {iterations} iterations")]
22 NoConvergence {
23 stage: &'static str,
24 iterations: usize,
25 },
26
27 #[error("{stage}: {message}")]
29 Failed {
30 stage: &'static str,
31 message: String,
32 },
33
34 #[error("dense {factorization} failed: {message}")]
36 DenseFactorization {
37 factorization: &'static str,
38 message: String,
39 },
40
41 #[error("ndarray shape error: {0}")]
42 Shape(String),
43}
44
45impl From<ndarray::ShapeError> for SvdLibError {
46 fn from(e: ndarray::ShapeError) -> Self {
47 SvdLibError::Shape(e.to_string())
48 }
49}
50
51impl SvdLibError {
52 pub(crate) fn invalid(msg: impl Into<String>) -> Self {
53 SvdLibError::InvalidArgument(msg.into())
54 }
55
56 pub(crate) fn failed(stage: &'static str, msg: impl Into<String>) -> Self {
57 SvdLibError::Failed {
58 stage,
59 message: msg.into(),
60 }
61 }
62
63 pub(crate) fn shape(msg: impl Into<String>) -> Self {
64 SvdLibError::ShapeMismatch(msg.into())
65 }
66}
67
68pub type Result<T> = std::result::Result<T, SvdLibError>;