exocore_chain/chain/
error.rs1use crate::block::BlockOffset;
2
3#[derive(Debug, thiserror::Error)]
4pub enum Error {
5 #[error("Block related error: {0}")]
6 Block(#[from] crate::block::Error),
7
8 #[error("The store is in an unexpected state: {0}")]
9 UnexpectedState(#[source] anyhow::Error),
10
11 #[error("The store has an integrity problem: {0}")]
12 Integrity(#[source] anyhow::Error),
13
14 #[error("Tried to write a block at offset {offset}, but next offset was {expected_offset}")]
15 InvalidNextBlock {
16 offset: BlockOffset,
17 expected_offset: BlockOffset,
18 },
19
20 #[error("Error in capnp serialization: {0}")]
21 Serialization(#[from] exocore_protos::capnp::Error),
22
23 #[error("An offset is out of the chain data: {0}")]
24 OutOfBound(#[source] anyhow::Error),
25
26 #[error("IO error of kind {0}: {1}")]
27 Io(std::io::Error, String),
28
29 #[cfg(feature = "directory-chain")]
30 #[error("Error in directory chain store: {0}")]
31 DirectoryError(#[from] super::directory::DirectoryError),
32
33 #[error("Try to lock a mutex that was poisoned")]
34 Poisoned,
35
36 #[error(transparent)]
37 Other(#[from] anyhow::Error),
38}
39
40impl Error {
41 pub fn is_fatal(&self) -> bool {
42 matches!(
43 self,
44 Error::UnexpectedState(_) | Error::Integrity(_) | Error::Io(_, _)
45 )
46 }
47
48 pub fn new_io<S: Into<String>>(io: std::io::Error, msg: S) -> Error {
49 Error::Io(io, msg.into())
50 }
51}
52
53impl<T> From<std::sync::PoisonError<T>> for Error {
54 fn from(_err: std::sync::PoisonError<T>) -> Self {
55 Error::Poisoned
56 }
57}