Skip to main content

ubiquisync_core/sync/
error.rs

1use crate::codec::CodecError;
2
3/// The sync subsystem's error: reading a log ([`LogSource`](super::LogSource)),
4/// applying entries ([`LogProcessor`](super::LogProcessor)), or writing the
5/// local log ([`FileLogSink`](super::FileLogSink)). Backends erase their own
6/// errors into [`SyncError::Backend`], so the object-safe traits share one fixed
7/// error type instead of an associated one.
8#[derive(Debug, thiserror::Error)]
9pub enum SyncError {
10    /// An underlying I/O error.
11    #[error("io error: {0}")]
12    Io(#[from] std::io::Error),
13    /// A peer id that this source/sink does not know.
14    #[error("unknown peer")]
15    UnknownPeer,
16    /// A requested entry index lay outside the peer's log.
17    #[error("index out of range")]
18    IndexOutOfRange,
19    /// A value could not be encoded for transport/storage.
20    #[error("encoding error: {0}")]
21    EncodingError(String),
22    /// The pull cursor's expected next index disagreed with the source — the
23    /// streams are out of sync.
24    #[error("cursor mismatch: expected entry_idx={expected_idx}, got entry_idx={actual_idx}")]
25    CursorMismatch {
26        /// Entry index the cursor expected next.
27        expected_idx: u64,
28        /// Entry index the source actually presented.
29        actual_idx: u64,
30    },
31    /// A wire-format error decoding a peer's log entries.
32    #[error("codec error: {0}")]
33    CodecError(#[from] CodecError),
34    /// A backend failure erased behind a boxed error, letting a concrete replica
35    /// surface its own error type through the fixed trait boundary.
36    #[error("backend error: {0}")]
37    Backend(Box<dyn std::error::Error + Send + Sync>),
38}