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
39impl From<std::io::Error> for Error {
40    fn from(e: std::io::Error) -> Self {
41        Self::Io {
42            message: e.to_string(),
43            source: e,
44        }
45    }
46}
47
48/// Result type alias for claude-wrapper operations.
49pub type Result<T> = std::result::Result<T, Error>;