1use std::{env::VarError, str::ParseBoolError};
2
3use thiserror::Error;
4
5#[derive(Debug, Error)]
7pub enum Error {
8    #[error("Key: {0}")]
9    Key(&'static str),
10
11    #[error("Rejected: {0}")]
12    Rejected(String),
13
14    #[error("IO: {0}")]
15    IO(#[from] std::io::Error),
16
17    #[error("Sign")]
18    Sign(ring::error::Unspecified),
19
20    #[error("Systemtime: {0}")]
21    SystemTime(#[from] std::time::SystemTimeError),
22
23    #[error("Ureq: {0}")]
26    Ureq(#[from] ureq::Error),
27
28    #[error("IP 4 address missing")]
30    Ipv4,
31
32    #[allow(dead_code)]
33    #[error("Acme challenge not found")]
34    AcmeChallege,
35
36    #[error("Address: {0}")]
37    Address(#[from] std::net::AddrParseError),
38
39    #[error("Invalid Token")]
40    Token,
41
42    #[error("Base64: {0}")]
43    Base64Decode(#[from] base64::DecodeError),
44
45    #[error("Utf8: {0}")]
46    Utf8Decode(#[from] std::str::Utf8Error),
47
48    #[error("Parse Int: {0}")]
49    ParseInt(#[from] std::num::ParseIntError),
50
51    #[error("Parse Expiration: {0}")]
52    ParseExpiration(&'static str),
53
54    #[error("Parse Dns entry: {0}")]
55    ParseDnsEntry(&'static str),
56
57    #[error("Parse Mailbox entry: {0}")]
58    ParseMailboxEntry(String),
59
60    #[error("Parse Mail forward entry: {0}")]
61    ParseMailForwardEntry(String),
62
63    #[error("Environment variable not set: {0}")]
64    EnvironmentVariable(String),
65
66    #[error("Var: {0}")]
67    Var(#[from] VarError),
68
69    #[error("Api test failed")]
70    ApiTest,
71
72    #[error("No IP")]
73    NoIp,
74
75    #[error("Parse: {0}")]
76    ParseBoolean(#[from] ParseBoolError),
77
78    #[error("Strum: {0}")]
79    Strum(#[from] strum::ParseError),
80
81    #[error("Serialization: {0}")]
82    Serialization(Box<dyn std::error::Error>),
83
84    #[error("Json: {0}")]
85    Json(#[from] serde_json::Error),
86}
87
88pub(crate) trait ResultExt<T, E>
89where
90    E: Into<Error>,
91{
92    fn err_into(self) -> Result<T, Error>;
93}
94
95impl<T, E> ResultExt<T, E> for Result<T, E>
96where
97    E: Into<Error>,
98{
99    fn err_into(self) -> Result<T, Error> {
100        self.map_err(Into::into)
101    }
102}