web_scrape/scrape/
scrape_error.rs1use std::fmt::{Display, Formatter};
2
3#[derive(Debug)]
5pub enum ScrapeError {
6 InvalidSelection { selection: String, message: String },
8
9 ExpectedOneGotMultiple { selection: String },
11
12 ExpectedOneGotNone { selection: String },
14
15 ExpectedOptionalGotMultiple { selection: String },
17
18 Other(String),
20}
21
22impl<S: Into<String>> From<S> for ScrapeError {
23 fn from(message: S) -> Self {
24 Self::Other(message.into())
25 }
26}
27
28impl Display for ScrapeError {
29 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
30 match self {
31 Self::InvalidSelection { selection, message } => {
32 write!(f, "invalid selection '{}': {}", selection, message)
33 }
34 Self::ExpectedOneGotMultiple { selection } => {
35 write!(f, "expected one, got multiple: {}", selection)
36 }
37 Self::ExpectedOneGotNone { selection } => {
38 write!(f, "expected one, got none: {}", selection)
39 }
40 Self::ExpectedOptionalGotMultiple { selection } => {
41 write!(f, "expected one or none, got multiple: {}", selection)
42 }
43 Self::Other(message) => {
44 write!(f, "error scraping page: {}", message)
45 }
46 }
47 }
48}
49
50impl std::error::Error for ScrapeError {}