scouter_drift/
error.rs

1use pyo3::exceptions::PyRuntimeError;
2use pyo3::PyErr;
3use scouter_dispatch::error::DispatchError;
4use thiserror::Error;
5
6#[cfg(feature = "sql")]
7use scouter_sql::sql::error::SqlError;
8
9#[derive(Error, Debug)]
10pub enum DriftError {
11    #[error("Failed to compute mean")]
12    ComputeMeanError,
13
14    #[error("At least 10 values needed to compute deciles")]
15    NotEnoughDecileValuesError,
16
17    #[error("Failed to convert deciles to array")]
18    ConvertDecileToArray,
19
20    #[error("Failed to compute deciles")]
21    ComputeDecilesError,
22
23    #[error("{0}")]
24    RunTimeError(String),
25
26    #[error("Feature and array length mismatch")]
27    FeatureLengthError,
28
29    #[error("Feature does not exist")]
30    FeatureNotExistError,
31
32    #[error(transparent)]
33    ShapeError(#[from] ndarray::ShapeError),
34
35    #[cfg(feature = "sql")]
36    #[error(transparent)]
37    SqlError(#[from] SqlError),
38
39    #[error("SPC rule length is not 8")]
40    SpcRuleLengthError,
41
42    #[error(transparent)]
43    ParseIntError(#[from] std::num::ParseIntError),
44
45    #[error(transparent)]
46    DispatchError(#[from] DispatchError),
47
48    #[error("Failed to process alerts")]
49    ProcessAlertError,
50
51    #[error("Invalid configuration provided for drifter. Please check that the configuration type matches the drifter type")]
52    InvalidConfigError,
53
54    #[error("Not implemented")]
55    NotImplemented,
56
57    #[error("Data type not supported: {0}")]
58    UnsupportedDataTypeError(String),
59
60    #[error("Failed to downcast Python object: {0}")]
61    DowncastError(String),
62
63    #[error(transparent)]
64    ProfileError(#[from] scouter_types::error::ProfileError),
65
66    #[error("Invalid drift type")]
67    InvalidDriftType,
68
69    #[error("Error processing alert: {0}")]
70    AlertProcessingError(String),
71
72    #[error("Feature to monitor: {0}, not present in data")]
73    FeatureToMonitorMissingError(String),
74
75    #[error("Categorical feature specified in drift config: {0}, not present in data")]
76    CategoricalFeatureMissingError(String),
77}
78
79impl<'a> From<pyo3::DowncastError<'a, 'a>> for DriftError {
80    fn from(err: pyo3::DowncastError) -> Self {
81        DriftError::DowncastError(err.to_string())
82    }
83}
84
85impl From<DriftError> for PyErr {
86    fn from(err: DriftError) -> PyErr {
87        let msg = err.to_string();
88        PyRuntimeError::new_err(msg)
89    }
90}
91
92impl From<PyErr> for DriftError {
93    fn from(err: PyErr) -> DriftError {
94        DriftError::RunTimeError(err.to_string())
95    }
96}