poa-bridge/bridge/src/error.rs

51 lines
1.2 KiB
Rust
Raw Normal View History

2017-08-13 04:09:50 -07:00
#![allow(unknown_lints)]
use std::io;
2017-08-31 08:32:34 -07:00
use api::ApiCall;
use tokio_timer::{TimerError, TimeoutError};
use {web3, toml, ethabi, rustc_hex};
2017-06-25 04:21:13 -07:00
2017-08-02 03:45:15 -07:00
error_chain! {
types {
Error, ErrorKind, ResultExt, Result;
2017-06-25 04:21:13 -07:00
}
2017-08-02 03:45:15 -07:00
foreign_links {
Io(io::Error);
Toml(toml::de::Error);
2017-08-10 08:55:46 -07:00
Ethabi(ethabi::Error);
2017-08-12 01:55:18 -07:00
Timer(TimerError);
Hex(rustc_hex::FromHexError);
2017-06-25 04:21:13 -07:00
}
2017-08-01 02:36:48 -07:00
2017-08-02 03:45:15 -07:00
errors {
ShutdownRequested
2017-08-31 08:32:34 -07:00
// api timeout
Timeout(request: &'static str) {
description("Request timeout"),
display("Request {} timed out", request),
}
2017-08-04 08:57:09 -07:00
// workaround for error_chain not allowing to check internal error kind
// https://github.com/rust-lang-nursery/error-chain/issues/206
MissingFile(filename: String) {
description("File not found"),
display("File {} not found", filename),
}
2017-08-02 03:45:15 -07:00
// workaround for lack of web3:Error Display and Error implementations
Web3(err: web3::Error) {
2017-08-04 08:57:09 -07:00
description("web3 error"),
display("{:?}", err),
2017-08-02 03:45:15 -07:00
}
2017-08-01 02:36:48 -07:00
}
}
2017-08-31 08:32:34 -07:00
impl<T, F> From<TimeoutError<ApiCall<T, F>>> for Error {
fn from(err: TimeoutError<ApiCall<T, F>>) -> Self {
match err {
TimeoutError::Timer(call, _) | TimeoutError::TimedOut(call) => {
ErrorKind::Timeout(call.message()).into()
}
}
}
}