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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
use std::string::FromUtf8Error;

pub type Result<T> = std::result::Result<T, Error>;

#[derive(Debug)]
pub enum Error {
    ReqwestError(reqwest::Error),
    RegexError(regex::Error),
    UrlParseError(url::ParseError),
    SerdeJsonError(serde_json::Error),
    IoError(std::io::Error),
    FromUtf8Error(std::string::FromUtf8Error),
    QuickXmlError(quick_xml::Error),
    QuickXmlAttributeError(quick_xml::events::attributes::AttrError),
    WikitextParserError {
        /// The error returned by the parser.
        error: Box<wikitext_parser::ParserError>,
        /// The name of the page.
        page_name: String,
        /// The page content causing the error.
        page_content: String,
    },

    /// The given english language name is unknown.
    UnknownEnglishLanguageName(String),

    /// The given wiktionary language abbreviation is unknown.
    UnknownWiktionaryLanguageAbbreviation(String),

    /// An error described by a string instead of a variant.
    Other(String),
}

impl From<reqwest::Error> for Error {
    fn from(error: reqwest::Error) -> Self {
        Self::ReqwestError(error)
    }
}

impl From<regex::Error> for Error {
    fn from(error: regex::Error) -> Self {
        Self::RegexError(error)
    }
}

impl From<url::ParseError> for Error {
    fn from(error: url::ParseError) -> Self {
        Self::UrlParseError(error)
    }
}

impl From<serde_json::Error> for Error {
    fn from(error: serde_json::Error) -> Self {
        Self::SerdeJsonError(error)
    }
}

impl From<std::io::Error> for Error {
    fn from(error: std::io::Error) -> Self {
        Self::IoError(error)
    }
}

impl From<std::string::FromUtf8Error> for Error {
    fn from(error: FromUtf8Error) -> Self {
        Self::FromUtf8Error(error)
    }
}

impl From<quick_xml::Error> for Error {
    fn from(error: quick_xml::Error) -> Self {
        Self::QuickXmlError(error)
    }
}

impl From<quick_xml::events::attributes::AttrError> for Error {
    fn from(error: quick_xml::events::attributes::AttrError) -> Self {
        Self::QuickXmlAttributeError(error)
    }
}