use thiserror::Error;
use entelix_core::error::Error;
#[derive(Debug, Error)]
#[non_exhaustive]
pub enum CloudError {
#[error("credential resolution failed: {message}")]
Credential {
message: String,
#[source]
source: Option<Box<dyn std::error::Error + Send + Sync + 'static>>,
},
#[error("signing failed: {message}")]
Signing {
message: String,
#[source]
source: Option<Box<dyn std::error::Error + Send + Sync + 'static>>,
},
#[error("network failure: {message}")]
Network {
message: String,
#[source]
source: Option<Box<dyn std::error::Error + Send + Sync + 'static>>,
},
#[error("configuration error: {0}")]
Config(String),
#[cfg(feature = "aws")]
#[cfg_attr(docsrs, doc(cfg(feature = "aws")))]
#[error("event-stream decode failed: {0}")]
EventStream(#[from] crate::bedrock::event_stream::EventStreamParseError),
}
impl CloudError {
pub fn credential<E>(source: E) -> Self
where
E: std::error::Error + Send + Sync + 'static,
{
Self::Credential {
message: source.to_string(),
source: Some(Box::new(source)),
}
}
pub fn credential_msg(message: impl Into<String>) -> Self {
Self::Credential {
message: message.into(),
source: None,
}
}
pub fn signing<E>(source: E) -> Self
where
E: std::error::Error + Send + Sync + 'static,
{
Self::Signing {
message: source.to_string(),
source: Some(Box::new(source)),
}
}
pub fn signing_msg(message: impl Into<String>) -> Self {
Self::Signing {
message: message.into(),
source: None,
}
}
pub fn network<E>(source: E) -> Self
where
E: std::error::Error + Send + Sync + 'static,
{
Self::Network {
message: source.to_string(),
source: Some(Box::new(source)),
}
}
pub fn network_msg(message: impl Into<String>) -> Self {
Self::Network {
message: message.into(),
source: None,
}
}
}
impl From<CloudError> for Error {
fn from(err: CloudError) -> Self {
match err {
CloudError::Config(msg) => Self::config(msg),
other => Self::provider_network_from(other),
}
}
}