Skip to content

Commit

Permalink
Merge pull request rust-ethereum#177 from paritytech/dp/chore/code-fo…
Browse files Browse the repository at this point in the history
…rmatting

Consistent code formatting
  • Loading branch information
dvdplm authored Jan 16, 2020
2 parents f050562 + 97186ff commit 321cc41
Show file tree
Hide file tree
Showing 36 changed files with 964 additions and 1,095 deletions.
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,10 @@ matrix:
before_script:
- export PATH=$HOME/.cargo/bin:$PATH
- cargo install cargo-travis || echo "cargo-travis already installed"
- rustup component add rustfmt

script:
- cargo fmt --all -- --check
- cargo test

after_success:
Expand Down
102 changes: 48 additions & 54 deletions cli/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,71 +3,65 @@ use std::{fmt, io};
/// Ethabi CLI errors
#[derive(Debug)]
pub enum Error {
/// Invalid signature.
InvalidSignature(ethabi::Hash),
/// Ambiguous event name.
AmbiguousEventName(String),
/// Invalid function signature.
InvalidFunctionSignature(String),
/// Ambiguous function name.
AmbiguousFunctionName(String),
/// ABI error.
Ethabi(ethabi::Error),
/// IO error.
Io(io::Error),
/// Hex parsing error.
Hex(rustc_hex::FromHexError),
/// Invalid signature.
InvalidSignature(ethabi::Hash),
/// Ambiguous event name.
AmbiguousEventName(String),
/// Invalid function signature.
InvalidFunctionSignature(String),
/// Ambiguous function name.
AmbiguousFunctionName(String),
/// ABI error.
Ethabi(ethabi::Error),
/// IO error.
Io(io::Error),
/// Hex parsing error.
Hex(rustc_hex::FromHexError),
}

impl std::error::Error for Error {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
use self::Error::*;
match self {
Ethabi(e) => Some(e),
Io(e) => Some(e),
Hex(e) => Some(e),
_ => None,
}
}
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
use self::Error::*;
match self {
Ethabi(e) => Some(e),
Io(e) => Some(e),
Hex(e) => Some(e),
_ => None,
}
}
}

impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
use self::Error::*;
match *self {
InvalidSignature(ref signature) => write!(f, "Invalid signature `{}`", signature),
AmbiguousEventName(ref name) => write!(
f,
"More than one event found for name `{}`, try providing the full signature",
name
),
InvalidFunctionSignature(ref signature) => {
write!(f, "Invalid function signature `{}`", signature)
}
AmbiguousFunctionName(ref name) => write!(
f,
"More than one function found for name `{}`, try providing the full signature",
name
),
Ethabi(ref err) => write!(f, "Ethabi error: {}", err),
Io(ref err) => write!(f, "IO error: {}", err),
Hex(ref err) => write!(f, "Hex parsing error: {}", err),
}
}
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
use self::Error::*;
match *self {
InvalidSignature(ref signature) => write!(f, "Invalid signature `{}`", signature),
AmbiguousEventName(ref name) => {
write!(f, "More than one event found for name `{}`, try providing the full signature", name)
}
InvalidFunctionSignature(ref signature) => write!(f, "Invalid function signature `{}`", signature),
AmbiguousFunctionName(ref name) => {
write!(f, "More than one function found for name `{}`, try providing the full signature", name)
}
Ethabi(ref err) => write!(f, "Ethabi error: {}", err),
Io(ref err) => write!(f, "IO error: {}", err),
Hex(ref err) => write!(f, "Hex parsing error: {}", err),
}
}
}

impl From<ethabi::Error> for Error {
fn from(err: ethabi::Error) -> Self {
Error::Ethabi(err)
}
fn from(err: ethabi::Error) -> Self {
Error::Ethabi(err)
}
}
impl From<io::Error> for Error {
fn from(err: io::Error) -> Self {
Error::Io(err)
}
fn from(err: io::Error) -> Self {
Error::Io(err)
}
}
impl From<rustc_hex::FromHexError> for Error {
fn from(err: rustc_hex::FromHexError) -> Self {
Error::Hex(err)
}
fn from(err: rustc_hex::FromHexError) -> Self {
Error::Hex(err)
}
}
Loading

0 comments on commit 321cc41

Please sign in to comment.