1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
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))
}
}