Skip to main content

rustybook_errors/
lib.rs

1use jsonpath_rust::parser::errors::*;
2use thiserror::Error;
3
4#[derive(Debug, Error)]
5pub enum Error {
6    #[error("extraction failed")]
7    ExtractionError(#[from] ExtractionError),
8    
9    #[error("network error")]
10    NetworkError(#[from] NetworkError),
11    
12    #[error("collector error")]
13    CollectorError(#[from] CollectorError)
14}
15
16#[derive(Debug, Error)]
17pub enum ExtractionError {
18    #[error("query failed")]
19    Query(#[from] JsonPathError),
20
21    #[error("deserialization failed")]
22    Serde(#[from] serde_json::Error),
23
24    #[error("regex search failed")]
25    Regex(#[from] regex::Error),
26
27    #[error("selector parse failed: {0}")]
28    Selector(String),
29
30    #[error("missing `content` attribute")]
31    MissingContentAttr,
32
33    #[error("missing `url` in meta refresh")]
34    MissingUrlAttr,
35
36    #[error("{0}")]
37    Other(String),
38}
39
40#[derive(Debug, Error)]
41pub enum NetworkError {
42    #[error("request failed")]
43    Reqwest(#[from] reqwest::Error),
44
45    #[error("max redirect exceeded")]
46    MetaRefreshExtractionError(#[from] ExtractionError),
47
48    #[error("exceeded maximum redirect limit")]
49    MaxRedirectExceeded,
50}
51
52#[derive(Debug, Error)]
53pub enum CollectorError {
54    #[error("serialization failed")]
55    Serde(#[from] serde_json::Error),
56    
57    #[error("write failed")]
58    WriteError(#[from] WriteError)
59}
60
61#[derive(Debug, Error)]
62pub enum WriteError {
63    #[error("write failed")]
64    WriteFailed,
65    
66    #[error("io error")]
67    IOError(#[from] std::io::Error)
68}