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

UtilError utilizes error_chain! #6461

Merged
merged 7 commits into from
Sep 5, 2017
Merged
Show file tree
Hide file tree
Changes from all 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
15 changes: 15 additions & 0 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/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ wasm = { path = "wasm" }
hash = { path = "../util/hash" }
triehash = { path = "../util/triehash" }
semantic_version = { path = "../util/semantic_version" }
unexpected = { path = "../util/unexpected" }

[dev-dependencies]
native-contracts = { path = "native_contracts", features = ["test_contracts"] }
Expand Down
2 changes: 1 addition & 1 deletion ethcore/src/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use rlp::{UntrustedRlp, RlpStream, Encodable, Decodable, DecoderError};
use bigint::prelude::U256;
use bigint::hash::H256;
use util::{Bytes, Address};
use util::error::{Mismatch, OutOfBounds};
use unexpected::{Mismatch, OutOfBounds};

use basic_types::{LogBloom, Seal};
use vm::{EnvInfo, LastHashes};
Expand Down
3 changes: 2 additions & 1 deletion ethcore/src/client/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ use itertools::Itertools;
// util
use hash::keccak;
use timer::PerfTimer;
use util::UtilError;
use util::Bytes;
use util::{journaldb, DBValue, TrieFactory, Trie};
use util::Address;
Expand Down Expand Up @@ -252,7 +253,7 @@ impl Client {
last_hashes: RwLock::new(VecDeque::new()),
factories: factories,
history: history,
rng: Mutex::new(OsRng::new().map_err(::util::UtilError::StdIo)?),
rng: Mutex::new(OsRng::new().map_err(UtilError::from)?),
ancient_verifier: Mutex::new(None),
on_user_defaults_change: Mutex::new(None),
registrar: Mutex::new(None),
Expand Down
1 change: 1 addition & 0 deletions ethcore/src/engines/authority_round/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ use bigint::prelude::{U256, U128};
use bigint::hash::{H256, H520};
use semantic_version::SemanticVersion;
use parking_lot::{Mutex, RwLock};
use unexpected::{Mismatch, OutOfBounds};
use util::*;

mod finality;
Expand Down
1 change: 1 addition & 0 deletions ethcore/src/engines/basic_authority.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ use bigint::prelude::U256;
use bigint::hash::{H256, H520};
use parking_lot::RwLock;
use util::*;
use unexpected::{Mismatch, OutOfBounds};
use ethkey::{recover, public_to_address, Signature};
use account_provider::AccountProvider;
use block::*;
Expand Down
1 change: 1 addition & 0 deletions ethcore/src/engines/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ use bigint::prelude::U256;
use bigint::hash::H256;
use semantic_version::SemanticVersion;
use util::*;
use unexpected::{Mismatch, OutOfBounds};

/// Default EIP-210 contrat code.
/// As defined in https://github.com/ethereum/EIPs/pull/210/commits/9df24a3714af42e3bf350265bdc75b486c909d7f#diff-e02a92c2fb96c1a1bfb05e4c6e2ef5daR49
Expand Down
1 change: 1 addition & 0 deletions ethcore/src/engines/tendermint/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ use bigint::prelude::{U128, U256};
use bigint::hash::{H256, H520};
use parking_lot::RwLock;
use util::*;
use unexpected::{OutOfBounds, Mismatch};
use client::{Client, EngineClient};
use error::{Error, BlockError};
use header::{Header, BlockNumber};
Expand Down
1 change: 1 addition & 0 deletions ethcore/src/engines/validator_set/safe_contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ use bigint::hash::{H160, H256};
use parking_lot::RwLock;
use util::*;
use util::cache::MemoryLruCache;
use unexpected::Mismatch;
use rlp::{UntrustedRlp, RlpStream};

use basic_types::LogBloom;
Expand Down
5 changes: 3 additions & 2 deletions ethcore/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ use std::fmt;
use bigint::prelude::U256;
use bigint::hash::H256;
use util::*;
use unexpected::{Mismatch, OutOfBounds};
use io::*;
use header::BlockNumber;
use basic_types::LogBloom;
Expand Down Expand Up @@ -394,7 +395,7 @@ impl From<ExecutionError> for Error {

impl From<::rlp::DecoderError> for Error {
fn from(err: ::rlp::DecoderError) -> Error {
Error::Util(UtilError::Decoder(err))
Error::Util(UtilError::from(err))
}
}

Expand Down Expand Up @@ -427,7 +428,7 @@ impl From<BlockImportError> for Error {
match err {
BlockImportError::Block(e) => Error::Block(e),
BlockImportError::Import(e) => Error::Import(e),
BlockImportError::Other(s) => Error::Util(UtilError::SimpleString(s)),
BlockImportError::Other(s) => Error::Util(UtilError::from(s)),
}
}
}
Expand Down
1 change: 1 addition & 0 deletions ethcore/src/ethereum/ethash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ use ethash::{quick_get_difficulty, slow_get_seedhash, EthashManager};
use bigint::prelude::U256;
use bigint::hash::{H256, H64};
use util::*;
use unexpected::{OutOfBounds, Mismatch};
use block::*;
use builtin::Builtin;
use vm::EnvInfo;
Expand Down
1 change: 1 addition & 0 deletions ethcore/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ extern crate heapsize;
extern crate triehash;
extern crate ansi_term;
extern crate semantic_version;
extern crate unexpected;

#[macro_use]
extern crate rlp_derive;
Expand Down
6 changes: 3 additions & 3 deletions ethcore/src/snapshot/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ impl Restoration {
let block_chunks = manifest.block_hashes.iter().cloned().collect();

let raw_db = Arc::new(Database::open(params.db_config, &*params.db_path.to_string_lossy())
.map_err(UtilError::SimpleString)?);
.map_err(UtilError::from)?);

let chain = BlockChain::new(Default::default(), params.genesis, raw_db.clone());
let components = params.engine.snapshot_components()
Expand Down Expand Up @@ -519,7 +519,7 @@ impl Service {

match is_done {
true => {
db.flush().map_err(::util::UtilError::SimpleString)?;
db.flush().map_err(UtilError::from)?;
drop(db);
return self.finalize_restoration(&mut *restoration);
},
Expand All @@ -532,7 +532,7 @@ impl Service {
}
}
};
result.and_then(|_| db.flush().map_err(|e| ::util::UtilError::SimpleString(e).into()))
result.and_then(|_| db.flush().map_err(|e| UtilError::from(e).into()))
}

