1use kafka_protocol::{messages::RequestKind, ResponseError};
4
5use crate::StrBytes;
6
7pub type ClientResult<T> = std::result::Result<T, ClientError>;
9
10#[derive(Debug, thiserror::Error)]
14pub enum ClientError {
15 #[error("error while interacting with a broker: {0:?}")]
17 BrokerError(BrokerRequestError),
18 #[error("error while encoding a batch of records: {0}")]
20 EncodingError(String),
21 #[error("broker returned a malformed response")]
23 MalformedResponse,
24 #[error("the specified topic has no available partitions: {0}")]
26 NoPartitionsAvailable(String),
27 #[error("produce requests must include at least 1 record")]
29 ProducerMessagesEmpty,
30 #[error("the specified topic is unknown to the cluster: {0}")]
32 UnknownTopic(String),
33 #[error("the specified topic partition is unknown to the cluster: {0}/{1}")]
35 UnknownPartition(String, i32),
36 #[error("the specified topic partition is does not currently have a known leader: {0}/{1}")]
38 NoPartitionLeader(String, i32),
39 #[error("an error was returned in a response from a broker: {0} {1:?} {2:?}")]
41 ResponseError(i16, Option<ResponseError>, Option<StrBytes>),
42 #[error("timeout while waiting for cluster metadata to bootstrap")]
44 ClusterMetadataTimeout,
45 #[error("could not find a broker specified by ID, or any broker at all")]
47 NoBrokerFound,
48 #[error("{0}")]
49 Other(String),
50 #[error("no topics were specified in the request")]
51 NoTopicsSpecified,
52 #[error("no controller was found in the cluster metadata")]
53 NoControllerFound,
54}
55
56#[derive(Debug, thiserror::Error)]
58#[error("broker connection error: {kind:?}")]
59pub struct BrokerRequestError {
60 pub(crate) payload: RequestKind,
62 pub(crate) kind: BrokerErrorKind,
64}
65
66#[derive(Debug, thiserror::Error)]
68pub enum BrokerErrorKind {
69 #[error("the client is disconnected")]
71 Disconnected,
72 #[error("the broker returned a malformed response")]
74 MalformedBrokerResponse,
75}