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(
63 fmt = "The historical database doesn't have history for the requested height {requested_height:#x}"
64 )]
65 NoHistoryForRequestedHeight { requested_height: u64 },
66 #[display(fmt = "Reached the end of the history")]
67 ReachedEndOfHistory,
68
69 #[cfg(feature = "backup")]
70 #[display(fmt = "BackupEngine initialization error: {}", _0)]
71 BackupEngineInitError(anyhow::Error),
72
73 #[cfg(feature = "backup")]
74 #[display(fmt = "Backup error: {}", _0)]
75 BackupError(anyhow::Error),
76
77 #[cfg(feature = "backup")]
78 #[display(fmt = "Restore error: {}", _0)]
79 RestoreError(anyhow::Error),
80
81 #[from]
83 Other(anyhow::Error),
84}
85
86#[cfg(feature = "test-helpers")]
87impl PartialEq for Error {
88 fn eq(&self, other: &Self) -> bool {
89 self.to_string().eq(&other.to_string())
90 }
91}
92
93impl From<Error> for anyhow::Error {
94 fn from(error: Error) -> Self {
95 anyhow::Error::msg(error)
96 }
97}
98
99impl From<Error> for StorageError {
100 fn from(e: Error) -> Self {
101 StorageError::DatabaseError(Box::new(e))
102 }
103}
104
105impl From<Error> for ExecutorError {
106 fn from(e: Error) -> Self {
107 ExecutorError::StorageError(format!("{}", StorageError::from(e)))
108 }
109}
110
111#[cfg(test)]
112fuel_core_trace::enable_tracing!();