/// Feed a state chunk to be processed synchronously.
Expand Down
2 changes: 1 addition & 1 deletion ethcore/src/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ impl UnverifiedTransaction {
self.recover_public()?;
}
if self.gas < U256::from(self.gas_required(&schedule)) {
return Err(TransactionError::InvalidGasLimit(::util::OutOfBounds{min: Some(U256::from(self.gas_required(&schedule))), max: None, found: self.gas}).into())
return Err(TransactionError::InvalidGasLimit(::unexpected::OutOfBounds{min: Some(U256::from(self.gas_required(&schedule))), max: None, found: self.gas}).into())
}
Ok(self)
}
Expand Down
2 changes: 2 additions & 0 deletions ethcore/src/verification/verification.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ use triehash::ordered_trie_root;
use heapsize::HeapSizeOf;
use bigint::hash::H256;
use util::*;
use unexpected::{Mismatch, OutOfBounds};
use engines::Engine;
use error::{BlockError, Error};
use blockchain::*;
Expand Down Expand Up @@ -274,6 +275,7 @@ mod tests {
use bigint::prelude::U256;
use bigint::hash::{H256, H2048};
use triehash::ordered_trie_root;
use unexpected::{Mismatch, OutOfBounds};
use util::*;
use ethkey::{Random, Generator};
use header::*;
Expand Down
1 change: 1 addition & 0 deletions util/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ regex = "0.2"
lru-cache = "0.1.0"
ethcore-logger = { path = "../logger" }
triehash = { path = "triehash" }
error-chain = "0.11.0-rc.2"

[features]
default = []
Expand Down
13 changes: 3 additions & 10 deletions util/network/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

use io::IoError;
use rlp::*;
use util::UtilError;
use std::fmt;
use ethkey::Error as KeyError;
use crypto::Error as CryptoError;
Expand Down Expand Up @@ -96,8 +95,8 @@ pub enum NetworkError {
PeerNotFound,
/// Peer is diconnected.
Disconnect(DisconnectReason),
/// Util error.
Util(UtilError),
/// Invalid NodeId
InvalidNodeId,
/// Socket IO error.
Io(IoError),
/// Error concerning the network address parsing subsystem.
Expand Down Expand Up @@ -125,7 +124,7 @@ impl fmt::Display for NetworkError {
AddressResolve(Some(ref err)) => format!("{}", err),
AddressResolve(_) => "Failed to resolve network address.".into(),
StdIo(ref err) => format!("{}", err),
Util(ref err) => format!("{}", err),
InvalidNodeId => "Invalid node id".into(),
OversizedPacket => "Packet is too large".into(),
};

Expand All @@ -151,12 +150,6 @@ impl From<IoError> for NetworkError {
}
}

impl From<UtilError> for NetworkError {
fn from(err: UtilError) -> NetworkError {
NetworkError::Util(err)
}
}

impl From<KeyError> for NetworkError {
fn from(_err: KeyError) -> Self {
NetworkError::Auth
Expand Down
3 changes: 1 addition & 2 deletions util/network/src/node_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ use std::fmt;
use std::fs;
use std::io::{Read, Write};
use bigint::hash::*;
use util::UtilError;
use rlp::*;
use time::Tm;
use error::NetworkError;
Expand Down Expand Up @@ -175,7 +174,7 @@ impl FromStr for Node {
type Err = NetworkError;
fn from_str(s: &str) -> Result<Self, Self::Err> {
let (id, endpoint) = if s.len() > 136 && &s[0..8] == "enode://" && &s[136..137] == "@" {
(s[8..136].parse().map_err(UtilError::from)?, NodeEndpoint::from_str(&s[137..])?)
(s[8..136].parse().map_err(|_| NetworkError::InvalidNodeId)?, NodeEndpoint::from_str(&s[137..])?)
}
else {
(NodeId::new(), NodeEndpoint::from_str(s)?)
Expand Down
Loading