Skip to main content

abyo_crdt/
error.rs

1//! Error types.
2
3use thiserror::Error;
4
5/// Errors that can occur in `abyo-crdt`.
6#[derive(Error, Debug, Clone, PartialEq, Eq)]
7#[non_exhaustive]
8pub enum Error {
9    /// Position is out of bounds for the current visible length.
10    #[error("position {pos} is out of bounds (visible length {len})")]
11    OutOfBounds {
12        /// The requested position.
13        pos: usize,
14        /// The current visible length.
15        len: usize,
16    },
17
18    /// A remote insertion referenced a parent that we have not seen.
19    ///
20    /// In a correct event-graph delivery, parents are always delivered
21    /// before children. This error indicates the caller violated causal
22    /// delivery (e.g. by applying `Op`s out of order).
23    #[error("missing causal parent {missing:?} for op {op:?}")]
24    MissingParent {
25        /// The op being applied.
26        op: crate::OpId,
27        /// The parent that wasn't found.
28        missing: crate::OpId,
29    },
30
31    /// A delete op targets an item we have not seen.
32    #[error("delete op {op:?} targets unknown item {target:?}")]
33    UnknownTarget {
34        /// The delete op.
35        op: crate::OpId,
36        /// The missing target.
37        target: crate::OpId,
38    },
39
40    /// A remote op claims to come from this replica's id. Two replicas
41    /// must never share an id — if they do, every guarantee is off.
42    #[error(
43        "remote op {op:?} uses our replica id {replica}; \
44         two replicas must never share a replica id"
45    )]
46    ReplicaIdConflict {
47        /// The offending op.
48        op: crate::OpId,
49        /// The shared replica id.
50        replica: crate::ReplicaId,
51    },
52
53    /// The Lamport clock would overflow `u64`. Practically never reachable
54    /// (~10¹⁹ ops per replica), but reported instead of silently wrapping.
55    #[error("Lamport clock overflow on replica {replica}")]
56    ClockOverflow {
57        /// The replica that overflowed.
58        replica: crate::ReplicaId,
59    },
60}