eval_metrics/error.rs
1//!
2//! Details evaluation error types
3//!
4
5///
6/// Represents a generic evaluation error
7///
8#[derive(Clone, Debug)]
9pub struct EvalError {
10 /// The error message
11 pub msg: String
12}
13
14impl EvalError {
15
16 ///
17 /// Alerts than an invalid input was provided
18 ///
19 /// # Arguments
20 ///
21 /// * `msg` - detailed error message
22 ///
23 pub fn invalid_input(msg: &str) -> EvalError {
24 EvalError {msg: format!("Invalid input: {}", msg)}
25 }
26
27 ///
28 /// Alerts that an undefined metric was encountered
29 ///
30 /// # Arguments
31 ///
32 /// * `name` - metric name
33 ///
34 pub fn undefined_metric(name: &str) -> EvalError {
35 EvalError {msg: format!("Undefined metric: {}", name)}
36 }
37
38 ///
39 /// Alerts than an infinite/NaN value was encountered
40 ///
41 pub fn infinite_value() -> EvalError {
42 EvalError {msg: String::from("Infinite or NaN value")}
43 }
44
45 ///
46 /// Alerts that constant input data was encountered
47 ///
48 pub fn constant_input_data() -> EvalError {
49 EvalError {msg: String::from("Constant input data")}
50 }
51
52 ///
53 /// Alerts than an invalid metric was provided
54 ///
55 /// # Arguments
56 ///
57 /// * `name` - metric name
58 ///
59 pub fn invalid_metric(name: &str) -> EvalError {
60 EvalError {msg: format!("Invalid metric: {}", name)}
61 }
62}
63
64impl std::fmt::Display for EvalError {
65 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
66 write!(f, "{}", self.msg)
67 }
68}
69
70impl std::error::Error for EvalError {}