scouter_profile/profile/
error.rs1use ndarray::Axis;
2use pyo3::exceptions::PyRuntimeError;
3use pyo3::PyErr;
4use scouter_types::error::ProfileError;
5use thiserror::Error;
6
7#[derive(Error, Debug)]
8pub enum QuantileError {
9 #[error("Failed to compute quantile {quantile} for axis {axis:?}")]
10 ComputeError {
11 quantile: f64,
12 axis: Axis,
13 source: Box<dyn std::error::Error + Send + Sync>,
14 },
15}
16
17#[derive(Error, Debug)]
18pub enum DataProfileError {
19 #[error("Failed to parse JSON")]
20 JsonParseError(#[from] serde_json::Error),
21
22 #[error("Failed to calculate mean")]
23 MeanError,
24
25 #[error(transparent)]
26 MinMaxError(#[from] ndarray_stats::errors::MinMaxError),
27
28 #[error("Failed to get max bin")]
29 MaxBinError,
30
31 #[error(transparent)]
32 ProfileError(#[from] ProfileError),
33
34 #[error(transparent)]
35 ShapeError(#[from] ndarray::ShapeError),
36
37 #[error(transparent)]
38 TypeError(#[from] scouter_types::error::TypeError),
39
40 #[error("{0}")]
41 PyError(String),
42
43 #[error("{0}")]
44 RuntimeError(String),
45
46 #[error("Failed to compute quantile {0}")]
47 Quantile(QuantileError),
48
49 #[error("Failed to compute quantile error")]
50 ComputeQuantileError,
51
52 #[error(transparent)]
53 QuantileError(#[from] ndarray_stats::errors::QuantileError),
54}
55
56impl From<DataProfileError> for PyErr {
57 fn from(err: DataProfileError) -> PyErr {
58 let msg = err.to_string();
59 PyRuntimeError::new_err(msg)
60 }
61}
62
63impl From<PyErr> for DataProfileError {
64 fn from(err: PyErr) -> DataProfileError {
65 DataProfileError::PyError(err.to_string())
66 }
67}