#[derive(Debug, thiserror::Error)]
pub enum EvalError {
#[error("agent error during evaluation")]
Agent {
#[source]
source: swink_agent::AgentError,
},
#[error("eval case not found: {id}")]
CaseNotFound { id: String },
#[error("eval set not found: {id}")]
SetNotFound { id: String },
#[error("eval result not found: {eval_set_id}/{timestamp}")]
ResultNotFound { eval_set_id: String, timestamp: u64 },
#[error("invalid eval case: {reason}")]
InvalidCase { reason: String },
#[error("duplicate evaluator registration: {name}")]
DuplicateEvaluator { name: String },
#[error("invalid {kind} identifier: {id}")]
InvalidIdentifier { kind: &'static str, id: String },
#[error("io error")]
Io {
#[source]
source: std::io::Error,
},
#[error("serialization error")]
Serde {
#[source]
source: serde_json::Error,
},
#[cfg(feature = "yaml")]
#[error("yaml error")]
Yaml {
#[source]
source: serde_yaml::Error,
},
}
impl EvalError {
pub const fn agent(source: swink_agent::AgentError) -> Self {
Self::Agent { source }
}
pub fn invalid_case(reason: impl Into<String>) -> Self {
Self::InvalidCase {
reason: reason.into(),
}
}
pub fn duplicate_evaluator(name: impl Into<String>) -> Self {
Self::DuplicateEvaluator { name: name.into() }
}
pub fn invalid_identifier(kind: &'static str, id: impl Into<String>) -> Self {
Self::InvalidIdentifier {
kind,
id: id.into(),
}
}
}
impl From<std::io::Error> for EvalError {
fn from(source: std::io::Error) -> Self {
Self::Io { source }
}
}
impl From<serde_json::Error> for EvalError {
fn from(source: serde_json::Error) -> Self {
Self::Serde { source }
}
}
impl From<swink_agent::AgentError> for EvalError {
fn from(source: swink_agent::AgentError) -> Self {
Self::Agent { source }
}
}
#[cfg(feature = "yaml")]
impl From<serde_yaml::Error> for EvalError {
fn from(source: serde_yaml::Error) -> Self {
Self::Yaml { source }
}
}