bloock_smt/error.rs
1//! # Error management
2//!
3//! This module contains all the possible error types that this crate can output.
4//! This are:
5//! * `CorruptedData`: used whenever a node is read with no coherent data.
6//! * `Datastorage`: used whenever there is an issue executing task in the datastorage.
7//! * `FailedMerge`: informs that a merge between 2 keys was not possible.
8//! * `IllogicalState`: the library reaches a state in which it does not have any way to
9//! recover nor proceed.
10//! * `NoLeavesProvided`: used to inform that a function that requires at least one leaf
11//! was provided with None.
12//! * `NotFound`: used to inform that some critical node was not found in the datastorage.
13//! * `ProofAssemblyError`: informs that some node was not found inside the main proof,
14//! hence the proof assembly process is no longer allowed to proceed.
15//!
16
17use bloock_storage::error::StorageError;
18use bloock_types::error::TypeError;
19use thiserror::Error;
20
21#[derive(Error, Debug, PartialEq)]
22pub enum SmtError {
23 /// Used whenever a node is read with no coherent data.
24 #[error("Conversion error from \"(key, value)\" to Node for key \"{key:?}\". Fail condition: \"{condition}\".")]
25 CorruptedData { key: String, condition: String },
26 #[error("Error while working with keys at byte level: ")]
27 ByteLevelError(#[from] TypeError),
28 /// Used whenever there is an issue executing task in the datastorage.
29 #[error("Datastorage error: ")]
30 Datastorage(#[from] StorageError),
31 /// Informs that a merge between 2 keys was not possible.
32 #[error("Failed to merge 2 keys.")]
33 FailedMerge { error: String },
34 /// The library reaches a state in which it does not have any way to
35 /// recover nor proceed.
36 #[error(
37 "The execution halted due reaching a illogical state of the tree. Reason: {failstate:?}"
38 )]
39 IllogicalState { failstate: String },
40 /// Informs that a function that requires at least one leaf was provided with None.
41 #[error("No leaves where passed to function \"{function}\" at node \"{key_option}\".")]
42 NoLeavesProvided {
43 function: String,
44 key_option: String,
45 },
46 /// Informs that some critical node was not found in the datastorage.
47 #[error("The node with key \"{key:?}\" is not in the db.")]
48 NotFound { key: String },
49 /// Informs that some node was not found inside the main proof,
50 /// hence the proof assembly process is no longer allowed to proceed.
51 #[error("Unable to assemble the proofs.")]
52 ProofAssemblyError { error: String },
53}