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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
use super::prelude::*;
use thiserror::Error;

/// Error type
#[derive(Debug, Error)]
pub enum ToolsError {
    /// Failed to validate record header
    #[error("record header validation error: {0}")]
    RecordHeaderValidation(String),
    /// Failed to validate index header
    #[error("index header validation error: {0}")]
    IndexHeaderValidation(String),
    /// Failed to validate index
    #[error("index validation error: {0}")]
    IndexValidation(String),
    /// Failed to validate blob header
    #[error("blob header validation error: {0}")]
    BlobHeaderValidation(String),
    /// Failed to validate record
    #[error("record validation error: {0}")]
    RecordValidation(String),
    /// Skip wrong record is not possible
    #[error("skip data error: {0}")]
    SkipRecordData(String),
    /// Can't migrate blob
    #[error("unsupported migration from {0} to {1}")]
    UnsupportedMigration(u32, u32),
    /// Key size is not supported
    #[error("key size is not supported by this build")]
    UnsupportedKeySize(u16),
}

impl ToolsError {
    pub(crate) fn record_header_validation_error(message: impl Into<String>) -> Self {
        Self::RecordHeaderValidation(message.into())
    }

    pub(crate) fn index_header_validation_error(message: impl Into<String>) -> Self {
        Self::IndexHeaderValidation(message.into())
    }

    pub(crate) fn blob_header_validation_error(message: impl Into<String>) -> Self {
        Self::BlobHeaderValidation(message.into())
    }

    pub(crate) fn record_validation_error(message: impl Into<String>) -> Self {
        Self::RecordValidation(message.into())
    }

    pub(crate) fn skip_record_data_error(message: impl Into<String>) -> Self {
        Self::SkipRecordData(message.into())
    }

    pub(crate) fn unsupported_migration(from: u32, to: u32) -> Self {
        Self::UnsupportedMigration(from, to)
    }

    pub(crate) fn unsupported_key_size(size: u16) -> Self {
        Self::UnsupportedKeySize(size)
    }
}