casper_storage/global_state/
error.rs

1use std::sync;
2
3use thiserror::Error;
4
5use casper_types::{bytesrepr, Digest, Key};
6
7use crate::global_state::{state::CommitError, trie::TrieRaw};
8
9use super::trie_store::TrieStoreCacheError;
10
11/// Error enum representing possible errors in global state interactions.
12#[derive(Debug, Clone, Error, PartialEq, Eq)]
13#[non_exhaustive]
14pub enum Error {
15    /// LMDB error returned from underlying `lmdb` crate.
16    #[error(transparent)]
17    Lmdb(#[from] lmdb::Error),
18
19    /// (De)serialization error.
20    #[error("{0}")]
21    BytesRepr(#[from] bytesrepr::Error),
22
23    /// Concurrency error.
24    #[error("Another thread panicked while holding a lock")]
25    Poison,
26
27    /// Error committing to execution engine.
28    #[error(transparent)]
29    Commit(#[from] CommitError),
30
31    /// Invalid state root hash.
32    #[error("RootNotFound")]
33    RootNotFound,
34
35    /// Failed to put a trie node into global state because some of its children were missing.
36    #[error("Failed to put a trie into global state because some of its children were missing")]
37    MissingTrieNodeChildren(Digest, TrieRaw, Vec<Digest>),
38
39    /// Failed to prune listed keys.
40    #[error("Pruning attempt failed.")]
41    FailedToPrune(Vec<Key>),
42
43    /// Cannot provide proofs over working state in a cache (programmer error).
44    #[error("Attempt to generate proofs using non-empty cache.")]
45    CannotProvideProofsOverCachedData,
46
47    /// Encountered a cache error.
48    #[error("Cache error")]
49    CacheError(#[from] TrieStoreCacheError),
50}
51
52impl<T> From<sync::PoisonError<T>> for Error {
53    fn from(_error: sync::PoisonError<T>) -> Self {
54        Error::Poison
55    }
56}