Skip to main content

kafka_client_engine/consumer/assigned_host/delivery/
error.rs

1//! Stable immediate-observation failures for assigned-consumer batches.
2
3use super::super::{result::AssignedConsumerPortError, shard::AssignedConsumerShardLockError};
4use crate::consumer::assigned_owner_model::AssignedConsumerOwnerError;
5
6/// Stable reason an immediate batch observation could not complete.
7#[derive(Clone, Copy, Debug, Eq, PartialEq)]
8pub enum AssignedConsumerTryTakeBatchErrorKind {
9    /// Another owner or caller currently holds the assigned-consumer shard.
10    Contended,
11    /// Consumer admission is permanently closed.
12    Closed,
13    /// Accepted control effects must settle before another batch can transfer.
14    Pending,
15    /// The synchronized engine host cannot execute consumer work.
16    HostUnavailable,
17    /// A non-semantic engine mechanism violated its ownership contract.
18    InternalInvariant,
19}
20
21/// Immediate observation rejection before any delivery lease transferred.
22#[derive(Clone, Copy, Debug, Eq, PartialEq)]
23pub struct AssignedConsumerTryTakeBatchError {
24    kind: AssignedConsumerTryTakeBatchErrorKind,
25}
26
27impl AssignedConsumerTryTakeBatchError {
28    pub(crate) const fn from_port(error: &AssignedConsumerPortError) -> Self {
29        Self {
30            kind: error_kind(error),
31        }
32    }
33
34    /// Returns the stable observation-failure category.
35    pub const fn kind(&self) -> AssignedConsumerTryTakeBatchErrorKind {
36        self.kind
37    }
38}
39
40impl std::fmt::Display for AssignedConsumerTryTakeBatchError {
41    fn fmt(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
42        write!(
43            formatter,
44            "assigned-consumer batch observation failed: {:?}",
45            self.kind
46        )
47    }
48}
49
50impl std::error::Error for AssignedConsumerTryTakeBatchError {}
51
52const fn error_kind(error: &AssignedConsumerPortError) -> AssignedConsumerTryTakeBatchErrorKind {
53    match error {
54        AssignedConsumerPortError::Closed => AssignedConsumerTryTakeBatchErrorKind::Closed,
55        AssignedConsumerPortError::Lock(AssignedConsumerShardLockError::Contended) => {
56            AssignedConsumerTryTakeBatchErrorKind::Contended
57        }
58        AssignedConsumerPortError::Lock(
59            AssignedConsumerShardLockError::Poisoned | AssignedConsumerShardLockError::OwnerMissing,
60        )
61        | AssignedConsumerPortError::Owner {
62            error: AssignedConsumerOwnerError::Faulted,
63            ..
64        } => AssignedConsumerTryTakeBatchErrorKind::HostUnavailable,
65        AssignedConsumerPortError::Owner {
66            error:
67                AssignedConsumerOwnerError::EffectsPending
68                | AssignedConsumerOwnerError::DeliveryUnavailable,
69            ..
70        } => AssignedConsumerTryTakeBatchErrorKind::Pending,
71        AssignedConsumerPortError::Clock(_) | AssignedConsumerPortError::Owner { .. } => {
72            AssignedConsumerTryTakeBatchErrorKind::InternalInvariant
73        }
74    }
75}