khive_fold/objective/
error.rs1use thiserror::Error;
4
5#[derive(Debug, Error)]
7pub enum ObjectiveError {
8 #[error("No candidates available")]
10 NoCandidates,
11
12 #[error("No candidate met criteria: {0}")]
14 NoMatch(String),
15
16 #[error("Invalid configuration: {0}")]
18 InvalidConfig(String),
19
20 #[error("Objective not found: {0}")]
22 NotFound(String),
23
24 #[error("Scoring error: {0}")]
26 Scoring(String),
27
28 #[error("Fold error: {0}")]
30 Fold(#[from] crate::FoldError),
31}
32
33pub type ObjectiveResult<T> = Result<T, ObjectiveError>;
35
36#[cfg(test)]
37mod tests {
38 use super::*;
39
40 #[test]
41 fn test_no_candidates_display() {
42 let err = ObjectiveError::NoCandidates;
43 assert_eq!(err.to_string(), "No candidates available");
44 }
45
46 #[test]
47 fn test_no_match_display() {
48 let err = ObjectiveError::NoMatch("score < 0.5".into());
49 assert!(err.to_string().contains("score < 0.5"));
50 }
51
52 #[test]
53 fn test_invalid_config_display() {
54 let err = ObjectiveError::InvalidConfig("missing weight".into());
55 assert!(err.to_string().contains("missing weight"));
56 }
57
58 #[test]
59 fn test_not_found_display() {
60 let err = ObjectiveError::NotFound("relevance_v1".into());
61 assert!(err.to_string().contains("relevance_v1"));
62 }
63
64 #[test]
65 fn test_scoring_display() {
66 let err = ObjectiveError::Scoring("NaN result".into());
67 assert!(err.to_string().contains("NaN result"));
68 }
69}