use std::{error::Error, fmt};
use super::ProducerRecord;
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub(crate) enum ProducerStoreError {
RecordCapacity,
ByteCapacity,
BatchCapacity,
RetainedSizeOverflow,
HeaderCountOutOfRange,
PayloadIdentityExhausted,
TopicIdentityExhausted,
UnknownTopic,
UnknownPayload,
InvalidPayloadState,
DuplicateOperation,
DuplicatePayloadMembership,
UnknownBatch,
UnknownBatchMember,
BatchRouteMismatch,
EmptyBatch,
BatchRecordCountOutOfRange,
BatchAlreadyMaterialized,
StaleBatchExecution,
PartitionOutOfRange,
RetainedSizeMismatch,
PayloadStillBatched,
}
impl fmt::Display for ProducerStoreError {
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
formatter.write_str(match self {
Self::RecordCapacity => "producer record capacity is full",
Self::ByteCapacity => "producer retained-byte capacity is full",
Self::BatchCapacity => "producer batch capacity is full",
Self::RetainedSizeOverflow => "producer retained byte size overflowed",
Self::HeaderCountOutOfRange => {
"producer record header count exceeds Kafka's signed domain"
}
Self::PayloadIdentityExhausted => "producer payload identity space is exhausted",
Self::TopicIdentityExhausted => "producer topic identity space is exhausted",
Self::UnknownTopic => "producer topic identity is stale",
Self::UnknownPayload => "producer payload identity is stale",
Self::InvalidPayloadState => "producer payload is in the wrong lifecycle state",
Self::DuplicateOperation => "producer operation already belongs to a batch",
Self::DuplicatePayloadMembership => "producer payload already belongs to a batch",
Self::UnknownBatch => "producer batch identity is stale",
Self::UnknownBatchMember => "operation is not a member of the producer batch",
Self::BatchRouteMismatch => "producer batch contains inconsistent routes",
Self::EmptyBatch => "producer batch has no records",
Self::BatchRecordCountOutOfRange => {
"producer batch record count exceeds Kafka's sequence domain"
}
Self::BatchAlreadyMaterialized => "producer batch was already materialized",
Self::StaleBatchExecution => "producer batch execution identity is stale",
Self::PartitionOutOfRange => "producer partition exceeds the Kafka protocol range",
Self::RetainedSizeMismatch => "producer release byte count does not match admission",
Self::PayloadStillBatched => "producer payload still belongs to a batch",
})
}
}
impl Error for ProducerStoreError {}
#[derive(Debug)]
pub(crate) struct ProducerAdmissionError {
reason: ProducerStoreError,
record: ProducerRecord,
}
impl ProducerAdmissionError {
pub(super) const fn new(reason: ProducerStoreError, record: ProducerRecord) -> Self {
Self { reason, record }
}
pub(crate) const fn reason(&self) -> ProducerStoreError {
self.reason
}
pub(crate) fn into_record(self) -> ProducerRecord {
self.record
}
}
impl fmt::Display for ProducerAdmissionError {
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
self.reason.fmt(formatter)
}
}
impl Error for ProducerAdmissionError {}