Skip to main content

KafkaError

Enum KafkaError 

Source
pub enum KafkaError {
Show 17 variants Connection { message: String, broker: String, }, Consumption { message: String, topic: String, partition: Option<i32>, offset: Option<i64>, }, Production { message: String, topic: String, partition: Option<i32>, }, Serialization { message: String, context: Option<String>, }, Deserialization { message: String, context: Option<String>, payload_sample: Option<Vec<u8>>, }, InvalidConfiguration { message: String, field: Option<String>, }, OffsetCommit { message: String, topic: String, partition: i32, offset: i64, }, GroupCoordination { message: String, group_id: String, }, PartitionAssignment { message: String, topics: Vec<String>, }, AuthError { message: String, protocol: String, }, IoError { message: String, source: Option<Error>, }, Timeout { operation: String, timeout_ms: u64, }, TopicMetadata { message: String, topic: String, }, PartitionNotFound { topic: String, partition: i32, }, ResourceExhausted { message: String, resource: String, }, KafkaClient { message: String, code: Option<i32>, }, Other(String),
}
Expand description

Comprehensive error type for Kafka operations.

This enum covers all possible error scenarios when working with Kafka, providing detailed context for debugging and error handling.

§Examples

use processor::kafka::error::{KafkaError, Result};

fn connect_to_kafka() -> Result<()> {
    // Simulate connection error
    Err(KafkaError::Connection {
        message: "Failed to connect to broker".to_string(),
        broker: "localhost:9092".to_string(),
    })
}

match connect_to_kafka() {
    Ok(_) => println!("Connected successfully"),
    Err(KafkaError::Connection { message, broker }) => {
        eprintln!("Connection error to {}: {}", broker, message);
    }
    Err(e) => eprintln!("Other error: {}", e),
}

Variants§

§

Connection

Error establishing connection to Kafka broker.

Fields

§message: String

Error message describing the connection failure.

§broker: String

Broker address that failed to connect.

§

Consumption

Error during message consumption.

Fields

§message: String

Error message describing the consumption failure.

§topic: String

Topic from which consumption failed.

§partition: Option<i32>

Partition number if available.

§offset: Option<i64>

Offset if available.

§

Production

Error during message production.

Fields

§message: String

Error message describing the production failure.

§topic: String

Topic to which production failed.

§partition: Option<i32>

Partition number if available.

§

Serialization

Error during serialization of messages.

Fields

§message: String

Error message describing the serialization failure.

§context: Option<String>

Optional context about what was being serialized.

§

Deserialization

Error during deserialization of messages.

Fields

§message: String

Error message describing the deserialization failure.

§context: Option<String>

Optional context about what was being deserialized.

§payload_sample: Option<Vec<u8>>

Raw bytes that failed to deserialize (truncated for display).

§

InvalidConfiguration

Configuration validation error.

Fields

§message: String

Error message describing the configuration issue.

§field: Option<String>

Field name that has invalid configuration.

§

OffsetCommit

Error committing offsets.

Fields

§message: String

Error message describing the commit failure.

§topic: String

Topic for which offset commit failed.

§partition: i32

Partition for which offset commit failed.

§offset: i64

Offset that failed to commit.

§

GroupCoordination

Error during consumer group coordination.

Fields

§message: String

Error message describing the coordination failure.

§group_id: String

Consumer group ID.

§

PartitionAssignment

Error during partition assignment.

Fields

§message: String

Error message describing the assignment failure.

§topics: Vec<String>

Topics involved in the assignment.

§

AuthError

Authentication or authorization error.

Fields

§message: String

Error message describing the auth failure.

§protocol: String

Security protocol being used.

§

IoError

Network or I/O error.

Fields

§message: String

Error message describing the I/O failure.

§source: Option<Error>

Optional underlying I/O error.

§

Timeout

Timeout error during Kafka operations.

Fields

§operation: String

Description of the operation that timed out.

§timeout_ms: u64

Timeout duration in milliseconds.

§

TopicMetadata

Error related to topic metadata.

Fields

§message: String

Error message describing the metadata failure.

§topic: String

Topic name.

§

PartitionNotFound

Error when a topic partition doesn’t exist.

Fields

§topic: String

Topic name.

§partition: i32

Partition number.

§

ResourceExhausted

Error when reaching resource limits.

Fields

§message: String

