Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update error #11

Merged
merged 3 commits into from
Jan 8, 2016
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
38 changes: 37 additions & 1 deletion src/raft/errors.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,56 @@
use std::{result, io, fmt};
use std::error;

use protobuf::ProtobufError;

#[derive(Debug, Clone)]
#[derive(Debug)]
pub enum Error {
Io(io::Error),
NotFound,
Protobuf(ProtobufError),
Other(String),
}

impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self {
Error::NotFound => write!(f, "not found"),
Error::Io(ref error) => fmt::Display::fmt(error, f),
_ => fmt::Display::fmt(self, f),
}
}
}

impl error::Error for Error {
fn description(&self) -> &str {
match self {
// not sure that cause should be included in message
&Error::Io(ref e) => e.description(),
&Error::NotFound => "not found",
&Error::Protobuf(ref e) => e.description(),
&Error::Other(ref e) => &e,
}
}

fn cause(&self) -> Option<&error::Error> {
match self {
&Error::Io(ref e) => Some(e),
&Error::Protobuf(ref e) => Some(e),
_ => None,
}
}
}

impl From<io::Error> for Error {
fn from(err: io::Error) -> Error {
Error::Io(err)
}
}

impl From<ProtobufError> for Error {
fn from(err: ProtobufError) -> Error {
Error::Protobuf(err)
}
}

pub type Result<T> = result::Result<T, Error>;
4 changes: 2 additions & 2 deletions src/raft/raft_log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ use raft::storage::Storage;


/// Raft log implementation
pub struct RaftLog {
store: Storage,
pub struct RaftLog<T: Storage> {
store: T,
}