Skip to main content

spider_lib/
error.rs

1use thiserror::Error;
2
3/// The main error type for the spider framework.
4#[derive(Debug, Error)]
5pub enum SpiderError {
6    #[error("Reqwest error: {0}")]
7    ReqwestError(#[from] reqwest::Error),
8    #[error("Url parsing error: {0}")]
9    UrlParseError(#[from] url::ParseError),
10    #[error("Json parsing error: {0}")]
11    JsonError(#[from] serde_json::Error),
12    #[error("Io error: {0}")]
13    IoError(#[from] std::io::Error),
14    #[error("Configuration error: {0}")]
15    ConfigurationError(String),
16    #[error("General error: {0}")]
17    GeneralError(String),
18    #[error("Failed to convert item to string: {0}")]
19    ItemToStringError(String),
20    #[error("Error during item serialization: {0}")]
21    ItemSerializationError(String),
22    #[error("Unknown error")]
23    Unknown,
24    #[error("Header value error: {0}")]
25    HeaderValueError(String),
26    #[error("HTML parsing error: {0}")]
27    HtmlParseError(String),
28    #[error("UTF-8 parsing error: {0}")]
29    Utf8Error(#[from] std::str::Utf8Error),
30    #[error("Pipeline error: {0}")]
31    PipelineError(#[from] PipelineError),
32    #[error("Request blocked by robots.txt")]
33    BlockedByRobotsTxt,
34}
35
36impl From<bincode::Error> for SpiderError {
37    fn from(err: bincode::Error) -> Self {
38        SpiderError::GeneralError(format!("Bincode error: {}", err))
39    }
40}
41
42/// The error type for item processing pipelines.
43#[derive(Error, Debug)]
44pub enum PipelineError {
45    #[error("I/O error: {0}")]
46    IoError(#[from] std::io::Error),
47    #[error("Item processing error: {0}")]
48    ItemError(String),
49    #[cfg(feature = "pipeline-sqlite")]
50    #[error("Database error: {0}")]
51    DatabaseError(#[from] rusqlite::Error),
52    #[error("Serialization error: {0}")]
53    SerializationError(#[from] serde_json::Error),
54    #[error("CSV error: {0}")]
55    CsvError(#[from] csv::Error),
56    #[error("Other pipeline error: {0}")]
57    Other(String),
58}