swink_agent_eval/
error.rs1#[derive(Debug, thiserror::Error)]
5pub enum EvalError {
6 #[error("agent error during evaluation")]
8 Agent {
9 #[source]
10 source: swink_agent::AgentError,
11 },
12
13 #[error("eval case not found: {id}")]
15 CaseNotFound { id: String },
16
17 #[error("eval set not found: {id}")]
19 SetNotFound { id: String },
20
21 #[error("eval result not found: {eval_set_id}/{timestamp}")]
23 ResultNotFound { eval_set_id: String, timestamp: u64 },
24
25 #[error("invalid eval case: {reason}")]
27 InvalidCase { reason: String },
28
29 #[error("duplicate evaluator registration: {name}")]
31 DuplicateEvaluator { name: String },
32
33 #[error("invalid {kind} identifier: {id}")]
35 InvalidIdentifier { kind: &'static str, id: String },
36
37 #[error("io error")]
39 Io {
40 #[source]
41 source: std::io::Error,
42 },
43
44 #[error("serialization error")]
46 Serde {
47 #[source]
48 source: serde_json::Error,
49 },
50
51 #[cfg(feature = "yaml")]
53 #[error("yaml error")]
54 Yaml {
55 #[source]
56 source: serde_yaml::Error,
57 },
58}
59
60impl EvalError {
61 pub const fn agent(source: swink_agent::AgentError) -> Self {
63 Self::Agent { source }
64 }
65
66 pub fn invalid_case(reason: impl Into<String>) -> Self {
68 Self::InvalidCase {
69 reason: reason.into(),
70 }
71 }
72
73 pub fn duplicate_evaluator(name: impl Into<String>) -> Self {
75 Self::DuplicateEvaluator { name: name.into() }
76 }
77
78 pub fn invalid_identifier(kind: &'static str, id: impl Into<String>) -> Self {
80 Self::InvalidIdentifier {
81 kind,
82 id: id.into(),
83 }
84 }
85}
86
87impl From<std::io::Error> for EvalError {
88 fn from(source: std::io::Error) -> Self {
89 Self::Io { source }
90 }
91}
92
93impl From<serde_json::Error> for EvalError {
94 fn from(source: serde_json::Error) -> Self {
95 Self::Serde { source }
96 }
97}
98
99impl From<swink_agent::AgentError> for EvalError {
100 fn from(source: swink_agent::AgentError) -> Self {
101 Self::Agent { source }
102 }
103}
104
105#[cfg(feature = "yaml")]
106impl From<serde_yaml::Error> for EvalError {
107 fn from(source: serde_yaml::Error) -> Self {
108 Self::Yaml { source }
109 }
110}