fuel_core_database/
lib.rs1#![deny(clippy::arithmetic_side_effects)]
8#![deny(clippy::cast_possible_truncation)]
9#![deny(missing_docs)]
10#![deny(unused_crate_dependencies)]
11#![deny(warnings)]
12#![deny(unused_variables)]
13
14use fuel_core_storage::Error as StorageError;
15use fuel_core_types::services::executor::Error as ExecutorError;
16
17#[derive(Debug, derive_more::Display, derive_more::From)]
19#[non_exhaustive]
20#[allow(missing_docs)]
21pub enum Error {
22 #[display(fmt = "error performing serialization or deserialization")]
24 Codec,
25 #[display(
27 fmt = "Invalid database version, expected {expected:#x}, found {found:#x}"
28 )]
29 InvalidDatabaseVersion {
30 found: u32,
32 expected: u32,
34 },
35 #[display(fmt = "Multiple heights found in the commit {heights:?}")]
37 MultipleHeightsInCommit {
38 heights: Vec<u64>,
40 },
41 #[display(fmt = "Failed to advance the height")]
43 FailedToAdvanceHeight,
44 #[display(
46 fmt = "New and old heights are not linked: prev_height: {prev_height:#x}, new_height: {new_height:#x}"
47 )]
48 HeightsAreNotLinked {
49 prev_height: u64,
51 new_height: u64,
53 },
54 #[display(
56 fmt = "The new height is not found, but the old height is set: prev_height: {prev_height:#x}"
57 )]
58 NewHeightIsNotSet {
59 prev_height: u64,
61 },
62 #[display(fmt = "The historical database doesn't have any history yet")]
63 NoHistoryIsAvailable,
64 #[display(
65 fmt = "The historical database doesn't have history for the requested height {requested_height:#x}, \
66 the oldest available height is {oldest_available_height:#x}"
67 )]
68 NoHistoryForRequestedHeight {
69 requested_height: u64,
70 oldest_available_height: u64,
71 },
72 #[display(fmt = "Reached the end of the history")]
73 ReachedEndOfHistory,
74
75 #[cfg(feature = "backup")]
76 #[display(fmt = "BackupEngine initialization error: {}", _0)]
77 BackupEngineInitError(anyhow::Error),
78
79 #[cfg(feature = "backup")]
80 #[display(fmt = "Backup error: {}", _0)]
81 BackupError(anyhow::Error),
82
83 #[cfg(feature = "backup")]
84 #[display(fmt = "Restore error: {}", _0)]
85 RestoreError(anyhow::Error),
86
87 #[from]
89 Other(anyhow::Error),
90}
91
92#[cfg(feature = "test-helpers")]
93impl PartialEq for Error {
94 fn eq(&self, other: &Self) -> bool {
95 self.to_string().eq(&other.to_string())
96 }
97}
98
99impl From<Error> for anyhow::Error {
100 fn from(error: Error) -> Self {
101 anyhow::Error::msg(error)
102 }
103}
104
105impl From<Error> for StorageError {
106 fn from(e: Error) -> Self {
107 StorageError::DatabaseError(Box::new(e))
108 }
109}
110
111impl From<Error> for ExecutorError {
112 fn from(e: Error) -> Self {
113 ExecutorError::StorageError(format!("{}", StorageError::from(e)))
114 }
115}
116
117#[cfg(test)]
118fuel_core_trace::enable_tracing!();