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("failed to parse terraform output: {message}")]
28 ParseError {
29 message: String,
31 },
32
33 #[error("io error: {message}")]
35 Io {
36 message: String,
38 #[source]
40 source: std::io::Error,
41 },
42
43 #[error("terraform command timed out after {timeout_seconds}s")]
45 Timeout {
46 timeout_seconds: u64,
48 },
49
50 #[cfg(feature = "json")]
52 #[error("json parse error: {message}")]
53 Json {
54 message: String,
56 #[source]
58 source: serde_json::Error,
59 },
60}
61
62impl From<std::io::Error> for Error {
63 fn from(e: std::io::Error) -> Self {
64 if e.kind() == std::io::ErrorKind::NotFound {
65 Error::NotFound
66 } else {
67 Error::Io {
68 message: e.to_string(),
69 source: e,
70 }
71 }
72 }
73}