Error message describing the resource exhaustion.

§resource: String

Resource type (e.g., “buffer”, “connections”).

§

KafkaClient

Error from the underlying rdkafka library.

Fields

§message: String

Error message from rdkafka.

§code: Option<i32>

rdkafka error code.

§

Other(String)

Generic error for cases not covered by specific variants.

Implementations§

Source§

impl KafkaError

Source

pub fn connection(message: impl Into<String>, broker: impl Into<String>) -> Self

Create a connection error.

Source

pub fn consumption( message: impl Into<String>, topic: impl Into<String>, partition: Option<i32>, offset: Option<i64>, ) -> Self

Create a consumption error.

Source

pub fn production( message: impl Into<String>, topic: impl Into<String>, partition: Option<i32>, ) -> Self

Create a production error.

Source

pub fn serialization( message: impl Into<String>, context: Option<String>, ) -> Self

Create a serialization error.

Source

pub fn deserialization( message: impl Into<String>, context: Option<String>, payload_sample: Option<Vec<u8>>, ) -> Self

Create a deserialization error.

Source

pub fn invalid_config(message: impl Into<String>, field: Option<String>) -> Self

Create an invalid configuration error.

Source

pub fn offset_commit( message: impl Into<String>, topic: impl Into<String>, partition: i32, offset: i64, ) -> Self

Create an offset commit error.

Source

pub fn group_coordination( message: impl Into<String>, group_id: impl Into<String>, ) -> Self

Create a group coordination error.

Source

pub fn partition_assignment( message: impl Into<String>, topics: Vec<String>, ) -> Self

Create a partition assignment error.

Source

pub fn auth_error( message: impl Into<String>, protocol: impl Into<String>, ) -> Self

Create an authentication/authorization error.

Source

pub fn timeout(operation: impl Into<String>, timeout_ms: u64) -> Self

Create a timeout error.

Source

pub fn topic_metadata( message: impl Into<String>, topic: impl Into<String>, ) -> Self

Create a topic metadata error.

Source

pub fn partition_not_found(topic: impl Into<String>, partition: i32) -> Self

Create a partition not found error.

Source

pub fn resource_exhausted( message: impl Into<String>, resource: impl Into<String>, ) -> Self

Create a resource exhausted error.

Source

pub fn kafka_client(message: impl Into<String>, code: Option<i32>) -> Self

Create a Kafka client error.

Source

pub fn is_retryable(&self) -> bool

Check if the error is retryable.

Returns true if the operation that caused this error can be retried.

Source

pub fn is_fatal(&self) -> bool

Check if the error is fatal and requires system shutdown.

Returns true if the error indicates an unrecoverable state.

Source

pub fn severity(&self) -> ErrorSeverity

Get error severity level.

Returns a severity level suitable for logging and monitoring.

Trait Implementations§

Source§

impl Debug for KafkaError

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for KafkaError

Source§

fn fmt(&self, __formatter: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Error for KafkaError

Source§

fn source(&self) -> Option<&(dyn Error + 'static)>

Returns the lower-level source of this error, if any. Read more
1.0.0 · Source§

fn description(&self) -> &str

👎Deprecated since 1.42.0:

use the Display impl or to_string()

1.0.0 · Source§

fn cause(&self) -> Option<&dyn Error>

👎Deprecated since 1.33.0:

replaced by Error::source, which can support downcasting

Source§

fn provide<'a>(&'a self, request: &mut Request<'a>)

🔬This is a nightly-only experimental API. (error_generic_member_access)
Provides type-based access to context intended for error reports. Read more
Source§

impl From<Box<ErrorKind>> for KafkaError

Source§

fn from(err: Error) -> Self

Converts to this type from the input type.
Source§

impl From<Error> for KafkaError

Source§

fn from(err: Error) -> Self

Converts to this type from the input type.
Source§

impl From<Error> for KafkaError

Source§

fn from(err: Error) -> Self

Converts to this type from the input type.
Source§

impl From<KafkaError> for KafkaError

Source§

fn from(err: KafkaError) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FutureExt for T

Source§

fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ

Attaches the provided Context to this type, returning a WithContext wrapper. Read more
Source§

fn with_current_context(self) -> WithContext<Self> ⓘ

Attaches the current Context to this type, returning a WithContext wrapper. Read more
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> IntoRequest<T> for T

Source§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
Source§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more