use std::error::Error;
use std::fmt::{self, Display, Formatter};
#[derive(Debug, Clone, Eq, PartialEq, Ord, PartialOrd, Hash, RustcEncodable, RustcDecodable)]
pub enum GetError {
NoSuchAccount,
NoSuchData,
NetworkOther(String),
}
impl Display for GetError {
fn fmt(&self, formatter: &mut Formatter) -> fmt::Result {
match *self {
GetError::NoSuchAccount => write!(formatter, "Account does not exist for client"),
GetError::NoSuchData => write!(formatter, "Requested data not found"),
GetError::NetworkOther(ref error) => {
write!(formatter, "Error on Vault network: {}", error)
}
}
}
}
impl Error for GetError {
fn description(&self) -> &str {
match *self {
GetError::NoSuchAccount => "No such account",
GetError::NoSuchData => "No such data",
GetError::NetworkOther(ref error) => error,
}
}
}
#[derive(Debug, Clone, Eq, PartialEq, Ord, PartialOrd, Hash, RustcEncodable, RustcDecodable)]
pub enum MutationError {
NoSuchAccount,
AccountExists,
NoSuchData,
DataExists,
LowBalance,
InvalidSuccessor,
InvalidOperation,
NetworkFull,
NetworkOther(String),
}
impl Display for MutationError {
fn fmt(&self, formatter: &mut Formatter) -> fmt::Result {
match *self {
MutationError::NoSuchAccount => write!(formatter, "Account does not exist for client"),
MutationError::AccountExists => write!(formatter, "Account already exists for client"),
MutationError::NoSuchData => write!(formatter, "Requested data not found"),
MutationError::DataExists => write!(formatter, "Data given already exists"),
MutationError::LowBalance => {
write!(formatter, "Insufficient account balance for this operation")
}
MutationError::InvalidSuccessor => {
write!(formatter,
"Data given is not a valid successor of stored data")
}
MutationError::InvalidOperation => {
write!(formatter, "Requested operation is not allowed")
}
MutationError::NetworkFull => {
write!(formatter, "Network cannot store any further data")
}
MutationError::NetworkOther(ref error) => {
write!(formatter, "Error on Vault network: {}", error)
}
}
}
}
impl Error for MutationError {
fn description(&self) -> &str {
match *self {
MutationError::NoSuchAccount => "No such account",
MutationError::AccountExists => "Account exists",
MutationError::NoSuchData => "No such data",
MutationError::DataExists => "Data exists",
MutationError::LowBalance => "Low account balance",
MutationError::InvalidSuccessor => "Invalid data successor",
MutationError::InvalidOperation => "Invalid operation",
MutationError::NetworkFull => "Network full",
MutationError::NetworkOther(ref error) => error,
}
}
}