use std::path::PathBuf;
#[derive(Debug, thiserror::Error)]
pub enum Error {
#[error("codex binary not found in PATH")]
NotFound,
#[error("codex command failed: {command} (exit code {exit_code}){}{}{}", working_dir.as_ref().map(|d| format!(" (in {})", d.display())).unwrap_or_default(), if stdout.is_empty() { String::new() } else { format!("\nstdout: {stdout}") }, if stderr.is_empty() { String::new() } else { format!("\nstderr: {stderr}") })]
CommandFailed {
command: String,
exit_code: i32,
stdout: String,
stderr: String,
working_dir: Option<PathBuf>,
},
#[error("io error: {message}{}", working_dir.as_ref().map(|d| format!(" (in {})", d.display())).unwrap_or_default())]
Io {
message: String,
#[source]
source: std::io::Error,
working_dir: Option<PathBuf>,
},
#[error("codex command timed out after {timeout_seconds}s")]
Timeout { timeout_seconds: u64 },
#[cfg(feature = "json")]
#[error("json parse error: {message}")]
Json {
message: String,
#[source]
source: serde_json::Error,
},
#[error("CLI version {found} does not meet minimum requirement {minimum}")]
VersionMismatch {
found: crate::version::CliVersion,
minimum: crate::version::CliVersion,
},
}
impl From<std::io::Error> for Error {
fn from(e: std::io::Error) -> Self {
Self::Io {
message: e.to_string(),
source: e,
working_dir: None,
}
}
}
pub type Result<T> = std::result::Result<T, Error>;