1use std::path::PathBuf;
2
3#[derive(Debug, thiserror::Error)]
5pub enum Error {
6 #[error("claude binary not found in PATH")]
8 NotFound,
9
10 #[error("claude command failed: {command} (exit code {exit_code}){}", working_dir.as_ref().map(|d| format!(" (in {})", d.display())).unwrap_or_default())]
12 CommandFailed {
13 command: String,
14 exit_code: i32,
15 stdout: String,
16 stderr: String,
17 working_dir: Option<PathBuf>,
18 },
19
20 #[error("io error: {message}{}", working_dir.as_ref().map(|d| format!(" (in {})", d.display())).unwrap_or_default())]
22 Io {
23 message: String,
24 #[source]
25 source: std::io::Error,
26 working_dir: Option<PathBuf>,
27 },
28
29 #[error("claude command timed out after {timeout_seconds}s")]
31 Timeout { timeout_seconds: u64 },
32
33 #[cfg(feature = "json")]
35 #[error("json parse error: {message}")]
36 Json {
37 message: String,
38 #[source]
39 source: serde_json::Error,
40 },
41
42 #[error("CLI version {found} does not meet minimum requirement {minimum}")]
44 VersionMismatch {
45 found: crate::version::CliVersion,
46 minimum: crate::version::CliVersion,
47 },
48}
49
50impl From<std::io::Error> for Error {
51 fn from(e: std::io::Error) -> Self {
52 Self::Io {
53 message: e.to_string(),
54 source: e,
55 working_dir: None,
56 }
57 }
58}
59
60pub type Result<T> = std::result::Result<T, Error>;