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
48impl From<adk_core::AdkError> for EvalError {
49    fn from(err: adk_core::AdkError) -> Self {
50        EvalError::AgentError(err.to_string())
51    }
52}
53
54impl From<EvalError> for adk_core::AdkError {
55    fn from(err: EvalError) -> Self {
56        use adk_core::{ErrorCategory, ErrorComponent};
57        let (category, code) = match &err {
58            EvalError::LoadError(_) => (ErrorCategory::NotFound, "eval.load"),
59            EvalError::ParseError(_) => (ErrorCategory::InvalidInput, "eval.parse"),
60            EvalError::ExecutionError(_) => (ErrorCategory::Internal, "eval.execution"),
61            EvalError::AgentError(_) => (ErrorCategory::Internal, "eval.agent"),
62            EvalError::ConfigError(_) => (ErrorCategory::InvalidInput, "eval.config"),
63            EvalError::IoError(_) => (ErrorCategory::Internal, "eval.io"),
64            EvalError::JsonError(_) => (ErrorCategory::Internal, "eval.json"),
65            EvalError::ScoringError(_) => (ErrorCategory::Internal, "eval.scoring"),
66            EvalError::JudgeError(_) => (ErrorCategory::Internal, "eval.judge"),
67        };
68        adk_core::AdkError::new(ErrorComponent::Eval, category, code, err.to_string())
69            .with_source(err)
70    }
71}