Skip to main content

claude_wrapper/
error.rs

1/// Errors returned by claude-wrapper operations.
2#[derive(Debug, thiserror::Error)]
3pub enum Error {
4    /// The `claude` binary was not found in PATH.
5    #[error("claude binary not found in PATH")]
6    NotFound,
7
8    /// A claude command failed with a non-zero exit code.
9    #[error("claude command failed: {command} (exit code {exit_code})")]
10    CommandFailed {
11        command: String,
12        exit_code: i32,
13        stdout: String,
14        stderr: String,
15    },
16
17    /// An I/O error occurred while spawning or communicating with the process.
18    #[error("io error: {message}")]
19    Io {
20        message: String,
21        #[source]
22        source: std::io::Error,
23    },
24
25    /// The command timed out.
26    #[error("claude command timed out after {timeout_seconds}s")]
27    Timeout { timeout_seconds: u64 },
28
29    /// JSON parsing failed.
30    #[cfg(feature = "json")]
31    #[error("json parse error: {message}")]
32    Json {
33        message: String,
34        #[source]
35        source: serde_json::Error,
36    },
37
38    /// The installed CLI version does not meet the minimum requirement.
39    #[error("CLI version {found} does not meet minimum requirement {minimum}")]
40    VersionMismatch {
41        found: crate::version::CliVersion,
42        minimum: crate::version::CliVersion,
43    },
44}
45
46impl From<std::io::Error> for Error {
47    fn from(e: std::io::Error) -> Self {
48        Self::Io {
49            message: e.to_string(),
50            source: e,
51        }
52    }
53}
54
55/// Result type alias for claude-wrapper operations.
56pub type Result<T> = std::result::Result<T, Error>;