terraform_wrapper/
error.rs1use thiserror::Error;
2
3pub type Result<T> = std::result::Result<T, Error>;
5
6#[derive(Error, Debug)]
8pub enum Error {
9 #[error("terraform binary not found")]
11 NotFound,
12
13 #[error("terraform command failed: {command} (exit code {exit_code})")]
15 CommandFailed {
16 command: String,
18 exit_code: i32,
20 stdout: String,
22 stderr: String,
24 },
25
26 #[error("io error: {message}")]
28 Io {
29 message: String,
31 #[source]
33 source: std::io::Error,
34 },
35
36 #[error("terraform command timed out after {timeout_seconds}s")]
38 Timeout {
39 timeout_seconds: u64,
41 },
42
43 #[cfg(feature = "json")]
45 #[error("json parse error: {message}")]
46 Json {
47 message: String,
49 #[source]
51 source: serde_json::Error,
52 },
53}
54
55impl From<std::io::Error> for Error {
56 fn from(e: std::io::Error) -> Self {
57 if e.kind() == std::io::ErrorKind::NotFound {
58 Error::NotFound
59 } else {
60 Error::Io {
61 message: e.to_string(),
62 source: e,
63 }
64 }
65 }
66}