Skip to main content

khive_fold/objective/
error.rs

1//! Objective error types
2
3use thiserror::Error;
4
5/// Objective function error type
6#[derive(Debug, Error)]
7pub enum ObjectiveError {
8    /// No candidates to select from
9    #[error("No candidates available")]
10    NoCandidates,
11
12    /// No candidate met the selection criteria
13    #[error("No candidate met criteria: {0}")]
14    NoMatch(String),
15
16    /// Invalid objective configuration
17    #[error("Invalid configuration: {0}")]
18    InvalidConfig(String),
19
20    /// Objective not found in registry
21    #[error("Objective not found: {0}")]
22    NotFound(String),
23
24    /// Scoring error
25    #[error("Scoring error: {0}")]
26    Scoring(String),
27
28    /// Fold error
29    #[error("Fold error: {0}")]
30    Fold(#[from] crate::FoldError),
31}
32
33/// Objective result type
34pub 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}