use crate::{
merkle::{Family, Location},
qmdb::sync::Target,
};
use commonware_cryptography::Digest;
#[derive(Debug, thiserror::Error)]
pub enum EngineError<F: Family, D: Digest> {
#[error("root digest mismatch - expected {expected:?}, got {actual:?}")]
RootMismatch { expected: D, actual: D },
#[error("compact proof failed verification")]
InvalidProof,
#[error("unexpected compact leaf count - expected {expected}, got {actual}")]
UnexpectedLeafCount {
expected: Location<F>,
actual: Location<F>,
},
#[error("invalid compact target: {0}")]
InvalidCompactTarget(&'static str),
#[error("invalid bounds: lower bound {lower_bound_pos} > upper bound {upper_bound_pos}")]
InvalidTarget {
lower_bound_pos: Location<F>,
upper_bound_pos: Location<F>,
},
#[error("invalid client state")]
InvalidState,
#[error("sync target root unchanged")]
SyncTargetRootUnchanged,
#[error("sync target moved backward: {old:?} -> {new:?}")]
SyncTargetMovedBackward {
old: Target<F, D>,
new: Target<F, D>,
},
#[error("sync already completed")]
AlreadyComplete,
#[error("sync stalled - no pending fetches")]
SyncStalled,
#[error("sync finish signal channel closed before finish was requested")]
FinishChannelClosed,
#[error("error extracting pinned nodes: {0}")]
PinnedNodes(String),
}
#[derive(Debug, thiserror::Error)]
pub enum Error<F, U, D>
where
F: Family,
U: std::error::Error + Send + 'static,
D: Digest,
{
#[error("database error: {0}")]
Database(crate::qmdb::Error<F>),
#[error("resolver error: {0:?}")]
Resolver(U),
#[error("engine error: {0}")]
Engine(EngineError<F, D>),
}
impl<F, T, U, D> From<T> for Error<F, U, D>
where
F: Family,
U: std::error::Error + Send + 'static,
D: Digest,
T: Into<crate::qmdb::Error<F>>,
{
fn from(err: T) -> Self {
Self::Database(err.into())
}
}