Skip to main content

troupekit_graph/
error.rs

1use troupekit_agent::AgentError;
2use troupekit_core::error::CoreError;
3
4/// A workflow file that failed validation.
5/// Names the file, the field (dotted, such as `nodes.plan.persona` or
6/// `edges[2].when`) and what is wrong with it.
7#[derive(Debug, Clone, PartialEq, Eq, thiserror::Error)]
8#[error("{file}: {field}: {message}")]
9pub struct WorkflowError {
10    pub file: String,
11    pub field: String,
12    pub message: String,
13}
14
15impl WorkflowError {
16    /// Builds the error for `field` of `file` with `message`.
17    /// Every workflow check reports through it.
18    /// Returns the error.
19    pub fn new(file: &str, field: &str, message: impl Into<String>) -> Self {
20        Self {
21            file: file.to_string(),
22            field: field.to_string(),
23            message: message.into(),
24        }
25    }
26}
27
28/// Why parsing a workflow, building a graph run, restoring one or applying
29/// a human answer or new budget failed. Failures during a step are not
30/// errors: they end the run in its `failed` status instead.
31#[derive(Debug, Clone, PartialEq, thiserror::Error)]
32pub enum GraphError {
33    #[error(transparent)]
34    Workflow(#[from] WorkflowError),
35    #[error("setup: {0}")]
36    Setup(String),
37    #[error("checkpoint: {0}")]
38    Checkpoint(String),
39    #[error("resume: {0}")]
40    Resume(String),
41    #[error(transparent)]
42    Agent(#[from] AgentError),
43    #[error(transparent)]
44    Store(#[from] CoreError),
45}