1use pyo3::exceptions::{PyRuntimeError, PyValueError};
2use pyo3::prelude::*;
3use std::fmt;
4
5#[derive(Debug)]
6pub enum RocheError {
7 DbrentError(String),
9 LinminError(String),
11 PotminError(String),
13 ParameterError(String),
15 FaceError(String),
17 RtsafeError(String),
19 WdphasesError(String),
21}
22
23impl std::error::Error for RocheError {}
24
25impl fmt::Display for RocheError {
26 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
27 match self {
28 RocheError::DbrentError(msg) => write!(f, "{}", msg),
29 RocheError::LinminError(msg) => write!(f, "{}", msg),
30 RocheError::PotminError(msg) => write!(f, "{}", msg),
31 RocheError::ParameterError(msg) => write!(f, "{}", msg),
32 RocheError::FaceError(msg) => write!(f, "{}", msg),
33 RocheError::RtsafeError(msg) => write!(f, "{}", msg),
34 RocheError::WdphasesError(msg) => write!(f, "{}", msg),
35 }
36 }
37}
38
39impl std::convert::From<RocheError> for PyErr {
40 fn from(err: RocheError) -> PyErr {
41 match err {
42 RocheError::DbrentError(_) => PyRuntimeError::new_err(err.to_string()),
43 RocheError::LinminError(_) => PyRuntimeError::new_err(err.to_string()),
44 RocheError::PotminError(_) => PyRuntimeError::new_err(err.to_string()),
45 RocheError::ParameterError(_) => PyValueError::new_err(err.to_string()),
46 RocheError::FaceError(_) => PyRuntimeError::new_err(err.to_string()),
47 RocheError::RtsafeError(_) => PyRuntimeError::new_err(err.to_string()),
48 RocheError::WdphasesError(_) => PyRuntimeError::new_err(err.to_string()),
49 }
50 }
51}