Skip to main content

klieo_flows/
error.rs

1//! Errors raised by `klieo-flows`.
2
3use thiserror::Error;
4
5/// Errors returned by [`crate::flow::Flow::run`] and its concrete impls.
6#[derive(Debug, Error)]
7#[non_exhaustive]
8pub enum FlowError {
9    /// An underlying [`klieo_core::Agent`] returned an error. Stringly
10    /// typed because `Agent::Error` is associated and not erasable.
11    #[error("agent error: {0}")]
12    Agent(String),
13
14    /// Marshalling between typed I/O and `serde_json::Value` failed.
15    #[error("json marshalling: {0}")]
16    Json(#[from] serde_json::Error),
17
18    /// [`crate::loop_flow::LoopFlow`] exceeded `max_iters` or its predicate
19    /// returned `LoopVerdict::Failed`.
20    #[error("loop terminated: {reason} (iter {iter})")]
21    Loop {
22        /// Human-readable reason.
23        reason: String,
24        /// Iteration count at termination.
25        iter: u32,
26    },
27
28    /// [`crate::graph::GraphFlow`] hit a cycle, missing node, or missing edge.
29    #[error("graph error: {0}")]
30    Graph(String),
31
32    /// Underlying bus surfaced a transient failure during a flow.
33    #[error("bus error: {0}")]
34    Bus(#[from] klieo_core::error::BusError),
35
36    /// A [`crate::flow::Flow`] dispatched a tool via
37    /// [`klieo_core::tool::ToolInvoker`] and the invocation itself failed.
38    /// Typed (rather than stringified) so callers can match
39    /// [`klieo_core::error::ToolError::Cancelled`] /
40    /// [`klieo_core::error::ToolError::Retryable`] and keep the source
41    /// chain intact.
42    #[error("tool error: {0}")]
43    Tool(#[from] klieo_core::error::ToolError),
44
45    /// The flow observed [`AgentContext::cancel`](klieo_core::agent::AgentContext)
46    /// before starting an iteration / step and stopped without doing further
47    /// work. Distinct from a body agent's own error so callers can tell a
48    /// cooperative cancellation apart from a failure.
49    #[error("flow cancelled")]
50    Cancelled,
51}