poa-bridge/bridge/src/error.rs

85 lines
2.1 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 tokio_timer::{TimerError, TimeoutError};
use {web3, toml, ethabi, rustc_hex};
use ethcore::ethstore;
use ethcore::account_provider::{SignError, Error as AccountError};
use serde_json;
use hyper;
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);
Json(serde_json::Error);
Hyper(hyper::Error);
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
InsufficientFunds
NoRequiredSignaturesChanged {
description("No RequiredSignaturesChanged has been observed")
}
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
}
KeyStore(err: ethstore::Error) {
description("keystore error"),
display("keystore error {:?}", err),
}
SignError(err: SignError) {
description("signing error")
display("signing error {:?}", err),
}
AccountError(err: AccountError) {
description("account error")
display("account error {:?}", err),
}
ContextualizedError(err: Box<Error>, context: &'static str) {
description("contextualized error")
display("{:?} in {}", err, context)
}
OtherError(error: String) {
description("other error")
display("{}", error)
}
ConfigError(err: String) {
description("config error")
display("{}", err)
}
2017-08-01 02:36:48 -07:00
}
}
2017-08-31 08:32:34 -07:00
impl<T> From<TimeoutError<T>> for Error {
fn from(err: TimeoutError<T>) -> Self {
2017-08-31 08:32:34 -07:00
match err {
TimeoutError::Timer(_call, _) | TimeoutError::TimedOut(_call) => {
ErrorKind::Timeout("communication timeout").into()
2017-08-31 08:32:34 -07:00
}
}
}
}