Skip to main content

chimera_core/
error.rs

1use std::path::PathBuf;
2
3#[derive(Debug, thiserror::Error)]
4#[non_exhaustive]
5pub enum AgentError {
6    #[error("binary not found: {binary} (searched: {searched:?})")]
7    BinaryNotFound {
8        binary: String,
9        searched: Vec<PathBuf>,
10    },
11
12    #[error("failed to spawn process: {source}")]
13    SpawnFailed {
14        #[source]
15        source: std::io::Error,
16    },
17
18    #[error("process exited with code {code}: {stderr}")]
19    ProcessFailed { code: i32, stderr: String },
20
21    #[error("process killed by signal: {stderr}")]
22    ProcessKilled { stderr: String },
23
24    #[error("failed to write to subprocess stdin: {source}")]
25    StdinWrite {
26        #[source]
27        source: std::io::Error,
28    },
29
30    #[error("failed to parse JSON: {line}")]
31    JsonParse {
32        line: String,
33        #[source]
34        source: serde_json::Error,
35    },
36
37    #[error("JSON buffer exceeded {limit} bytes")]
38    BufferOverflow { limit: usize },
39
40    #[error("turn failed: {message}")]
41    TurnFailed { message: String },
42
43    #[error("control protocol error: {message}")]
44    ControlError { message: String },
45
46    #[error("operation timed out after {duration:?}")]
47    Timeout { duration: std::time::Duration },
48
49    #[error("session interrupted")]
50    Interrupted,
51
52    #[error("backend config does not match backend variant")]
53    ConfigMismatch,
54
55    #[error("{message}")]
56    Other {
57        message: String,
58        #[source]
59        source: Option<Box<dyn std::error::Error + Send + Sync>>,
60    },
61}