kafka/error.rs
1//! Error struct and methods
2
3use std::{io, result, sync::Arc};
4use thiserror::Error;
5
6pub type Result<T> = result::Result<T, Error>;
7
8#[derive(Debug, Error)]
9pub enum Error {
10 #[error(transparent)]
11 Io(#[from] io::Error),
12
13 #[cfg(feature = "security")]
14 #[error(transparent)]
15 Ssl(#[from] openssl::ssl::Error),
16
17 #[cfg(feature = "snappy")]
18 #[error(transparent)]
19 InvalidSnappy(#[from] ::snap::Error),
20
21 /// An error as reported by a remote Kafka server
22 #[error("Kafka Error ({0:?})")]
23 Kafka(KafkaCode),
24
25 /// An error when transmitting a request for a particular topic and partition.
26 /// Contains the topic and partition of the request that failed,
27 /// and the error code as reported by the Kafka server, respectively.
28 #[error("Topic Partition Error ({topic_name:?}, {partition_id:?}, {error_code:?})")]
29 TopicPartitionError {
30 topic_name: String,
31 partition_id: i32,
32 error_code: KafkaCode,
33 },
34
35 /// Failure to correctly parse the server response due to the
36 /// server speaking a newer protocol version (than the one this
37 /// library supports)
38 #[error("Unsupported protocol version")]
39 UnsupportedProtocol,
40
41 /// Failure to correctly parse the server response by this library
42 /// due to an unsupported compression format of the data
43 #[error("Unsupported compression format")]
44 UnsupportedCompression,
45
46 /// Failure to decode a response due to an insufficient number of bytes available
47 #[error("Unexpected EOF")]
48 UnexpectedEOF,
49
50 /// Failure to decode or encode a response or request respectively
51 #[error("Encoding/Decoding Error")]
52 CodecError,
53
54 /// Failure to decode a string into a valid utf8 byte sequence
55 #[error("String decoding error")]
56 StringDecodeError,
57
58 /// Unable to reach any host
59 #[error("No host reachable")]
60 NoHostReachable,
61
62 /// Unable to set up `Consumer` due to missing topic assignments
63 #[error("No topic assigned")]
64 NoTopicsAssigned,
65
66 /// An invalid user-provided duration
67 #[error("Invalid duration")]
68 InvalidDuration,
69
70 #[error(transparent)]
71 ArcSelf(#[from] Arc<Self>),
72
73 #[error("Operation requires offset storage but no offset storage was set")]
74 UnsetOffsetStorage,
75
76 #[error("Operation requires group id but no group was set")]
77 UnsetGroupId,
78}
79
80/// Various errors reported by a remote Kafka server.
81/// See also [Kafka Errors](http://kafka.apache.org/protocol.html)
82#[derive(Debug, Copy, Clone, PartialEq, Eq)]
83pub enum KafkaCode {
84 /// An unexpected server error
85 Unknown = -1,
86 /// The requested offset is outside the range of offsets
87 /// maintained by the server for the given topic/partition
88 OffsetOutOfRange = 1,
89 /// This indicates that a message contents does not match its CRC
90 CorruptMessage = 2,
91 /// This request is for a topic or partition that does not exist
92 /// on this broker.
93 UnknownTopicOrPartition = 3,
94 /// The message has a negative size
95 InvalidMessageSize = 4,
96 /// This error is thrown if we are in the middle of a leadership
97 /// election and there is currently no leader for this partition
98 /// and hence it is unavailable for writes.
99 LeaderNotAvailable = 5,
100 /// This error is thrown if the client attempts to send messages
101 /// to a replica that is not the leader for some partition. It
102 /// indicates that the clients metadata is out of date.
103 NotLeaderForPartition = 6,
104 /// This error is thrown if the request exceeds the user-specified
105 /// time limit in the request.
106 RequestTimedOut = 7,
107 /// This is not a client facing error and is used mostly by tools
108 /// when a broker is not alive.
109 BrokerNotAvailable = 8,
110 /// If replica is expected on a broker, but is not (this can be
111 /// safely ignored).
112 ReplicaNotAvailable = 9,
113 /// The server has a configurable maximum message size to avoid
114 /// unbounded memory allocation. This error is thrown if the
115 /// client attempt to produce a message larger than this maximum.
116 MessageSizeTooLarge = 10,
117 /// Internal error code for broker-to-broker communication.
118 StaleControllerEpoch = 11,
119 /// If you specify a string larger than configured maximum for
120 /// offset metadata
121 OffsetMetadataTooLarge = 12,
122 /// The server disconnected before a response was received.
123 NetworkException = 13,
124 /// The broker returns this error code for an offset fetch request
125 /// if it is still loading offsets (after a leader change for that
126 /// offsets topic partition), or in response to group membership
127 /// requests (such as heartbeats) when group metadata is being
128 /// loaded by the coordinator.
129 GroupLoadInProgress = 14,
130 /// The broker returns this error code for group coordinator
131 /// requests, offset commits, and most group management requests
132 /// if the offsets topic has not yet been created, or if the group
133 /// coordinator is not active.
134 GroupCoordinatorNotAvailable = 15,
135 /// The broker returns this error code if it receives an offset
136 /// fetch or commit request for a group that it is not a
137 /// coordinator for.
138 NotCoordinatorForGroup = 16,
139 /// For a request which attempts to access an invalid topic
140 /// (e.g. one which has an illegal name), or if an attempt is made
141 /// to write to an internal topic (such as the consumer offsets
142 /// topic).
143 InvalidTopic = 17,
144 /// If a message batch in a produce request exceeds the maximum
145 /// configured segment size.
146 RecordListTooLarge = 18,
147 /// Returned from a produce request when the number of in-sync
148 /// replicas is lower than the configured minimum and requiredAcks is
149 /// -1.
150 NotEnoughReplicas = 19,
151 /// Returned from a produce request when the message was written
152 /// to the log, but with fewer in-sync replicas than required.
153 NotEnoughReplicasAfterAppend = 20,
154 /// Returned from a produce request if the requested requiredAcks is
155 /// invalid (anything other than -1, 1, or 0).
156 InvalidRequiredAcks = 21,
157 /// Returned from group membership requests (such as heartbeats) when
158 /// the generation id provided in the request is not the current
159 /// generation.
160 IllegalGeneration = 22,
161 /// Returned in join group when the member provides a protocol type or
162 /// set of protocols which is not compatible with the current group.
163 InconsistentGroupProtocol = 23,
164 /// Returned in join group when the groupId is empty or null.
165 InvalidGroupId = 24,
166 /// Returned from group requests (offset commits/fetches, heartbeats,
167 /// etc) when the memberId is not in the current generation.
168 UnknownMemberId = 25,
169 /// Return in join group when the requested session timeout is outside
170 /// of the allowed range on the broker
171 InvalidSessionTimeout = 26,
172 /// Returned in heartbeat requests when the coordinator has begun
173 /// rebalancing the group. This indicates to the client that it
174 /// should rejoin the group.
175 RebalanceInProgress = 27,
176 /// This error indicates that an offset commit was rejected because of
177 /// oversize metadata.
178 InvalidCommitOffsetSize = 28,
179 /// Returned by the broker when the client is not authorized to access
180 /// the requested topic.
181 TopicAuthorizationFailed = 29,
182 /// Returned by the broker when the client is not authorized to access
183 /// a particular groupId.
184 GroupAuthorizationFailed = 30,
185 /// Returned by the broker when the client is not authorized to use an
186 /// inter-broker or administrative API.
187 ClusterAuthorizationFailed = 31,
188 /// The timestamp of the message is out of acceptable range.
189 InvalidTimestamp = 32,
190 /// The broker does not support the requested SASL mechanism.
191 UnsupportedSaslMechanism = 33,
192 /// Request is not valid given the current SASL state.
193 IllegalSaslState = 34,
194 /// The version of API is not supported.
195 UnsupportedVersion = 35,
196 // CAUTION! When adding to this list, KafkaCode::from_protocol must be updated. If there's a better way, please open an issue for it!
197}