//! General error types for use in ethcore. use rustc_serialize::hex::FromHexError; use network::NetworkError; use rlp::DecoderError; use io; #[derive(Debug)] pub enum BaseDataError { NegativelyReferencedHash, } #[derive(Debug)] /// General error type which should be capable of representing all errors in ethcore. pub enum UtilError { Crypto(::crypto::CryptoError), StdIo(::std::io::Error), Io(io::IoError), AddressParse(::std::net::AddrParseError), AddressResolve(Option<::std::io::Error>), FromHex(FromHexError), BaseData(BaseDataError), Network(NetworkError), Decoder(DecoderError), BadSize, } impl From for UtilError { fn from(err: FromHexError) -> UtilError { UtilError::FromHex(err) } } impl From for UtilError { fn from(err: BaseDataError) -> UtilError { UtilError::BaseData(err) } } impl From for UtilError { fn from(err: NetworkError) -> UtilError { UtilError::Network(err) } } impl From<::std::io::Error> for UtilError { fn from(err: ::std::io::Error) -> UtilError { UtilError::StdIo(err) } } impl From for UtilError { fn from(err: io::IoError) -> UtilError { UtilError::Io(err) } } impl From<::crypto::CryptoError> for UtilError { fn from(err: ::crypto::CryptoError) -> UtilError { UtilError::Crypto(err) } } impl From<::std::net::AddrParseError> for UtilError { fn from(err: ::std::net::AddrParseError) -> UtilError { UtilError::AddressParse(err) } } impl From<::rlp::DecoderError> for UtilError { fn from(err: ::rlp::DecoderError) -> UtilError { UtilError::Decoder(err) } } // TODO: uncomment below once https://github.com/rust-lang/rust/issues/27336 sorted. /*#![feature(concat_idents)] macro_rules! assimilate { ($name:ident) => ( impl From for Error { fn from(err: concat_idents!($name, Error)) -> Error { Error:: $name (err) } } ) } assimilate!(FromHex); assimilate!(BaseData);*/