raft_engine/
errors.rs

1// Copyright (c) 2017-present, PingCAP, Inc. Licensed under Apache-2.0.
2
3use std::error;
4use std::io::Error as IoError;
5
6use thiserror::Error;
7
8use crate::codec::Error as CodecError;
9
10#[derive(Debug, Error)]
11pub enum Error {
12    #[error("Invalid Argument: {0}")]
13    InvalidArgument(String),
14    #[error("Corruption: {0}")]
15    Corruption(String),
16    #[error("IO Error: {0:?}")]
17    Io(#[from] IoError),
18    #[error("Codec Error: {0}")]
19    Codec(#[from] CodecError),
20    #[error("Protobuf Error: {0}")]
21    Protobuf(#[from] protobuf::ProtobufError),
22    #[error("TryAgain Error: {0}")]
23    TryAgain(String),
24    #[error("Entry Compacted")]
25    EntryCompacted,
26    #[error("Entry Not Found")]
27    EntryNotFound,
28    #[error("Full")]
29    Full,
30    #[error("Other Error: {0}")]
31    Other(#[from] Box<dyn error::Error + Send + Sync>),
32}
33
34pub type Result<T> = ::std::result::Result<T, Error>;
35
36/// Check whether the given error is a nospace error.
37pub(crate) fn is_no_space_err(e: &IoError) -> bool {
38    // TODO: make the following judgement more elegant when the error type
39    // `ErrorKind::StorageFull` is stable.
40    format!("{e}").contains("nospace")
41}