electrsd/
error.rs

1/// All the possible error in this crate
2#[derive(Debug)]
3pub enum Error {
4    /// Wrapper of io Error
5    Io(std::io::Error),
6
7    /// Wrapper of bitcoind Error
8    Bitcoind(corepc_node::Error),
9
10    /// Wrapper of electrum_client Error
11    ElectrumClient(electrum_client::Error),
12
13    /// Wrapper of nix Error
14    #[cfg(not(target_os = "windows"))]
15    Nix(nix::Error),
16
17    /// Wrapper of early exit status
18    EarlyExit(std::process::ExitStatus),
19
20    /// Returned when both tmpdir and staticdir is specified in `Conf` options
21    BothDirsSpecified,
22
23    /// Returned when calling methods requiring the bitcoind executable but none is found
24    /// (no feature, no `ELECTRS_EXEC`, no `electrs` in `PATH` )
25    NoElectrsExecutableFound,
26
27    /// Returned if both env vars `ELECTRS_EXEC` and `ELECTRS_EXE` are found
28    BothEnvVars,
29}
30
31impl std::error::Error for Error {
32    fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
33        match self {
34            Error::Io(e) => Some(e),
35            Error::Bitcoind(e) => Some(e),
36            Error::ElectrumClient(e) => Some(e),
37            // Error::BitcoinCoreRpc(e) => Some(e),
38            #[cfg(not(target_os = "windows"))]
39            Error::Nix(e) => Some(e),
40
41            _ => None,
42        }
43    }
44}
45
46impl std::fmt::Display for Error {
47    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
48        write!(f, "{:?}", self)
49    }
50}
51
52impl From<std::io::Error> for Error {
53    fn from(e: std::io::Error) -> Self {
54        Error::Io(e)
55    }
56}
57
58impl From<corepc_node::Error> for Error {
59    fn from(e: corepc_node::Error) -> Self {
60        Error::Bitcoind(e)
61    }
62}
63
64impl From<electrum_client::Error> for Error {
65    fn from(e: electrum_client::Error) -> Self {
66        Error::ElectrumClient(e)
67    }
68}
69
70#[cfg(not(target_os = "windows"))]
71impl From<nix::Error> for Error {
72    fn from(e: nix::Error) -> Self {
73        Error::Nix(e)
74    }
75}