commonware_storage/qmdb/sync/
error.rs1use crate::{
4 merkle::{Family, Location},
5 qmdb::sync::Target,
6};
7use commonware_cryptography::Digest;
8
9#[derive(Debug, thiserror::Error)]
10pub enum EngineError<F: Family, D: Digest> {
11 #[error("root digest mismatch - expected {expected:?}, got {actual:?}")]
13 RootMismatch { expected: D, actual: D },
14 #[error("compact proof failed verification")]
16 InvalidProof,
17 #[error("unexpected compact leaf count - expected {expected}, got {actual}")]
19 UnexpectedLeafCount {
20 expected: Location<F>,
21 actual: Location<F>,
22 },
23 #[error("invalid compact target: {0}")]
25 InvalidCompactTarget(&'static str),
26 #[error("invalid bounds: lower bound {lower_bound_pos} > upper bound {upper_bound_pos}")]
28 InvalidTarget {
29 lower_bound_pos: Location<F>,
30 upper_bound_pos: Location<F>,
31 },
32 #[error("invalid client state")]
34 InvalidState,
35 #[error("sync target root unchanged")]
37 SyncTargetRootUnchanged,
38 #[error("sync target moved backward: {old:?} -> {new:?}")]
40 SyncTargetMovedBackward {
41 old: Target<F, D>,
42 new: Target<F, D>,
43 },
44 #[error("sync already completed")]
46 AlreadyComplete,
47 #[error("sync stalled - no pending fetches")]
49 SyncStalled,
50 #[error("sync finish signal channel closed before finish was requested")]
52 FinishChannelClosed,
53 #[error("error extracting pinned nodes: {0}")]
55 PinnedNodes(String),
56}
57
58#[derive(Debug, thiserror::Error)]
60pub enum Error<F, U, D>
61where
62 F: Family,
63 U: std::error::Error + Send + 'static,
64 D: Digest,
65{
66 #[error("database error: {0}")]
68 Database(crate::qmdb::Error<F>),
69
70 #[error("resolver error: {0:?}")]
72 Resolver(U),
73
74 #[error("engine error: {0}")]
76 Engine(EngineError<F, D>),
77}
78
79impl<F, T, U, D> From<T> for Error<F, U, D>
80where
81 F: Family,
82 U: std::error::Error + Send + 'static,
83 D: Digest,
84 T: Into<crate::qmdb::Error<F>>,
85{
86 fn from(err: T) -> Self {
87 Self::Database(err.into())
88 }
89}