Skip to main content

kafka_client_engine/consumer/group_recv/
error.rs

1//! Stable failures for notification-backed classic-group batch observation.
2
3use crate::consumer::{GroupConsumerFetchFailureKind, GroupConsumerPositionFailureKind};
4
5/// Stable reason a named group receive cannot continue.
6#[derive(Clone, Copy, Debug, Eq, PartialEq)]
7pub enum GroupConsumerRecvErrorKind {
8    /// The synchronized group host is unavailable or retained a terminal fault.
9    HostUnavailable,
10    /// Hosted Fetch reached one exact terminal outcome before transferring bytes.
11    Fetch(GroupConsumerFetchFailureKind),
12    /// Group-position bootstrap or reset reached one exact terminal outcome.
13    Position(GroupConsumerPositionFailureKind),
14    /// An internal observation mechanism violated its ownership contract.
15    InternalInvariant,
16}
17
18/// Named receive failure after no group batch transferred.
19#[derive(Clone, Copy, Debug, Eq, PartialEq)]
20pub struct GroupConsumerRecvError {
21    kind: GroupConsumerRecvErrorKind,
22}
23
24impl GroupConsumerRecvError {
25    pub(super) const fn host_unavailable() -> Self {
26        Self {
27            kind: GroupConsumerRecvErrorKind::HostUnavailable,
28        }
29    }
30
31    pub(super) const fn position(kind: GroupConsumerPositionFailureKind) -> Self {
32        Self {
33            kind: GroupConsumerRecvErrorKind::Position(kind),
34        }
35    }
36
37    pub(super) const fn fetch(kind: GroupConsumerFetchFailureKind) -> Self {
38        Self {
39            kind: GroupConsumerRecvErrorKind::Fetch(kind),
40        }
41    }
42
43    pub(in crate::consumer) const fn internal_invariant() -> Self {
44        Self {
45            kind: GroupConsumerRecvErrorKind::InternalInvariant,
46        }
47    }
48
49    /// Returns the stable receive-failure category.
50    pub const fn kind(&self) -> GroupConsumerRecvErrorKind {
51        self.kind
52    }
53}
54
55impl std::fmt::Display for GroupConsumerRecvError {
56    fn fmt(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
57        write!(
58            formatter,
59            "classic-group receive observation failed: {:?}",
60            self.kind
61        )
62    }
63}
64
65impl std::error::Error for GroupConsumerRecvError {}