vibranium/blockchain/
error.rs

1use std::io;
2use std::fmt;
3use std::error::Error;
4
5#[derive(Debug)]
6pub enum NodeError {
7  Io(io::Error),
8  UnsupportedClient,
9  Other(String),
10}
11
12impl Error for NodeError {
13  fn cause(&self) -> Option<&Error> {
14    match self {
15      NodeError::Io(err) => Some(err),
16      NodeError::UnsupportedClient => None,
17      NodeError::Other(_message) => None,
18    }
19  }
20}
21
22impl fmt::Display for NodeError {
23  fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
24    match self {
25      NodeError::Io(ref err) => {
26        match err.kind() {
27          io::ErrorKind::NotFound => write!(f, "Couldn't find executable for node client"),
28          _ => write!(f, "{}", err),
29        }
30      },
31      NodeError::UnsupportedClient => write!(f, "No built-in support for request blockchain client. Please specify NodeConfig.client_options"),
32      NodeError::Other(message) => write!(f, "{}", message),
33    }
34  }
35}
36
37#[derive(Debug)]
38pub enum ConnectionError {
39  UnsupportedProtocol,
40  MissingConnectorConfig,
41  Transport(web3::Error),
42  Other(String),
43}
44
45impl Error for ConnectionError {
46  fn cause(&self) -> Option<&Error> {
47    match self {
48      ConnectionError::UnsupportedProtocol => None,
49      ConnectionError::MissingConnectorConfig => None,
50      ConnectionError::Transport(error) => Some(error),
51      ConnectionError::Other(_message) => None,
52    }
53  }
54}
55
56impl fmt::Display for ConnectionError {
57  fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
58    match self {
59      ConnectionError::UnsupportedProtocol => write!(f, "Couldn't create blockchain connector. The configured protocol is not supported"),
60      ConnectionError::MissingConnectorConfig => write!(f, "Couldn't find configuration for blockchain connector in project configuration."),
61      ConnectionError::Transport(error) => write!(f, "{}", error),
62      ConnectionError::Other(message) => write!(f, "{}", message),
63    }
64  }
65}