chia_datalayer/merkle/
error.rs1use crate::{Hash, InternalNode, KeyId, TreeIndex};
2use thiserror::Error;
3
4#[cfg_attr(feature = "py-bindings", derive(chia_datalayer_macro::PythonError))]
5#[derive(Debug, Error)]
6pub enum Error {
7 #[error("IO error: {0}")]
8 Io(#[from] std::io::Error),
9 #[error("failed loading metadata: {0}")]
10 FailedLoadingMetadata(chia_traits::chia_error::Error),
11 #[error("failed loading node: {0}")]
12 FailedLoadingNode(chia_traits::chia_error::Error),
13 #[error("blob length must be a multiple of block count, found extra bytes: {0}")]
14 InvalidBlobLength(usize),
15 #[error("key already present")]
16 KeyAlreadyPresent(),
17 #[error("hash already present")]
18 HashAlreadyPresent(),
19 #[error("requested insertion at root but tree not empty")]
20 UnableToInsertAsRootOfNonEmptyTree(),
21 #[error("unable to find a leaf")]
22 UnableToFindALeaf(),
23 #[error("unknown key: {0:?}")]
24 UnknownKey(KeyId),
25 #[error("key not in key to index cache: {0:?}")]
26 IntegrityKeyNotInCache(KeyId),
27 #[error("key to index cache for {0:?} should be {1:?} got: {2:?}")]
28 IntegrityKeyToIndexCacheIndex(KeyId, TreeIndex, TreeIndex),
29 #[error("parent and child relationship mismatched: {0:?}")]
30 IntegrityParentChildMismatch(TreeIndex),
31 #[error("found {0:?} leaves but key to index cache length is: {1}")]
32 IntegrityKeyToIndexCacheLength(usize, usize),
33 #[error("found {0:?} leaves but leaf hash to index cache length is: {1}")]
34 IntegrityLeafHashToIndexCacheLength(usize, usize),
35 #[error("unmatched parent -> child references found: {0}")]
36 IntegrityUnmatchedChildParentRelationships(usize),
37 #[error("expected total node count {0:?} found: {1:?}")]
38 IntegrityTotalNodeCount(TreeIndex, usize),
39 #[error("zero-length seed bytes not allowed")]
40 ZeroLengthSeedNotAllowed(),
41 #[error("node not a leaf: {0:?}")]
42 NodeNotALeaf(InternalNode),
43 #[error("from streamable: {0:?}")]
44 Streaming(chia_traits::chia_error::Error),
45 #[error("index not a child: {0}")]
46 IndexIsNotAChild(TreeIndex),
47 #[error("cycle found")]
48 CycleFound(),
49 #[error("recursion depth exceeded while building merkle blob (max=64)")]
50 RecursionDepthExceeded(),
51 #[error("block index out of bounds: {0}")]
52 BlockIndexOutOfBounds(TreeIndex),
53 #[error("leaf hash not found: {0:?}")]
54 LeafHashNotFound(Hash),
55 #[error("root hash and node list disagreement")]
56 RootHashAndNodeListDisagreement(),
57 #[error("node hash not in nodes: {0:?}")]
58 NodeHashNotInNodeMaps(Hash),
59 #[error("move source index not in use: {0:?}")]
60 MoveSourceIndexNotInUse(TreeIndex),
61 #[error("move destination index not in use: {0:?}")]
62 MoveDestinationIndexNotInUse(TreeIndex),
63 #[error("must specify neither or both of reference_kid and side")]
64 IncompleteInsertLocationParameters(),
65 #[error("hash is dirty for index: {0:?}")]
66 Dirty(TreeIndex),
67 #[error("hash is dirty for leaf index: {0:?}")]
68 DirtyLeaf(TreeIndex),
69 #[error("key/value and hash collection lengths must match: {0:?} keys/values, {0:?} hashes")]
70 UnmatchedKeysAndValues(usize, usize),
71 #[error("hash not found: {0:?}")]
72 HashNotFound(Hash),
73 #[error("reference to unknown parent")]
74 ReferenceToUnknownParent(),
75 #[error("root has parent")]
76 RootHasParent(),
77 #[error("unexpected parentless node")]
78 UnexpectedParentlessNode(),
79 #[error("child's parent disclaims the child")]
80 ParentDisagreesWithChild(),
81 #[error("leaf cannot be parent")]
82 LeafCannotBeParent(),
83 #[error("invalid children")]
84 InvalidChildren(),
85 #[error("insert subtree requires reference leaf is not root")]
86 LeafCannotBeRootWhenInsertingSubtree(),
87}