1use thiserror::Error;
6
7use entelix_core::error::Error;
8
9#[derive(Debug, Error)]
12#[non_exhaustive]
13pub enum CloudError {
14 #[error("credential resolution failed: {message}")]
16 Credential {
17 message: String,
19 #[source]
21 source: Option<Box<dyn std::error::Error + Send + Sync + 'static>>,
22 },
23
24 #[error("signing failed: {message}")]
26 Signing {
27 message: String,
29 #[source]
31 source: Option<Box<dyn std::error::Error + Send + Sync + 'static>>,
32 },
33
34 #[error("network failure: {message}")]
36 Network {
37 message: String,
39 #[source]
41 source: Option<Box<dyn std::error::Error + Send + Sync + 'static>>,
42 },
43
44 #[error("configuration error: {0}")]
46 Config(String),
47
48 #[cfg(feature = "aws")]
50 #[cfg_attr(docsrs, doc(cfg(feature = "aws")))]
51 #[error("event-stream decode failed: {0}")]
52 EventStream(#[from] crate::bedrock::event_stream::EventStreamParseError),
53}
54
55impl CloudError {
56 pub fn credential<E>(source: E) -> Self
58 where
59 E: std::error::Error + Send + Sync + 'static,
60 {
61 Self::Credential {
62 message: source.to_string(),
63 source: Some(Box::new(source)),
64 }
65 }
66
67 pub fn credential_msg(message: impl Into<String>) -> Self {
69 Self::Credential {
70 message: message.into(),
71 source: None,
72 }
73 }
74
75 pub fn signing<E>(source: E) -> Self
77 where
78 E: std::error::Error + Send + Sync + 'static,
79 {
80 Self::Signing {
81 message: source.to_string(),
82 source: Some(Box::new(source)),
83 }
84 }
85
86 pub fn signing_msg(message: impl Into<String>) -> Self {
88 Self::Signing {
89 message: message.into(),
90 source: None,
91 }
92 }
93
94 pub fn network<E>(source: E) -> Self
96 where
97 E: std::error::Error + Send + Sync + 'static,
98 {
99 Self::Network {
100 message: source.to_string(),
101 source: Some(Box::new(source)),
102 }
103 }
104
105 pub fn network_msg(message: impl Into<String>) -> Self {
107 Self::Network {
108 message: message.into(),
109 source: None,
110 }
111 }
112}
113
114impl From<CloudError> for Error {
115 fn from(err: CloudError) -> Self {
116 match err {
117 CloudError::Config(msg) => Self::config(msg),
118 other => Self::provider_network_from(other),
119 }
120 }
121}