Skip to main content

vynil_core/
lib.rs

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