Skip to main content

adk_eval/
error.rs

1//! Error types for the evaluation framework
2
3use thiserror::Error;
4
5/// Result type alias for evaluation operations
6pub type Result<T> = std::result::Result<T, EvalError>;
7
8/// Errors that can occur during evaluation
9#[derive(Error, Debug)]
10pub enum EvalError {
11    /// Failed to load test file
12    #[error("Failed to load test file: {0}")]
13    LoadError(String),
14
15    /// Failed to parse test file
16    #[error("Failed to parse test file: {0}")]
17    ParseError(String),
18
19    /// Test case execution failed
20    #[error("Test case execution failed: {0}")]
21    ExecutionError(String),
22
23    /// Agent error during evaluation
24    #[error("Agent error: {0}")]
25    AgentError(String),
26
27    /// Invalid configuration
28    #[error("Invalid configuration: {0}")]
29    ConfigError(String),
30
31    /// IO error
32    #[error("IO error: {0}")]
33    IoError(#[from] std::io::Error),
34
35    /// JSON serialization error
36    #[error("JSON error: {0}")]
37    JsonError(#[from] serde_json::Error),
38
39    /// Scoring error
40    #[error("Scoring error: {0}")]
41    ScoringError(String),
42
43    /// LLM judge error
44    #[error("LLM judge error: {0}")]
45    JudgeError(String),
46
47    /// Structured judge parse error
48    #[error("Structured judge parse error: {0}")]
49    JudgeParseError(String),
50
51    /// Embedding scorer error
52    #[error("Embedding scorer error: {0}")]
53    EmbeddingError(String),
54
55    /// Baseline I/O error
56    #[error("Baseline I/O error: {0}")]
57    BaselineError(String),
58
59    /// Annotation format error
60    #[error("Annotation format error: {0}")]
61    AnnotationError(String),
62
63    /// Test generation error
64    #[error("Test generation error: {0}")]
65    GenerationError(String),
66
67    /// Statistics computation error
68    #[error("Statistics computation error: {0}")]
69    StatisticsError(String),
70}
71
72impl From<adk_core::AdkError> for EvalError {
73    fn from(err: adk_core::AdkError) -> Self {
74        EvalError::AgentError(err.to_string())
75    }
76}
77
78impl From<EvalError> for adk_core::AdkError {
79    fn from(err: EvalError) -> Self {
80        use adk_core::{ErrorCategory, ErrorComponent};
81        let (category, code) = match &err {
82            EvalError::LoadError(_) => (ErrorCategory::NotFound, "eval.load"),
83            EvalError::ParseError(_) => (ErrorCategory::InvalidInput, "eval.parse"),
84            EvalError::ExecutionError(_) => (ErrorCategory::Internal, "eval.execution"),
85            EvalError::AgentError(_) => (ErrorCategory::Internal, "eval.agent"),
86            EvalError::ConfigError(_) => (ErrorCategory::InvalidInput, "eval.config"),
87            EvalError::IoError(_) => (ErrorCategory::Internal, "eval.io"),
88            EvalError::JsonError(_) => (ErrorCategory::Internal, "eval.json"),
89            EvalError::ScoringError(_) => (ErrorCategory::Internal, "eval.scoring"),
90            EvalError::JudgeError(_) => (ErrorCategory::Internal, "eval.judge"),
91            EvalError::JudgeParseError(_) => (ErrorCategory::InvalidInput, "eval.judge_parse"),
92            EvalError::EmbeddingError(_) => (ErrorCategory::Internal, "eval.embedding"),
93            EvalError::BaselineError(_) => (ErrorCategory::Internal, "eval.baseline"),
94            EvalError::AnnotationError(_) => (ErrorCategory::InvalidInput, "eval.annotation"),
95            EvalError::GenerationError(_) => (ErrorCategory::Internal, "eval.generation"),
96            EvalError::StatisticsError(_) => (ErrorCategory::Internal, "eval.statistics"),
97        };
98        adk_core::AdkError::new(ErrorComponent::Eval, category, code, err.to_string())
99            .with_source(err)
100    }
101}