cfx_db_errors/
storage.rs

1// Copyright 2019 Conflux Foundation. All rights reserved.
2// Conflux is free software and distributed under GNU General Public License.
3// See http://www.gnu.org/licenses/
4
5use primitives::account::AccountError;
6use std::{io, num};
7use thiserror::Error;
8type DeltaMptId = u16;
9
10#[derive(Debug, Error)]
11pub enum Error {
12    #[error(transparent)]
13    Account(#[from] AccountError),
14
15    #[error(transparent)]
16    Io(#[from] io::Error),
17
18    #[error(transparent)]
19    IntegerConversionError(#[from] std::num::TryFromIntError),
20
21    #[error(transparent)]
22    ParseIntError(#[from] num::ParseIntError),
23
24    #[error(transparent)]
25    RlpDecodeError(#[from] rlp::DecoderError),
26
27    #[error(transparent)]
28    SqliteError(#[from] sqlite::Error),
29
30    #[error(transparent)]
31    StrfmtFmtError(#[from] strfmt::FmtError),
32
33    #[error("Out of capacity")]
34    OutOfCapacity,
35
36    #[error("Out of memory.")]
37    OutOfMem,
38
39    #[error("Slab: invalid position accessed")]
40    SlabKeyError,
41
42    #[error("Key not found.")]
43    MPTKeyNotFound,
44
45    #[error("Invalid key length {length}. length must be within [1, {length_limit}].")]
46    MPTInvalidKeyLength { length: usize, length_limit: usize },
47
48    #[error("Invalid value length {length}. Length must be less than {length_limit}")]
49    MPTInvalidValueLength { length: usize, length_limit: usize },
50
51    #[error("Too many nodes.")]
52    MPTTooManyNodes,
53
54    #[error("State commit called before computing Merkle hash.")]
55    StateCommitWithoutMerkleHash,
56
57    #[error("Not allowed to operate on an readonly empty db.")]
58    DbNotExist,
59
60    // TODO(yz): add error details.
61    #[error("Unexpected result from db query.")]
62    DbValueError,
63
64    #[error("Db is unclean.")]
65    DbIsUnclean,
66
67    #[error("Failed to create new snapshot by COW. Use XFS on linux or APFS on Mac.")]
68    SnapshotCowCreation,
69
70    #[error("Failed to copy a snapshot.")]
71    SnapshotCopyFailure,
72
73    #[error("Snapshot file not found.")]
74    SnapshotNotFound,
75
76    #[error("Attempting to create or modify a Snapshot which already exists.")]
77    SnapshotAlreadyExists,
78
79    #[error("Trie node not found when loading Snapshot MPT.")]
80    SnapshotMPTTrieNodeNotFound,
81
82    #[error("Too many Delta MPTs created ({}).", DeltaMptId::max_value())]
83    TooManyDeltaMPT,
84
85    #[error("Attempting to create a Delta MPT which already exists.")]
86    DeltaMPTAlreadyExists,
87
88    #[error("Can't find requested Delta MPT in registry.")]
89    DeltaMPTEntryNotFound,
90
91    #[error(
92        "Error(s) happened in Delta MPT destroy, error_1: {e1:?}, error_2: {e2:?}"
93    )]
94    DeltaMPTDestroyErrors {
95        e1: Option<Box<Error>>,
96        e2: Option<Box<Error>>,
97    },
98
99    #[error(
100        "The operation \"{0}\" isn't possible on freshly synced snapshot."
101    )]
102    UnsupportedByFreshlySyncedSnapshot(&'static str),
103
104    #[error("Trie proof is invalid.")]
105    InvalidTrieProof,
106
107    #[error("Snapshot sync proof is invalid")]
108    InvalidSnapshotSyncProof,
109
110    #[error("Failed to create unit test data dir.")]
111    FailedToCreateUnitTestDataDir,
112
113    #[error("Thread panicked with message {0:?}.")]
114    ThreadPanicked(String),
115
116    #[error("Error from std::sync::mpsc.")]
117    MpscError,
118
119    #[error(
120        "tokio::sync::Semaphore::try_acquire(): the semaphore is unavailable."
121    )]
122    SemaphoreTryAcquireError,
123
124    #[error(
125        "tokio::sync::Semaphore::acquire(): the semaphore is unavailable."
126    )]
127    SemaphoreAcquireError,
128
129    #[error("{0}")]
130    Msg(String),
131}
132
133pub type Result<T> = std::result::Result<T, Error>;
134
135impl From<String> for Error {
136    fn from(e: String) -> Self { Error::Msg(e) }
137}
138impl From<&str> for Error {
139    fn from(e: &str) -> Self { Error::Msg(e.into()) }
140}