1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
//! Error types for mantaray operations.
use std::sync::Arc;
use nectar_primitives::chunk::ChunkAddress;
use nectar_primitives::error::PrimitivesError;
/// Result type alias for mantaray operations.
pub type Result<T> = std::result::Result<T, MantarayError>;
/// Errors that can occur during mantaray trie operations.
#[derive(thiserror::Error, Debug)]
pub enum MantarayError {
/// Node is not a value type (has no entry).
#[error("not a value type")]
NotValueType,
/// No fork found for node with the given reference.
#[error("no fork found for node: {}", reference.map_or_else(|| "<none>".to_string(), |a| a.to_string()))]
NoForkFound {
/// Reference of the node.
reference: Option<ChunkAddress>,
},
/// No entry found for node with the given reference.
#[error("no entry found for node: {}", reference.map_or_else(|| "<none>".to_string(), |a| a.to_string()))]
NoEntryFound {
/// Reference of the node.
reference: Option<ChunkAddress>,
},
/// Entry size does not match expected reference byte size.
#[error("entry size mismatch: expected {expected}, got {actual}")]
EntrySizeMismatch {
/// Expected size.
expected: usize,
/// Actual size.
actual: usize,
},
/// Path cannot be empty for this operation.
#[error("empty path")]
EmptyPath,
/// Prefix not found in path.
#[error("path prefix not found: {prefix}")]
PathPrefixNotFound {
/// The prefix that was not found.
prefix: String,
},
/// Data is too short to contain a valid header.
#[error("data too short for header")]
DataTooShort,
/// Version hash does not match any known version.
#[error("invalid version hash")]
InvalidVersionHash,
/// Fork data has insufficient bytes.
#[error("insufficient fork bytes: expected {expected}, got {actual} at byte {byte_index}")]
InsufficientForkBytes {
/// Expected number of bytes.
expected: usize,
/// Actual number of bytes.
actual: usize,
/// Byte index of the fork.
byte_index: usize,
},
/// Reference is too long.
#[error("reference too long: max {max}, got {actual}")]
RefTooLong {
/// Maximum allowed length.
max: usize,
/// Actual length.
actual: usize,
},
/// Metadata exceeds maximum allowed size.
#[error("metadata too large: max {max}, got {actual}")]
MetadataTooLarge {
/// Maximum allowed size.
max: usize,
/// Actual size.
actual: usize,
},
/// Prefix length is invalid.
#[error("invalid prefix length: max {max}, got {actual}")]
InvalidPrefixLength {
/// Maximum allowed length.
max: usize,
/// Actual length.
actual: usize,
},
/// Metadata could not be parsed.
#[error("invalid metadata: {message}")]
InvalidMetadata {
/// Description of the error.
message: String,
},
/// Node has not been saved yet (reference is empty).
#[error("missing reference")]
MissingReference,
/// Error from primitives (chunk creation, BMT, etc.).
#[error(transparent)]
Primitives(#[from] PrimitivesError),
/// Error from the typed chunk store during get operations.
#[error("store get error: {source}")]
StoreGet {
/// Original store error, preserved for downcasting.
source: Arc<dyn std::error::Error + Send + Sync>,
},
/// Error from the typed chunk store during put operations.
#[error("store put error: {source}")]
StorePut {
/// Original store error, preserved for downcasting.
source: Arc<dyn std::error::Error + Send + Sync>,
},
}