fluers_core/error.rs
1//! Error types for the core crate.
2
3use thiserror::Error;
4
5/// A specialized [`Result`] for `fluers-core` operations.
6pub type Result<T> = std::result::Result<T, CoreError>;
7
8/// Errors raised by the core agent/model layer.
9#[derive(Debug, Error)]
10pub enum CoreError {
11 /// A tool call referenced an unknown tool.
12 #[error("unknown tool: {0}")]
13 UnknownTool(String),
14
15 /// Tool input failed JSON-schema validation.
16 #[error("tool input validation failed: {0}")]
17 ToolInputValidation(String),
18
19 /// Tool output failed to serialize or validate.
20 #[error("tool output invalid: {0}")]
21 ToolOutput(String),
22
23 /// The model provider rejected the request.
24 #[error("model provider error: {0}")]
25 ModelProvider(String),
26
27 /// The model response could not be parsed.
28 #[error("model response parse error: {0}")]
29 ModelResponse(String),
30
31 /// An I/O or transport error talking to a provider.
32 #[error("transport error: {0}")]
33 Transport(String),
34
35 /// A caller cancelled the operation (e.g. SIGINT, token triggered).
36 ///
37 /// Distinct from [`CoreError::TurnTimeout`]: a *caller-initiated* abort,
38 /// not a deadline elapsing. Keeping the two separate lets the CLI map a
39 /// turn-budget timeout to exit code `124` without string-matching the
40 /// message (the headless runner contract distinguishes them).
41 #[error("operation cancelled: {0}")]
42 Cancelled(String),
43
44 /// A per-turn deadline elapsed (the agent loop's `turn_timeout_ms`).
45 ///
46 /// Mapped to exit code `124` by the CLI headless runner (matching the
47 /// `timeout(1)` convention used by the bash tool). This is a *deadline*
48 /// event, not caller-initiated cancellation — see [`CoreError::Cancelled`].
49 #[error("turn timed out after {ms}ms")]
50 TurnTimeout {
51 /// The per-turn deadline that was exceeded, in milliseconds.
52 ms: u64,
53 },
54}