use std::fmt;
use std::error;
use maidsafe_utilities::serialisation;
#[allow(missing_docs)]
#[derive(Debug)]
pub enum Error {
Serialisation(serialisation::SerialisationError),
Crypto,
Validation,
Signature,
Majority,
NoLink,
BadIdentifier,
}
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self {
Error::Serialisation(ref err) => err.fmt(f),
Error::Crypto => write!(f, "Crypto failure."),
Error::Validation => write!(f, "Not enough signatures."),
Error::Signature => write!(f, "Invalid signature."),
Error::Majority => write!(f, "Not enough signatures for validation."),
Error::NoLink => write!(f, "Could not get a valid link."),
Error::BadIdentifier => write!(f, "Invalid identifier type."),
}
}
}
impl error::Error for Error {
fn description(&self) -> &str {
match *self {
Error::Serialisation(ref err) => err.description(),
Error::Crypto => "Crypto failure.",
Error::Validation => "Not enough signatures.",
Error::Signature => "Invalid signature.",
Error::Majority => "Not enough signatures for validation.",
Error::NoLink => "Cold not get a valid link.",
Error::BadIdentifier => "Invalid identifier type.",
}
}
}
impl From<serialisation::SerialisationError> for Error {
fn from(orig_error: serialisation::SerialisationError) -> Self {
Error::Serialisation(orig_error)
}
}
impl From<()> for Error {
fn from(_: ()) -> Self {
Error::Crypto
}
}