use thiserror::Error;
pub type Result<T> = std::result::Result<T, Error>;
#[derive(Error, Debug)]
pub enum Error {
#[error("terraform binary not found")]
NotFound,
#[error("terraform command failed: {command} (exit code {exit_code})")]
CommandFailed {
command: String,
exit_code: i32,
stdout: String,
stderr: String,
},
#[error("io error: {message}")]
Io {
message: String,
#[source]
source: std::io::Error,
},
#[error("terraform 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,
},
}
impl From<std::io::Error> for Error {
fn from(e: std::io::Error) -> Self {
if e.kind() == std::io::ErrorKind::NotFound {
Error::NotFound
} else {
Error::Io {
message: e.to_string(),
source: e,
}
}
}
}