Skip to main content

krabka_client_streams/
error.rs

1//! Error type for the streams membership client.
2
3/// Errors surfaced by the streams membership client.
4#[derive(Debug, thiserror::Error)]
5pub enum StreamsClientError {
6    /// A transport failure or a dispatch failure from `krabka-client-core`.
7    #[cfg(not(target_family = "wasm"))]
8    #[error(transparent)]
9    Transport(#[from] krabka_client_core::ClientError),
10    /// The topology build failed, because the node graph is bad.
11    #[error("topology error: {0}")]
12    Topology(#[from] crate::topology::TopologyError),
13    /// The group coordinator was unavailable past the retry deadline.
14    #[error("streams group coordinator unavailable")]
15    CoordinatorUnavailable,
16    /// The broker rejected the topology with an error from the
17    /// `STREAMS_INVALID_TOPOLOGY*` family.
18    #[error("invalid topology (code {code}): {message}")]
19    InvalidTopology { code: i16, message: String },
20    /// `GROUP_AUTHORIZATION_FAILED` / `TOPIC_AUTHORIZATION_FAILED`.
21    #[error("authorization failed (code {0})")]
22    Authorization(i16),
23    /// `GROUP_ID_NOT_FOUND`.
24    #[error("group id not found")]
25    GroupIdNotFound,
26    /// The membership handle has been closed.
27    #[error("membership closed")]
28    Closed,
29    /// An unmapped broker error code.
30    #[error("broker error code {0}")]
31    Server(i16),
32    /// A runtime failure in processing, produce, or commit.
33    #[error("runtime error: {0}")]
34    Runtime(String),
35    /// The transactional or idempotent producer was fenced by a newer epoch.
36    /// This is fatal for the stream thread and must never enter retry rollback.
37    #[cfg(not(target_family = "wasm"))]
38    #[error(transparent)]
39    Producer(#[from] krabka_client_producer::ProducerError),
40    /// An interactive query failed.
41    #[cfg(not(target_family = "wasm"))]
42    #[error(transparent)]
43    InteractiveQuery(#[from] crate::runtime::iq::IqError),
44    /// A record on the `__barrier_state` topic does not match the frozen
45    /// layout. `part` names the record part that failed, either `key` or
46    /// `cut value`.
47    #[error("malformed barrier state {part}: {message}")]
48    BarrierFormat { part: &'static str, message: String },
49    /// A state-store snapshot could not be written, read, or decoded.
50    #[error("state snapshot error: {0}")]
51    Snapshot(String),
52}
53
54#[cfg(not(target_family = "wasm"))]
55impl StreamsClientError {
56    #[must_use]
57    pub(crate) fn is_producer_fenced(&self) -> bool {
58        matches!(
59            self,
60            Self::Producer(krabka_client_producer::ProducerError::FencedProducer)
61        )
62    }
63}