Skip to main content

troupekit_agent/
error.rs

1use troupekit_core::error::CoreError;
2
3/// A persona file that failed validation.
4/// Names the file (its source label and path), the field (dotted, such as
5/// `output.cases` or `evals[1]`) and what is wrong with it.
6#[derive(Debug, Clone, PartialEq, Eq, thiserror::Error)]
7#[error("{file}: {field}: {message}")]
8pub struct PersonaError {
9    pub file: String,
10    pub field: String,
11    pub message: String,
12}
13
14impl PersonaError {
15    /// Builds the error for `field` of `file` with `message`.
16    /// Every persona check reports through it.
17    /// Returns the error.
18    pub fn new(file: &str, field: &str, message: impl Into<String>) -> Self {
19        Self {
20            file: file.to_string(),
21            field: field.to_string(),
22            message: message.into(),
23        }
24    }
25}
26
27/// Why loading a persona, building a run or resuming one failed.
28/// Run failures during a step are not errors: they end the run in its
29/// `Failed` state instead.
30#[derive(Debug, Clone, PartialEq, thiserror::Error)]
31pub enum AgentError {
32    #[error(transparent)]
33    Persona(#[from] PersonaError),
34    #[error("persona not found: {0}")]
35    NotFound(String),
36    #[error("persona source: {0}")]
37    Source(String),
38    #[error("setup: {0}")]
39    Setup(String),
40    #[error("checkpoint: {0}")]
41    Checkpoint(String),
42    #[error(transparent)]
43    Store(#[from] CoreError),
44}