Skip to main content

crabka_remote_storage_topic/
error.rs

1//! Errors surfaced by the topic-backed
2//! [`RemoteLogMetadataManager`](crabka_remote_storage::RemoteLogMetadataManager)
3//! and the underlying [`MetadataEventLog`](crate::MetadataEventLog).
4
5use crabka_remote_storage::RemoteStorageError;
6
7/// Failures from the publish/subscribe transport that backs the
8/// `__remote_log_metadata` topic.
9#[derive(Debug, thiserror::Error)]
10pub enum MetadataLogError {
11    /// The transport refused the publish (broker unreachable, ack
12    /// timed out, …). The event was not appended.
13    #[error("publish failed: {0}")]
14    Publish(String),
15
16    /// Asked about a partition outside `[0, partition_count())`.
17    #[error("metadata partition {partition} out of range (count {count})")]
18    PartitionOutOfRange {
19        /// The offending partition index.
20        partition: i32,
21        /// The configured partition count.
22        count: i32,
23    },
24
25    /// The transport is closed and no further operations are possible.
26    #[error("metadata log closed")]
27    Closed,
28
29    /// Any other transport-layer failure.
30    #[error("metadata log error: {0}")]
31    Other(String),
32}
33
34impl MetadataLogError {
35    /// Wrap as a [`RemoteStorageError`] so the manager can surface
36    /// transport failures through the synchronous SPI.
37    #[must_use]
38    pub fn into_storage(self) -> RemoteStorageError {
39        RemoteStorageError::Io(std::io::Error::other(self.to_string()))
40    }
41}
42
43/// Errors from the binary wire codec.
44#[derive(Debug, thiserror::Error)]
45pub enum CodecError {
46    /// The buffer ended before the parser had finished a field.
47    #[error("unexpected end of input at offset {0}")]
48    UnexpectedEof(usize),
49
50    /// A state byte the codec does not know how to read.
51    #[error("unknown state byte {0} for {ctx}", ctx = .1)]
52    UnknownState(u8, &'static str),
53
54    /// A length prefix that does not fit in `usize`.
55    #[error("length prefix {0} too large")]
56    LengthOverflow(u64),
57
58    /// Reconstructing the event-domain type from the decoded fields
59    /// violated a precondition (e.g. empty leader-epoch map).
60    #[error("decoded event rejected: {0}")]
61    Domain(String),
62
63    /// An error propagated from the generated protocol codec (envelope
64    /// framing, schema mismatch, or trailing bytes).
65    #[error("protocol codec: {0}")]
66    Protocol(String),
67}
68
69/// Errors from the on-disk RLMM snapshot.
70#[derive(Debug, thiserror::Error)]
71pub enum SnapshotError {
72    /// The snapshot file could not be read or written.
73    #[error("snapshot io error: {0}")]
74    Io(#[from] std::io::Error),
75
76    /// A snapshot format version the loader does not understand.
77    #[error("unsupported snapshot format version {0}")]
78    UnsupportedVersion(u16),
79
80    /// The snapshot bytes were malformed (truncated, bad framing, or a
81    /// contained event failed to decode).
82    #[error("malformed snapshot: {0}")]
83    Malformed(#[from] CodecError),
84
85    /// Trailing bytes remained after the declared entries were read.
86    #[error("snapshot has {0} trailing bytes")]
87    TrailingBytes(usize),
88}