exocore_chain/engine/
error.rs1#[derive(Debug, thiserror::Error)]
3pub enum EngineError {
4 #[error("Error in transport: {0:?}")]
5 Transport(#[from] exocore_transport::Error),
6
7 #[error("Error in pending store: {0:?}")]
8 PendingStore(#[from] crate::pending::Error),
9
10 #[error("Error in chain store: {0:?}")]
11 ChainStore(#[from] crate::chain::Error),
12
13 #[error("Error in pending synchronizer: {0:?}")]
14 PendingSync(#[from] crate::engine::pending_sync::PendingSyncError),
15
16 #[error("Error in chain synchronizer: {0:?}")]
17 ChainSync(#[from] crate::engine::chain_sync::ChainSyncError),
18
19 #[error("Error in commit manager: {0:?}")]
20 CommitManager(#[from] crate::engine::commit_manager::CommitManagerError),
21
22 #[error("Got a block related error: {0:?}")]
23 Block(#[from] crate::block::Error),
24
25 #[error("Got an operation related error: {0:?}")]
26 Operation(#[from] crate::operation::Error),
27
28 #[error("Out of sync with the rest of cluster")]
29 OutOfSync,
30
31 #[error("Chain is not initialized")]
32 UninitializedChain,
33
34 #[error("Error in capnp serialization: {0}")]
35 Serialization(#[from] exocore_protos::capnp::Error),
36
37 #[error("Field is not in capnp schema: code={0}")]
38 SerializationNotInSchema(u16),
39
40 #[error("Local node not found in nodes list")]
41 MyNodeNotFound,
42
43 #[error("Node not found in cell: {0}")]
44 NodeNotFound(exocore_core::cell::NodeId),
45
46 #[error("Inner was dropped or couldn't get locked")]
47 InnerUpgrade,
48
49 #[error("Try to lock a mutex that was poisoned")]
50 Poisoned,
51
52 #[error("A fatal error occurred: {0}")]
53 Fatal(#[source] anyhow::Error),
54
55 #[error(transparent)]
56 Other(#[from] anyhow::Error),
57}
58
59impl EngineError {
60 pub fn is_fatal(&self) -> bool {
61 match self {
62 EngineError::ChainStore(inner) => inner.is_fatal(),
63 EngineError::ChainSync(inner) => inner.is_fatal(),
64 EngineError::MyNodeNotFound
65 | EngineError::InnerUpgrade
66 | EngineError::Poisoned
67 | EngineError::Fatal(_) => true,
68 _ => false,
69 }
70 }
71
72 pub fn recover_non_fatal_error(self) -> Result<(), EngineError> {
73 if !self.is_fatal() {
74 Ok(())
75 } else {
76 Err(self)
77 }
78 }
79}
80
81impl<T> From<std::sync::PoisonError<T>> for EngineError {
82 fn from(_err: std::sync::PoisonError<T>) -> Self {
83 EngineError::Poisoned
84 }
85}
86
87impl From<exocore_protos::capnp::NotInSchema> for EngineError {
88 fn from(err: exocore_protos::capnp::NotInSchema) -> Self {
89 EngineError::SerializationNotInSchema(err.0)
90 }
91}