1use thiserror::Error;
2
3#[derive(Error, Debug)]
4pub enum Error {
5 #[error("SerializationError: {0}")]
6 SerializationError(#[from] serde_json::Error),
7
8 #[error("YamlError: {0}")]
9 YamlError(String),
10
11 #[error("Registering template failed with error: {0}")]
12 HbsTemplateError(#[from] handlebars::TemplateError),
13
14 #[error("Renderer error: {0}")]
15 HbsRenderError(#[from] handlebars::RenderError),
16
17 #[error("Rhai script error: {0}")]
18 RhaiError(#[from] Box<rhai::EvalAltResult>),
19
20 #[error("Reqwest error: {0}")]
21 ReqwestError(#[from] reqwest::Error),
22
23 #[error("Json decoding error: {0}")]
24 JsonError(#[source] serde_json::Error),
25
26 #[error("{0} query failed: {1}")]
27 MethodFailed(String, u16, String),
28
29 #[error("Unsupported method")]
30 UnsupportedMethod,
31
32 #[error("Missing script {0}")]
33 MissingScript(std::path::PathBuf),
34
35 #[error("UTF8 error {0}")]
36 UTF8(#[from] std::string::FromUtf8Error),
37
38 #[error("Semver error {0}")]
39 Semver(#[from] ::semver::Error),
40
41 #[error("Argon2 password_hash error {0}")]
42 Argon2hash(#[from] argon2::password_hash::Error),
43
44 #[error("Bcrypt hash error {0}")]
45 BcryptError(#[from] bcrypt::BcryptError),
46
47 #[error("Stdio error {0}")]
48 Stdio(#[from] std::io::Error),
49
50 #[error("Base64 decode error {0}")]
51 Base64DecodeError(#[from] base64::DecodeError),
52
53 #[error("RAW api error {0}")]
54 RawHTTP(#[from] ::http::Error),
55
56 #[error("ParseIntError {0}")]
57 ParseInt(#[from] std::num::ParseIntError),
58
59 #[error("KEY-OPENSSL-001 OpenSSL error {0}")]
60 OpenSSL(#[from] openssl::error::ErrorStack),
61
62 #[error("KEY-ALGO-001 Unsupported key algorithm: {0}")]
63 UnsupportedKeyAlgorithm(String),
64
65 #[error("{0}")]
66 PasswordSpec(String),
67
68 #[error("Error: {0}")]
69 Other(String),
70
71 #[cfg(feature = "oci")]
72 #[error("OCI jukebox error {0}")]
73 OCIDistrib(#[from] oci_client::errors::OciDistributionError),
74
75 #[cfg(feature = "oci")]
76 #[error("OCI parse error {0}")]
77 OCIParseError(#[from] oci_client::ParseError),
78
79 #[cfg(feature = "k8s")]
80 #[error("K8s error: {0}")]
81 KubeError(#[from] kube::Error),
82
83 #[cfg(feature = "k8s")]
84 #[error("K8s wait error: {0}")]
85 KubeWaitError(#[from] kube::runtime::wait::Error),
86
87 #[cfg(feature = "k8s")]
88 #[error("Elapsed wait error: {0}")]
89 Elapsed(#[from] tokio::time::error::Elapsed),
90
91 #[cfg(feature = "k8s")]
92 #[error("Finalizer error: {0}")]
93 FinalizerError(#[from] Box<kube::runtime::finalizer::Error<Error>>),
94}
95
96pub type Result<T, E = Error> = std::result::Result<T, E>;
97pub type RhaiRes<T> = std::result::Result<T, Box<rhai::EvalAltResult>>;
98
99pub fn rhai_err(e: Error) -> Box<rhai::EvalAltResult> {
100 e.to_string().into()
101}
102
103pub fn rhai_err_str(e: String) -> Box<rhai::EvalAltResult> {
104 e.into()
105}
106
107pub mod chrono;
108pub mod client_name;
109pub mod engine;
110pub mod glob;
111pub mod hashes;
112pub mod hbs;
113pub mod http;
114pub mod http_mock;
115pub mod key;
116pub mod password;
117pub mod semver;
118pub mod shell;
119pub mod yaml;
120
121#[cfg(feature = "oci")] pub mod oci;
122#[cfg(feature = "oci")] pub mod oci_mock;
123
124#[cfg(feature = "s3")] pub mod s3;
125
126#[cfg(feature = "k8s")] pub mod k8s;
127#[cfg(feature = "k8s")] pub mod k8s_mock;
128
129pub use client_name::{client_name_is_set, get_client_name, set_client_name};
130pub use semver::Semver;
131
132#[cfg(feature = "k8s")] pub use k8s::update_cache;