use crate::{
action::transform::error::TransformError, auth::google::GoogleOAuth2Error,
external_save::ExternalSaveError, sink::error::SinkError, source::error::SourceError,
};
use std::error::Error as StdError;
#[allow(missing_docs)] #[derive(thiserror::Error, Debug)]
pub enum Error {
#[error("Can't fetch data")]
Source(#[from] SourceError),
#[error("Can't transform data")]
Transform(#[from] Box<TransformError>),
#[error("Can't send data")]
Sink(#[from] SinkError),
#[error("Google authentication error")]
GoogleOAuth2(#[from] GoogleOAuth2Error),
#[error("Error writing to the external save location")]
ExternalSave(#[source] ExternalSaveError),
}
#[allow(missing_docs)] #[derive(thiserror::Error, Debug)]
#[error("Invalid URL: {1}")]
pub struct InvalidUrlError(#[source] pub url::ParseError, pub String);
#[allow(missing_docs)] #[derive(thiserror::Error, Debug)]
#[error("Invalid regular expression")]
pub struct BadRegexError(#[from] pub regex::Error);
impl Error {
#[allow(clippy::match_same_arms)]
#[must_use]
pub fn is_connection_error(&self) -> Option<&(dyn StdError + Send + Sync)> {
#[allow(clippy::match_wildcard_for_single_variants)]
match self {
Self::Source(source_err) => source_err.is_connection_err(),
Error::Transform(tr_err) => tr_err.is_connection_err(),
Error::Sink(sink_err) => sink_err.is_connection_err(),
Error::GoogleOAuth2(google_oauth2_err) => google_oauth2_err.is_connection_err(),
_ => None,
}
}
}
impl From<TransformError> for Error {
fn from(e: TransformError) -> Self {
Error::Transform(Box::new(e))
}
}