Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

Die error_chain, die #10747

Merged
merged 6 commits into from
Jun 17, 2019
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions ethcore/light/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ authors = ["Parity Technologies <admin@parity.io>"]
log = "0.4"
parity-bytes = "0.1"
common-types = { path = "../types" }
derive_more = "0.14.0"
ethcore = { path = ".."}
ethcore-db = { path = "../db" }
ethcore-blockchain = { path = "../blockchain" }
Expand Down
4 changes: 2 additions & 2 deletions ethcore/light/src/client/header_chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ impl HeaderChain {
let best_block = {
let era = match candidates.get(&curr.best_num) {
Some(era) => era,
None => bail!("Database corrupt: highest block referenced but no data."),
None => return Err("Database corrupt: highest block referenced but no data.".into()),
};

let best = &era.candidates[0];
Expand Down Expand Up @@ -582,7 +582,7 @@ impl HeaderChain {
} else {
let msg = format!("header of block #{} not found in DB ; database in an \
inconsistent state", h_num);
bail!(msg);
return Err(msg.into());
};

let decoded = header.decode().expect("decoding db value failed");
Expand Down
3 changes: 1 addition & 2 deletions ethcore/light/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,7 @@ extern crate keccak_hash as hash;
extern crate triehash_ethereum as triehash;
extern crate kvdb;
extern crate memory_cache;
#[macro_use]
extern crate error_chain;
extern crate derive_more;

#[cfg(test)]
extern crate kvdb_memorydb;
Expand Down
43 changes: 21 additions & 22 deletions ethcore/light/src/on_demand/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,32 +66,31 @@ pub const DEFAULT_NUM_CONSECUTIVE_FAILED_REQUESTS: usize = 1;

/// OnDemand related errors
pub mod error {
// Silence: `use of deprecated item 'std::error::Error::cause': replaced by Error::source, which can support downcasting`
// https://github.com/paritytech/parity-ethereum/issues/10302
#![allow(deprecated)]

use futures::sync::oneshot::Canceled;

error_chain! {

foreign_links {
ChannelCanceled(Canceled) #[doc = "Canceled oneshot channel"];
}

errors {
#[doc = "Timeout bad response"]
BadResponse(err: String) {
description("Max response evaluation time exceeded")
display("{}", err)
}
/// OnDemand Error
#[derive(Debug, derive_more::Display, derive_more::From)]
pub enum Error {
/// Canceled oneshot channel
ChannelCanceled(Canceled),
/// Timeout bad response
BadResponse(String),
/// OnDemand requests limit exceeded
#[display(fmt = "OnDemand request maximum backoff iterations exceeded")]
RequestLimit,
}

#[doc = "OnDemand requests limit exceeded"]
RequestLimit {
description("OnDemand request maximum backoff iterations exceeded")
display("OnDemand request maximum backoff iterations exceeded")
impl std::error::Error for Error {
fn source(&self) -> Option<&(std::error::Error + 'static)> {
match self {
Error::ChannelCanceled(err) => Some(err),
_ => None,
}
}
}

/// OnDemand Result
pub type Result<T> = std::result::Result<T, Error>;
}

/// Public interface for performing network requests `OnDemand`
Expand Down Expand Up @@ -272,15 +271,15 @@ impl Pending {
response_err
);

let err = self::error::ErrorKind::BadResponse(err);
let err = self::error::Error::BadResponse(err);
if self.sender.send(Err(err.into())).is_err() {
debug!(target: "on_demand", "Dropped oneshot channel receiver on no response");
}
}

// returning a peer discovery timeout during query attempts
fn request_limit_reached(self) {
let err = self::error::ErrorKind::RequestLimit;
let err = self::error::Error::RequestLimit;
if self.sender.send(Err(err.into())).is_err() {
debug!(target: "on_demand", "Dropped oneshot channel receiver on time out");
}
Expand Down
4 changes: 0 additions & 4 deletions ethcore/private-tx/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@

//! Private transactions module.

// Recursion limit required because of
// error_chain foreign_links.
#![recursion_limit="256"]

mod encryptor;
mod key_server_keys;
mod private_transactions;
Expand Down
2 changes: 1 addition & 1 deletion ethcore/service/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ authors = ["Parity Technologies <admin@parity.io>"]

[dependencies]
ansi_term = "0.10"
error-chain = { version = "0.12", default-features = false }
derive_more = "0.14.0"
ethcore = { path = ".." }
ethcore-blockchain = { path = "../blockchain" }
ethcore-io = { path = "../../util/io" }
Expand Down
26 changes: 17 additions & 9 deletions ethcore/service/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,26 @@
// You should have received a copy of the GNU General Public License
// along with Parity Ethereum. If not, see <http://www.gnu.org/licenses/>.

// Silence: `use of deprecated item 'std::error::Error::cause': replaced by Error::source, which can support downcasting`
// https://github.com/paritytech/parity-ethereum/issues/10302
#![allow(deprecated)]

use ethcore;
use io;
use ethcore_private_tx;

error_chain! {
foreign_links {
Ethcore(ethcore::error::Error);
IoError(io::IoError);
PrivateTransactions(ethcore_private_tx::Error);
#[derive(Debug, derive_more::Display, derive_more::From)]
pub enum Error {
/// Ethcore Error
Ethcore(ethcore::error::Error),
/// Io Error
IoError(io::IoError),
/// Private Transactions Error
PrivateTransactions(ethcore_private_tx::Error),
}

impl std::error::Error for Error {
fn source(&self) -> Option<&(std::error::Error + 'static)> {
match self {
Error::Ethcore(err) => Some(err),
Error::IoError(err) => Some(err),
Error::PrivateTransactions(err) => Some(err),
}
}
}
5 changes: 2 additions & 3 deletions ethcore/service/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ extern crate ethcore_sync as sync;
extern crate ethereum_types;
extern crate kvdb;

#[macro_use]
extern crate error_chain;
extern crate derive_more;
#[macro_use]
extern crate log;
#[macro_use]
Expand All @@ -42,5 +41,5 @@ mod stop_guard;
#[cfg(test)]
extern crate kvdb_rocksdb;

pub use error::{Error, ErrorKind};
pub use error::Error;
pub use service::{ClientService, PrivateTxService};
4 changes: 2 additions & 2 deletions ethcore/service/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ impl PrivateTxHandler for PrivateTxService {
Ok(import_result) => Ok(import_result),
Err(err) => {
warn!(target: "privatetx", "Unable to import private transaction packet: {}", err);
bail!(err.to_string())
return Err(err.to_string())
}
}
}
Expand All @@ -69,7 +69,7 @@ impl PrivateTxHandler for PrivateTxService {
Ok(import_result) => Ok(import_result),
Err(err) => {
warn!(target: "privatetx", "Unable to import signed private transaction packet: {}", err);
bail!(err.to_string())
return Err(err.to_string())
}
}
}
Expand Down
4 changes: 0 additions & 4 deletions ethcore/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,6 @@
//! cargo build --release
//! ```

// Recursion limit required because of
// error_chain foreign_links.
#![recursion_limit="128"]

extern crate ansi_term;
extern crate bn;
extern crate byteorder;
Expand Down
6 changes: 3 additions & 3 deletions ethcore/sync/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use std::time::Duration;
use bytes::Bytes;
use devp2p::NetworkService;
use network::{NetworkProtocolHandler, NetworkContext, PeerId, ProtocolId,
NetworkConfiguration as BasicNetworkConfiguration, NonReservedPeerMode, Error, ErrorKind,
NetworkConfiguration as BasicNetworkConfiguration, NonReservedPeerMode, Error,
ConnectionFilter};
use network::client_version::ClientVersion;

Expand Down Expand Up @@ -593,7 +593,7 @@ impl ChainNotify for EthSync {
match self.network.start() {
Err((err, listen_address)) => {
match err.into() {
ErrorKind::Io(ref e) if e.kind() == io::ErrorKind::AddrInUse => {
Error::Io(ref e) if e.kind() == io::ErrorKind::AddrInUse => {
warn!("Network port {:?} is already in use, make sure that another instance of an Ethereum client is not running or change the port using the --port option.", listen_address.expect("Listen address is not set."))
},
err => warn!("Error starting network: {}", err),
Expand Down Expand Up @@ -983,7 +983,7 @@ impl ManageNetwork for LightSync {
match self.network.start() {
Err((err, listen_address)) => {
match err.into() {
ErrorKind::Io(ref e) if e.kind() == io::ErrorKind::AddrInUse => {
Error::Io(ref e) if e.kind() == io::ErrorKind::AddrInUse => {
warn!("Network port {:?} is already in use, make sure that another instance of an Ethereum client is not running or change the port using the --port option.", listen_address.expect("Listen address is not set."))
},
err => warn!("Error starting network: {}", err),
Expand Down
8 changes: 4 additions & 4 deletions ethcore/sync/src/blocks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -435,13 +435,13 @@ impl BlockCollection {
},
None => {
warn!("Got body with no header {}", h);
Err(network::ErrorKind::BadProtocol.into())
Err(network::Error::BadProtocol)
}
}
}
None => {
trace!(target: "sync", "Ignored unknown/stale block body. tx_root = {:?}, uncles = {:?}", header_id.transactions_root, header_id.uncles);
Err(network::ErrorKind::BadProtocol.into())
Err(network::Error::BadProtocol)
}
}
}
Expand All @@ -463,15 +463,15 @@ impl BlockCollection {
},
None => {
warn!("Got receipt with no header {}", h);
return Err(network::ErrorKind::BadProtocol.into())
return Err(network::Error::BadProtocol)
}
}
}
Ok(block_hashes)
},
hash_map::Entry::Vacant(_) => {
trace!(target: "sync", "Ignored unknown/stale block receipt {:?}", receipt_root);
Err(network::ErrorKind::BadProtocol.into())
Err(network::Error::BadProtocol)
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion ethcore/sync/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,5 +76,5 @@ mod api;
pub use api::*;
pub use chain::{SyncStatus, SyncState};
pub use devp2p::validate_node_url;
pub use network::{NonReservedPeerMode, Error, ErrorKind, ConnectionFilter, ConnectionDirection};
pub use network::{NonReservedPeerMode, Error, ConnectionFilter, ConnectionDirection};
pub use private_tx::{PrivateTxHandler, NoopPrivateTxHandler, SimplePrivateTxHandler};
2 changes: 0 additions & 2 deletions miner/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@ extern crate ethabi_contract;
#[macro_use]
extern crate ethabi_derive;
#[macro_use]
extern crate error_chain;
#[macro_use]
extern crate log;
#[macro_use]
extern crate serde_derive;
Expand Down
Loading