1use std::io;
2
3#[derive(Debug, thiserror::Error)]
5#[non_exhaustive]
6pub enum Error {
7 #[error("claude CLI not found in PATH")]
8 CliNotFound,
9
10 #[error("claude CLI version {found} too old, need >= {required}")]
11 CliVersionTooOld { found: String, required: String },
12
13 #[error("failed to connect to CLI process: {0}")]
14 CliConnection(String),
15
16 #[error("CLI process error: {0}")]
17 Process(String),
18
19 #[error("CLI process exited with code {code}: {stderr}")]
20 ProcessExit { code: i32, stderr: String },
21
22 #[error("JSON decode error: {0}")]
23 JsonDecode(#[from] serde_json::Error),
24
25 #[error("failed to parse message: {reason}")]
26 MessageParse { reason: String },
27
28 #[error("control protocol timeout after {0:?}")]
29 ControlTimeout(std::time::Duration),
30
31 #[error("control protocol error: {0}")]
32 ControlProtocol(String),
33
34 #[error("transport closed")]
35 TransportClosed,
36
37 #[error("not connected")]
38 NotConnected,
39
40 #[error("already connected")]
41 AlreadyConnected,
42
43 #[error("IO error: {0}")]
44 Io(#[from] io::Error),
45
46 #[error("MCP error: {code}: {message}")]
47 Mcp { code: i64, message: String },
48
49 #[error("hook error: {0}")]
50 Hook(String),
51}
52
53pub type Result<T> = std::result::Result<T, Error>;