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
39
40
use anyhow;
use glob;
use std::io;
use std::path::PathBuf;
use thiserror::Error;

/// The result of any operation.
pub type Result<T> = ::std::result::Result<T, TinkvError>;

/// The kind of error that could be produced during tinkv operation.
#[derive(Error, Debug)]
pub enum TinkvError {
    #[error(transparent)]
    Io(#[from] io::Error),
    #[error(transparent)]
    Glob(#[from] glob::GlobError),
    #[error(transparent)]
    Pattern(#[from] glob::PatternError),
    #[error(transparent)]
    Codec(#[from] Box<bincode::ErrorKind>),
    /// Custom error definitions.
    #[error("crc check failed, data entry (key='{}', file_id={}, offset={}) was corrupted", String::from_utf8_lossy(.key), .file_id, .offset)]
    DataEntryCorrupted {
        file_id: u64,
        key: Vec<u8>,
        offset: u64,
    },
    #[error("key '{}' not found", String::from_utf8_lossy(.0))]
    KeyNotFound(Vec<u8>),
    #[error("file '{}' is not writeable", .0.display())]
    FileNotWriteable(PathBuf),
    #[error("key is too large")]
    KeyIsTooLarge,
    #[error("value is too large")]
    ValueIsTooLarge,
    #[error("{}", .0)]
    Custom(String),
    #[error(transparent)]
    Other(#[from] anyhow::Error),
}