<commit_before>use std::error;
use std::boxed::Box;
use std::result;

pub type Error = Box<error::Error + Send + Sync>;

pub type Result<T> = result::Result<T, Error>;

pub fn other<T>(err: T) -> Error
    where T: Into<Box<error::Error + Sync + Send + 'static>>
{
    err.into()
}<commit_msg>raftserver: use quick error for raft server error.<commit_after>use std::error;
use std::boxed::Box;
use std::result;
use std::io;
use std::net;
use std::vec::Vec;

use protobuf::ProtobufError;

use util::codec;
use pd;
use raft;
use proto::metapb;

quick_error!{
    #[derive(Debug)]
    pub enum Error {
        RegionNotFound(region_id:u64) {
            description("region is not found")
            display("region {} not found", region_id)
        }
        NotLeader(region_id: u64, leader:Option<metapb::Peer>) {
            description("peer is not leader")
            display("peer is not leader for region {}, leader may {:?}", region_id, leader)
        }
        KeyNotInRegion(key: Vec<u8>, region: metapb::Region) {
            description("key is not in region")
            display("key {:?} is not in region key range [{:?}, {:?}) for region {}",
                key, region.get_start_key(), region.get_end_key(), region.get_region_id())
        }
        Other(err: Box<error::Error + Sync + Send>) {
            cause(err.as_ref())
            description(err.description())
            display("{:?}", err)
        }

        // Following is for From other errors.
        Io(err: io::Error) {
            from()
            cause(err)
            description(err.description())
        }
        // RocksDB uses plain string as the error.
        // Maybe other libs use this too?
        RocksDB(msg: String) {
            from()
            description("RocksDB error")
            display("{}", msg)
        }
        Protobuf(err: ProtobufError) {
            from()
            cause(err)
            description(err.description())
        }
        Codec(err: codec::Error) {
            from()
            cause(err)
            description(err.description())
        }
        AddrParse(err: net::AddrParseError) {
            from()
            cause(err)
            description(err.description())
        }
        Pd(err: pd::Error) {
            from()
            cause(err)
            description(err.description())
        }
        Raft(err: raft::Error) {
            from()
            cause(err)
            description(err.description())
        }
    }
}


pub type Result<T> = result::Result<T, Error>;

pub fn other<T>(err: T) -> Error
    where T: Into<Box<error::Error + Sync + Send + 'static>>
{
    Error::Other(err.into())
}
{'fraction_non_alphanumeric': 0.1430175964058405, 'fraction_numerical': 0.0018719580681392737, 'mean_word_length': 2.0260475651189127, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7357960', 'n_tokens_mistral': 805, 'n_tokens_neox': 790, 'n_words': 192}