1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
// Copyright 2020 TiKV Project Authors. Licensed under Apache-2.0.

use super::ErrorCodeExt;
use raft::Error;

define_error_codes!(
    "KV:Raft:",

    IO => ("Io", "", ""),
    STORE => ("Store", "", ""),
    STEP_LOCAL_MSG => ("StepLocalMsg", "", ""),
    STEP_PEER_NOT_FOUND => ("StepPeerNotFound", "", ""),
    PROPOSAL_DROPPED => ("ProposalDropped", "", ""),
    CONFIG_INVALID => ("ConfigInvalid", "", ""),
    CODEC_ERROR => ("CodecError", "", ""),
    EXISTS => ("Exists", "", ""),
    NOT_EXISTS => ("NotExists", "", ""),
    REQUEST_SNAPSHOT_DROPPED => ("RequestSnapshotDropped", "", ""),
    CONF_CHANGE_ERROR => ("ConfChangeError", "", "")
);

impl ErrorCodeExt for Error {
    fn error_code(&self) -> ErrorCode {
        match self {
            Error::Io(_) => IO,
            Error::Store(_) => STORE,
            Error::StepLocalMsg => STEP_LOCAL_MSG,
            Error::StepPeerNotFound => STEP_PEER_NOT_FOUND,
            Error::ProposalDropped => PROPOSAL_DROPPED,
            Error::ConfigInvalid(_) => CONFIG_INVALID,
            Error::CodecError(_) => CODEC_ERROR,
            Error::Exists { .. } => EXISTS,
            Error::NotExists { .. } => NOT_EXISTS,
            Error::RequestSnapshotDropped => REQUEST_SNAPSHOT_DROPPED,
            Error::ConfChangeError(_) => CONF_CHANGE_ERROR,
        }
    }
}