Skip to main content

blueprint_remote_providers/core/
error.rs

1use thiserror::Error;
2
3#[derive(Error, Debug)]
4pub enum Error {
5    #[error("Configuration error: {0}")]
6    ConfigurationError(String),
7
8    #[error("Cluster not found: {0}")]
9    ClusterNotFound(String),
10
11    #[error("Network error: {0}")]
12    NetworkError(String),
13
14    #[cfg(feature = "kubernetes")]
15    #[error("Kubernetes error: {0}")]
16    Kube(#[from] kube::Error),
17
18    #[cfg(feature = "aws")]
19    #[error("AWS EC2 error: {0}")]
20    AwsEc2(#[from] aws_sdk_ec2::Error),
21
22    #[cfg(feature = "aws-eks")]
23    #[error("AWS EKS error: {0}")]
24    AwsEks(#[from] aws_sdk_eks::Error),
25
26    #[error("IO error: {0}")]
27    Io(#[from] blueprint_std::io::Error),
28
29    #[error("Provider {0:?} not configured")]
30    ProviderNotConfigured(crate::core::remote::CloudProvider),
31
32    #[error("Serialization error: {0}")]
33    SerializationError(String),
34
35    #[error("HTTP error: {0}")]
36    HttpError(String),
37
38    #[error("Other error: {0}")]
39    Other(String),
40}
41
42impl From<toml::de::Error> for Error {
43    fn from(err: toml::de::Error) -> Self {
44        Error::SerializationError(err.to_string())
45    }
46}
47
48impl From<serde_yaml::Error> for Error {
49    fn from(err: serde_yaml::Error) -> Self {
50        Error::SerializationError(err.to_string())
51    }
52}
53
54#[cfg(feature = "aws")]
55impl<E> From<aws_sdk_ec2::error::SdkError<E>> for Error
56where
57    E: blueprint_std::error::Error + Send + Sync + 'static,
58{
59    fn from(err: aws_sdk_ec2::error::SdkError<E>) -> Self {
60        Error::Other(err.to_string())
61    }
62}
63
64#[cfg(feature = "kubernetes")]
65impl From<kube::config::InferConfigError> for Error {
66    fn from(err: kube::config::InferConfigError) -> Self {
67        Error::Other(err.to_string())
68    }
69}
70
71#[cfg(feature = "kubernetes")]
72impl From<kube::config::KubeconfigError> for Error {
73    fn from(err: kube::config::KubeconfigError) -> Self {
74        Error::Other(err.to_string())
75    }
76}
77
78pub type Result<T> = blueprint_std::result::Result<T, Error>;