1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
#[cfg(feature = "python")]
use pyo3;
use regex;
use thiserror::Error;

#[derive(Error, Debug)]
pub enum EstimatorErr {
    #[error("Invalid paramer: `{0}`")]
    InvalidParams(String),
    #[error("Invalid regex parameter")]
    RegexErr {
        #[from]
        source: regex::Error,
    },
}

#[cfg(feature = "python")]
impl From<EstimatorErr> for pyo3::PyErr {
    fn from(err: EstimatorErr) -> pyo3::PyErr {
        pyo3::PyErr::new::<pyo3::exceptions::ValueError, _>(format!("{}", err))
    }
}