ubiquisync_core/codec/error.rs
1/// An error encoding or decoding the log wire format.
2#[derive(Debug, thiserror::Error)]
3pub enum CodecError {
4 /// The input ended mid-value (truncated entry or segment).
5 #[error("unexpected end of input")]
6 UnexpectedEof,
7 /// Bytes remained after a value that should have consumed its whole input.
8 #[error("trailing bytes remain after decoding")]
9 TrailingBytes,
10 /// An entry tag the op vocabulary does not recognize.
11 #[error("unknown tag: {0}")]
12 UnknownTag(u8),
13 /// A UUID dictionary reference pointed at an index that was never defined.
14 #[error("unresolved UUID dictionary reference {0}")]
15 UnresolvedUuid(u64),
16 /// The number of primary-key values disagreed with the table ID's PK count.
17 #[error("primary key has {got} value(s) but the table ID declares {expected}")]
18 PkCountMismatch {
19 /// PK column count the table ID declares.
20 expected: usize,
21 /// Number of PK values actually supplied.
22 got: usize,
23 },
24 /// A column value's variant did not match the column ID's declared type.
25 #[error("column value variant does not match the column ID's declared type")]
26 ColumnValueMismatch,
27 /// A primary-key value's variant did not match the table ID's declared PK
28 /// type.
29 #[error("primary key value variant does not match the table ID's declared PK type")]
30 PkValueMismatch,
31 /// The recomputed integrity hash did not match the stored one — corruption
32 /// or tampering.
33 #[error("hash mismatch: expected {expected:#010x}, got {got:#010x}")]
34 HashMismatch {
35 /// Truncated hash read from the entry.
36 expected: u32,
37 /// Truncated hash recomputed over the decoded bytes.
38 got: u32,
39 },
40 /// A varint encoded a value larger than `u64`.
41 #[error("varint overflows u64")]
42 VarIntOverflow,
43 /// A timestamp delta went backwards, violating the monotonic ordering.
44 #[error("non-monotonic delta")]
45 NonMonotonicDelta,
46 /// Adding a timestamp delta to the running base overflowed `u64`.
47 #[error("timestamp delta overflows u64")]
48 TimestampOverflow,
49 /// An on-wire length/count did not fit in `usize` on this target.
50 #[error("on-wire length/count {0} does not fit in usize on this target")]
51 LengthTooLarge(u64),
52 /// A text value was not valid UTF-8.
53 #[error("invalid utf-8")]
54 InvalidUtf8(#[from] std::string::FromUtf8Error),
55 /// A text value contained an embedded NUL byte, which is disallowed.
56 #[error("text value contains an embedded NUL byte")]
57 TextContainsNul,
58 /// The segment's leading magic bytes did not match the expected app magic.
59 #[error("bad magic bytes")]
60 BadMagic,
61 /// The segment flags byte was neither the device nor the server mode value.
62 #[error("unknown segment flags byte {0:#04x}")]
63 UnknownSegmentFlags(u8),
64 /// A server-mode entry was missing its required user id.
65 #[error("missing user id in server mode")]
66 MissingUserId,
67 /// An underlying I/O error.
68 #[error("io error: {0}")]
69 Io(#[from] std::io::Error),
70 /// The log file's framing was structurally invalid.
71 #[error("corrupted log file")]
72 CorruptedLogFile,
73}