Skip to main content

kacrab_protocol/generated/
error_code.rs

1//! Kafka protocol error codes.
2//!
3//! Generated from Kafka's `Errors.java` -- DO NOT EDIT.
4#![allow(
5    missing_docs,
6    clippy::all,
7    clippy::pedantic,
8    clippy::nursery,
9    reason = "Generated protocol error-code variants mirror Kafka's Java enum and intentionally \
10              avoid duplicating Java docs for every variant."
11)]
12/// Kafka protocol error code.
13///
14/// Every response in the Kafka protocol carries an `i16` error code.
15/// This enum provides a typed representation with human-readable messages,
16/// retriability classification, and forward-compatible handling of unknown codes.
17#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
18#[non_exhaustive]
19pub enum ErrorCode {
20    UnknownServerError,
21    None,
22    OffsetOutOfRange,
23    CorruptMessage,
24    UnknownTopicOrPartition,
25    InvalidFetchSize,
26    LeaderNotAvailable,
27    NotLeaderOrFollower,
28    RequestTimedOut,
29    BrokerNotAvailable,
30    ReplicaNotAvailable,
31    MessageTooLarge,
32    StaleControllerEpoch,
33    OffsetMetadataTooLarge,
34    NetworkException,
35    CoordinatorLoadInProgress,
36    CoordinatorNotAvailable,
37    NotCoordinator,
38    InvalidTopicException,
39    RecordListTooLarge,
40    NotEnoughReplicas,
41    NotEnoughReplicasAfterAppend,
42    InvalidRequiredAcks,
43    IllegalGeneration,
44    InconsistentGroupProtocol,
45    InvalidGroupId,
46    UnknownMemberId,
47    InvalidSessionTimeout,
48    RebalanceInProgress,
49    InvalidCommitOffsetSize,
50    TopicAuthorizationFailed,
51    GroupAuthorizationFailed,
52    ClusterAuthorizationFailed,
53    InvalidTimestamp,
54    UnsupportedSaslMechanism,
55    IllegalSaslState,
56    UnsupportedVersion,
57    TopicAlreadyExists,
58    InvalidPartitions,
59    InvalidReplicationFactor,
60    InvalidReplicaAssignment,
61    InvalidConfig,
62    NotController,
63    InvalidRequest,
64    UnsupportedForMessageFormat,
65    PolicyViolation,
66    OutOfOrderSequenceNumber,
67    DuplicateSequenceNumber,
68    InvalidProducerEpoch,
69    InvalidTxnState,
70    InvalidProducerIdMapping,
71    InvalidTransactionTimeout,
72    ConcurrentTransactions,
73    TransactionCoordinatorFenced,
74    TransactionalIdAuthorizationFailed,
75    SecurityDisabled,
76    OperationNotAttempted,
77    KafkaStorageError,
78    LogDirNotFound,
79    SaslAuthenticationFailed,
80    UnknownProducerId,
81    ReassignmentInProgress,
82    DelegationTokenAuthDisabled,
83    DelegationTokenNotFound,
84    DelegationTokenOwnerMismatch,
85    DelegationTokenRequestNotAllowed,
86    DelegationTokenAuthorizationFailed,
87    DelegationTokenExpired,
88    InvalidPrincipalType,
89    NonEmptyGroup,
90    GroupIdNotFound,
91    FetchSessionIdNotFound,
92    InvalidFetchSessionEpoch,
93    ListenerNotFound,
94    TopicDeletionDisabled,
95    FencedLeaderEpoch,
96    UnknownLeaderEpoch,
97    UnsupportedCompressionType,
98    StaleBrokerEpoch,
99    OffsetNotAvailable,
100    MemberIdRequired,
101    PreferredLeaderNotAvailable,
102    GroupMaxSizeReached,
103    FencedInstanceId,
104    EligibleLeadersNotAvailable,
105    ElectionNotNeeded,
106    NoReassignmentInProgress,
107    GroupSubscribedToTopic,
108    InvalidRecord,
109    UnstableOffsetCommit,
110    ThrottlingQuotaExceeded,
111    ProducerFenced,
112    ResourceNotFound,
113    DuplicateResource,
114    UnacceptableCredential,
115    InconsistentVoterSet,
116    InvalidUpdateVersion,
117    FeatureUpdateFailed,
118    PrincipalDeserializationFailure,
119    SnapshotNotFound,
120    PositionOutOfRange,
121    UnknownTopicId,
122    DuplicateBrokerRegistration,
123    BrokerIdNotRegistered,
124    InconsistentTopicId,
125    InconsistentClusterId,
126    TransactionalIdNotFound,
127    FetchSessionTopicIdError,
128    IneligibleReplica,
129    NewLeaderElected,
130    OffsetMovedToTieredStorage,
131    FencedMemberEpoch,
132    UnreleasedInstanceId,
133    UnsupportedAssignor,
134    StaleMemberEpoch,
135    MismatchedEndpointType,
136    UnsupportedEndpointType,
137    UnknownControllerId,
138    UnknownSubscriptionId,
139    TelemetryTooLarge,
140    InvalidRegistration,
141    TransactionAbortable,
142    InvalidRecordState,
143    ShareSessionNotFound,
144    InvalidShareSessionEpoch,
145    FencedStateEpoch,
146    InvalidVoterKey,
147    DuplicateVoter,
148    VoterNotFound,
149    InvalidRegularExpression,
150    RebootstrapRequired,
151    StreamsInvalidTopology,
152    StreamsInvalidTopologyEpoch,
153    StreamsTopologyFenced,
154    ShareSessionLimitReached,
155    /// An error code not recognized by this client version.
156    Unknown(i16),
157}
158impl ErrorCode {
159    /// Returns the `i16` wire value for this error code.
160    pub fn code(&self) -> i16 {
161        match self {
162            ErrorCode::UnknownServerError => -1,
163            ErrorCode::None => 0,
164            ErrorCode::OffsetOutOfRange => 1,
165            ErrorCode::CorruptMessage => 2,
166            ErrorCode::UnknownTopicOrPartition => 3,
167            ErrorCode::InvalidFetchSize => 4,
168            ErrorCode::LeaderNotAvailable => 5,
169            ErrorCode::NotLeaderOrFollower => 6,
170            ErrorCode::RequestTimedOut => 7,
171            ErrorCode::BrokerNotAvailable => 8,
172            ErrorCode::ReplicaNotAvailable => 9,
173            ErrorCode::MessageTooLarge => 10,
174            ErrorCode::StaleControllerEpoch => 11,
175            ErrorCode::OffsetMetadataTooLarge => 12,
176            ErrorCode::NetworkException => 13,
177            ErrorCode::CoordinatorLoadInProgress => 14,
178            ErrorCode::CoordinatorNotAvailable => 15,
179            ErrorCode::NotCoordinator => 16,
180            ErrorCode::InvalidTopicException => 17,
181            ErrorCode::RecordListTooLarge => 18,
182            ErrorCode::NotEnoughReplicas => 19,
183            ErrorCode::NotEnoughReplicasAfterAppend => 20,
184            ErrorCode::InvalidRequiredAcks => 21,
185            ErrorCode::IllegalGeneration => 22,
186            ErrorCode::InconsistentGroupProtocol => 23,
187            ErrorCode::InvalidGroupId => 24,
188            ErrorCode::UnknownMemberId => 25,
189            ErrorCode::InvalidSessionTimeout => 26,
190            ErrorCode::RebalanceInProgress => 27,
191            ErrorCode::InvalidCommitOffsetSize => 28,
192            ErrorCode::TopicAuthorizationFailed => 29,
193            ErrorCode::GroupAuthorizationFailed => 30,
194            ErrorCode::ClusterAuthorizationFailed => 31,
195            ErrorCode::InvalidTimestamp => 32,
196            ErrorCode::UnsupportedSaslMechanism => 33,
197            ErrorCode::IllegalSaslState => 34,
198            ErrorCode::UnsupportedVersion => 35,
199            ErrorCode::TopicAlreadyExists => 36,
200            ErrorCode::InvalidPartitions => 37,
201            ErrorCode::InvalidReplicationFactor => 38,
202            ErrorCode::InvalidReplicaAssignment => 39,
203            ErrorCode::InvalidConfig => 40,
204            ErrorCode::NotController => 41,
205            ErrorCode::InvalidRequest => 42,
206            ErrorCode::UnsupportedForMessageFormat => 43,
207            ErrorCode::PolicyViolation => 44,
208            ErrorCode::OutOfOrderSequenceNumber => 45,
209            ErrorCode::DuplicateSequenceNumber => 46,
210            ErrorCode::InvalidProducerEpoch => 47,
211            ErrorCode::InvalidTxnState => 48,
212            ErrorCode::InvalidProducerIdMapping => 49,
213            ErrorCode::InvalidTransactionTimeout => 50,
214            ErrorCode::ConcurrentTransactions => 51,
215            ErrorCode::TransactionCoordinatorFenced => 52,
216            ErrorCode::TransactionalIdAuthorizationFailed => 53,
217            ErrorCode::SecurityDisabled => 54,
218            ErrorCode::OperationNotAttempted => 55,
219            ErrorCode::KafkaStorageError => 56,
220            ErrorCode::LogDirNotFound => 57,
221            ErrorCode::SaslAuthenticationFailed => 58,
222            ErrorCode::UnknownProducerId => 59,
223            ErrorCode::ReassignmentInProgress => 60,
224            ErrorCode::DelegationTokenAuthDisabled => 61,
225            ErrorCode::DelegationTokenNotFound => 62,
226            ErrorCode::DelegationTokenOwnerMismatch => 63,
227            ErrorCode::DelegationTokenRequestNotAllowed => 64,
228            ErrorCode::DelegationTokenAuthorizationFailed => 65,
229            ErrorCode::DelegationTokenExpired => 66,
230            ErrorCode::InvalidPrincipalType => 67,
231            ErrorCode::NonEmptyGroup => 68,
232            ErrorCode::GroupIdNotFound => 69,
233            ErrorCode::FetchSessionIdNotFound => 70,
234            ErrorCode::InvalidFetchSessionEpoch => 71,
235            ErrorCode::ListenerNotFound => 72,
236            ErrorCode::TopicDeletionDisabled => 73,
237            ErrorCode::FencedLeaderEpoch => 74,
238            ErrorCode::UnknownLeaderEpoch => 75,
239            ErrorCode::UnsupportedCompressionType => 76,
240            ErrorCode::StaleBrokerEpoch => 77,
241            ErrorCode::OffsetNotAvailable => 78,
242            ErrorCode::MemberIdRequired => 79,
243            ErrorCode::PreferredLeaderNotAvailable => 80,
244            ErrorCode::GroupMaxSizeReached => 81,
245            ErrorCode::FencedInstanceId => 82,
246            ErrorCode::EligibleLeadersNotAvailable => 83,
247            ErrorCode::ElectionNotNeeded => 84,
248            ErrorCode::NoReassignmentInProgress => 85,
249            ErrorCode::GroupSubscribedToTopic => 86,
250            ErrorCode::InvalidRecord => 87,
251            ErrorCode::UnstableOffsetCommit => 88,
252            ErrorCode::ThrottlingQuotaExceeded => 89,
253            ErrorCode::ProducerFenced => 90,
254            ErrorCode::ResourceNotFound => 91,
255            ErrorCode::DuplicateResource => 92,
256            ErrorCode::UnacceptableCredential => 93,
257            ErrorCode::InconsistentVoterSet => 94,
258            ErrorCode::InvalidUpdateVersion => 95,
259            ErrorCode::FeatureUpdateFailed => 96,
260            ErrorCode::PrincipalDeserializationFailure => 97,
261            ErrorCode::SnapshotNotFound => 98,
262            ErrorCode::PositionOutOfRange => 99,
263            ErrorCode::UnknownTopicId => 100,
264            ErrorCode::DuplicateBrokerRegistration => 101,
265            ErrorCode::BrokerIdNotRegistered => 102,
266            ErrorCode::InconsistentTopicId => 103,
267            ErrorCode::InconsistentClusterId => 104,
268            ErrorCode::TransactionalIdNotFound => 105,
269            ErrorCode::FetchSessionTopicIdError => 106,
270            ErrorCode::IneligibleReplica => 107,
271            ErrorCode::NewLeaderElected => 108,
272            ErrorCode::OffsetMovedToTieredStorage => 109,
273            ErrorCode::FencedMemberEpoch => 110,
274            ErrorCode::UnreleasedInstanceId => 111,
275            ErrorCode::UnsupportedAssignor => 112,
276            ErrorCode::StaleMemberEpoch => 113,
277            ErrorCode::MismatchedEndpointType => 114,
278            ErrorCode::UnsupportedEndpointType => 115,
279            ErrorCode::UnknownControllerId => 116,
280            ErrorCode::UnknownSubscriptionId => 117,
281            ErrorCode::TelemetryTooLarge => 118,
282            ErrorCode::InvalidRegistration => 119,
283            ErrorCode::TransactionAbortable => 120,
284            ErrorCode::InvalidRecordState => 121,
285            ErrorCode::ShareSessionNotFound => 122,
286            ErrorCode::InvalidShareSessionEpoch => 123,
287            ErrorCode::FencedStateEpoch => 124,
288            ErrorCode::InvalidVoterKey => 125,
289            ErrorCode::DuplicateVoter => 126,
290            ErrorCode::VoterNotFound => 127,
291            ErrorCode::InvalidRegularExpression => 128,
292            ErrorCode::RebootstrapRequired => 129,
293            ErrorCode::StreamsInvalidTopology => 130,
294            ErrorCode::StreamsInvalidTopologyEpoch => 131,
295            ErrorCode::StreamsTopologyFenced => 132,
296            ErrorCode::ShareSessionLimitReached => 133,
297            ErrorCode::Unknown(c) => *c,
298        }
299    }
300    /// Returns `true` if the operation that produced this error can be retried.
301    ///
302    /// The retriable set matches the Kafka Java client's `RetriableException` hierarchy.
303    /// [`ErrorCode::Unknown`] is **not** retriable (matches Java client behaviour).
304    pub fn is_retriable(&self) -> bool {
305        match self {
306            ErrorCode::CorruptMessage => true,
307            ErrorCode::UnknownTopicOrPartition => true,
308            ErrorCode::LeaderNotAvailable => true,
309            ErrorCode::NotLeaderOrFollower => true,
310            ErrorCode::RequestTimedOut => true,
311            ErrorCode::ReplicaNotAvailable => true,
312            ErrorCode::StaleControllerEpoch => true,
313            ErrorCode::NetworkException => true,
314            ErrorCode::CoordinatorLoadInProgress => true,
315            ErrorCode::CoordinatorNotAvailable => true,
316            ErrorCode::NotCoordinator => true,
317            ErrorCode::NotEnoughReplicas => true,
318            ErrorCode::NotEnoughReplicasAfterAppend => true,
319            ErrorCode::RebalanceInProgress => true,
320            ErrorCode::NotController => true,
321            ErrorCode::FetchSessionIdNotFound => true,
322            ErrorCode::InvalidFetchSessionEpoch => true,
323            ErrorCode::OffsetNotAvailable => true,
324            ErrorCode::PreferredLeaderNotAvailable => true,
325            ErrorCode::EligibleLeadersNotAvailable => true,
326            ErrorCode::ElectionNotNeeded => true,
327            ErrorCode::NoReassignmentInProgress => true,
328            ErrorCode::UnstableOffsetCommit => true,
329            ErrorCode::ThrottlingQuotaExceeded => true,
330            ErrorCode::UnknownTopicId => true,
331            ErrorCode::FetchSessionTopicIdError => true,
332            ErrorCode::NewLeaderElected => true,
333            ErrorCode::OffsetMovedToTieredStorage => true,
334            ErrorCode::FencedMemberEpoch => true,
335            ErrorCode::UnreleasedInstanceId => true,
336            ErrorCode::StaleMemberEpoch => true,
337            ErrorCode::ShareSessionNotFound => true,
338            ErrorCode::InvalidShareSessionEpoch => true,
339            ErrorCode::RebootstrapRequired => true,
340            _ => false,
341        }
342    }
343    /// Returns `true` if this represents an error condition.
344    ///
345    /// Only [`ErrorCode::None`] (code 0) returns `false`.
346    pub fn is_error(&self) -> bool {
347        !matches!(self, ErrorCode::None)
348    }
349}
350impl From<i16> for ErrorCode {
351    fn from(code: i16) -> Self {
352        match code {
353            -1 => ErrorCode::UnknownServerError,
354            0 => ErrorCode::None,
355            1 => ErrorCode::OffsetOutOfRange,
356            2 => ErrorCode::CorruptMessage,
357            3 => ErrorCode::UnknownTopicOrPartition,
358            4 => ErrorCode::InvalidFetchSize,
359            5 => ErrorCode::LeaderNotAvailable,
360            6 => ErrorCode::NotLeaderOrFollower,
361            7 => ErrorCode::RequestTimedOut,
362            8 => ErrorCode::BrokerNotAvailable,
363            9 => ErrorCode::ReplicaNotAvailable,
364            10 => ErrorCode::MessageTooLarge,
365            11 => ErrorCode::StaleControllerEpoch,
366            12 => ErrorCode::OffsetMetadataTooLarge,
367            13 => ErrorCode::NetworkException,
368            14 => ErrorCode::CoordinatorLoadInProgress,
369            15 => ErrorCode::CoordinatorNotAvailable,
370            16 => ErrorCode::NotCoordinator,
371            17 => ErrorCode::InvalidTopicException,
372            18 => ErrorCode::RecordListTooLarge,
373            19 => ErrorCode::NotEnoughReplicas,
374            20 => ErrorCode::NotEnoughReplicasAfterAppend,
375            21 => ErrorCode::InvalidRequiredAcks,
376            22 => ErrorCode::IllegalGeneration,
377            23 => ErrorCode::InconsistentGroupProtocol,
378            24 => ErrorCode::InvalidGroupId,
379            25 => ErrorCode::UnknownMemberId,
380            26 => ErrorCode::InvalidSessionTimeout,
381            27 => ErrorCode::RebalanceInProgress,
382            28 => ErrorCode::InvalidCommitOffsetSize,
383            29 => ErrorCode::TopicAuthorizationFailed,
384            30 => ErrorCode::GroupAuthorizationFailed,
385            31 => ErrorCode::ClusterAuthorizationFailed,
386            32 => ErrorCode::InvalidTimestamp,
387            33 => ErrorCode::UnsupportedSaslMechanism,
388            34 => ErrorCode::IllegalSaslState,
389            35 => ErrorCode::UnsupportedVersion,
390            36 => ErrorCode::TopicAlreadyExists,
391            37 => ErrorCode::InvalidPartitions,
392            38 => ErrorCode::InvalidReplicationFactor,
393            39 => ErrorCode::InvalidReplicaAssignment,
394            40 => ErrorCode::InvalidConfig,
395            41 => ErrorCode::NotController,
396            42 => ErrorCode::InvalidRequest,
397            43 => ErrorCode::UnsupportedForMessageFormat,
398            44 => ErrorCode::PolicyViolation,
399            45 => ErrorCode::OutOfOrderSequenceNumber,
400            46 => ErrorCode::DuplicateSequenceNumber,
401            47 => ErrorCode::InvalidProducerEpoch,
402            48 => ErrorCode::InvalidTxnState,
403            49 => ErrorCode::InvalidProducerIdMapping,
404            50 => ErrorCode::InvalidTransactionTimeout,
405            51 => ErrorCode::ConcurrentTransactions,
406            52 => ErrorCode::TransactionCoordinatorFenced,
407            53 => ErrorCode::TransactionalIdAuthorizationFailed,
408            54 => ErrorCode::SecurityDisabled,
409            55 => ErrorCode::OperationNotAttempted,
410            56 => ErrorCode::KafkaStorageError,
411            57 => ErrorCode::LogDirNotFound,
412            58 => ErrorCode::SaslAuthenticationFailed,
413            59 => ErrorCode::UnknownProducerId,
414            60 => ErrorCode::ReassignmentInProgress,
415            61 => ErrorCode::DelegationTokenAuthDisabled,
416            62 => ErrorCode::DelegationTokenNotFound,
417            63 => ErrorCode::DelegationTokenOwnerMismatch,
418            64 => ErrorCode::DelegationTokenRequestNotAllowed,
419            65 => ErrorCode::DelegationTokenAuthorizationFailed,
420            66 => ErrorCode::DelegationTokenExpired,
421            67 => ErrorCode::InvalidPrincipalType,
422            68 => ErrorCode::NonEmptyGroup,
423            69 => ErrorCode::GroupIdNotFound,
424            70 => ErrorCode::FetchSessionIdNotFound,
425            71 => ErrorCode::InvalidFetchSessionEpoch,
426            72 => ErrorCode::ListenerNotFound,
427            73 => ErrorCode::TopicDeletionDisabled,
428            74 => ErrorCode::FencedLeaderEpoch,
429            75 => ErrorCode::UnknownLeaderEpoch,
430            76 => ErrorCode::UnsupportedCompressionType,
431            77 => ErrorCode::StaleBrokerEpoch,
432            78 => ErrorCode::OffsetNotAvailable,
433            79 => ErrorCode::MemberIdRequired,
434            80 => ErrorCode::PreferredLeaderNotAvailable,
435            81 => ErrorCode::GroupMaxSizeReached,
436            82 => ErrorCode::FencedInstanceId,
437            83 => ErrorCode::EligibleLeadersNotAvailable,
438            84 => ErrorCode::ElectionNotNeeded,
439            85 => ErrorCode::NoReassignmentInProgress,
440            86 => ErrorCode::GroupSubscribedToTopic,
441            87 => ErrorCode::InvalidRecord,
442            88 => ErrorCode::UnstableOffsetCommit,
443            89 => ErrorCode::ThrottlingQuotaExceeded,
444            90 => ErrorCode::ProducerFenced,
445            91 => ErrorCode::ResourceNotFound,
446            92 => ErrorCode::DuplicateResource,
447            93 => ErrorCode::UnacceptableCredential,
448            94 => ErrorCode::InconsistentVoterSet,
449            95 => ErrorCode::InvalidUpdateVersion,
450            96 => ErrorCode::FeatureUpdateFailed,
451            97 => ErrorCode::PrincipalDeserializationFailure,
452            98 => ErrorCode::SnapshotNotFound,
453            99 => ErrorCode::PositionOutOfRange,
454            100 => ErrorCode::UnknownTopicId,
455            101 => ErrorCode::DuplicateBrokerRegistration,
456            102 => ErrorCode::BrokerIdNotRegistered,
457            103 => ErrorCode::InconsistentTopicId,
458            104 => ErrorCode::InconsistentClusterId,
459            105 => ErrorCode::TransactionalIdNotFound,
460            106 => ErrorCode::FetchSessionTopicIdError,
461            107 => ErrorCode::IneligibleReplica,
462            108 => ErrorCode::NewLeaderElected,
463            109 => ErrorCode::OffsetMovedToTieredStorage,
464            110 => ErrorCode::FencedMemberEpoch,
465            111 => ErrorCode::UnreleasedInstanceId,
466            112 => ErrorCode::UnsupportedAssignor,
467            113 => ErrorCode::StaleMemberEpoch,
468            114 => ErrorCode::MismatchedEndpointType,
469            115 => ErrorCode::UnsupportedEndpointType,
470            116 => ErrorCode::UnknownControllerId,
471            117 => ErrorCode::UnknownSubscriptionId,
472            118 => ErrorCode::TelemetryTooLarge,
473            119 => ErrorCode::InvalidRegistration,
474            120 => ErrorCode::TransactionAbortable,
475            121 => ErrorCode::InvalidRecordState,
476            122 => ErrorCode::ShareSessionNotFound,
477            123 => ErrorCode::InvalidShareSessionEpoch,
478            124 => ErrorCode::FencedStateEpoch,
479            125 => ErrorCode::InvalidVoterKey,
480            126 => ErrorCode::DuplicateVoter,
481            127 => ErrorCode::VoterNotFound,
482            128 => ErrorCode::InvalidRegularExpression,
483            129 => ErrorCode::RebootstrapRequired,
484            130 => ErrorCode::StreamsInvalidTopology,
485            131 => ErrorCode::StreamsInvalidTopologyEpoch,
486            132 => ErrorCode::StreamsTopologyFenced,
487            133 => ErrorCode::ShareSessionLimitReached,
488            other => ErrorCode::Unknown(other),
489        }
490    }
491}
492impl From<ErrorCode> for i16 {
493    fn from(error: ErrorCode) -> Self {
494        error.code()
495    }
496}
497impl std::fmt::Display for ErrorCode {
498    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
499        match self {
500            ErrorCode::UnknownServerError => f.write_str(
501                "The server experienced an unexpected error when processing the request.",
502            ),
503            ErrorCode::None => f.write_str("NONE"),
504            ErrorCode::OffsetOutOfRange => f.write_str(
505                "The requested offset is not within the range of offsets maintained by the server.",
506            ),
507            ErrorCode::CorruptMessage => f.write_str(
508                "This message has failed its CRC checksum, exceeds the valid size, has a null key \
509                 for a compacted topic, or is otherwise corrupt.",
510            ),
511            ErrorCode::UnknownTopicOrPartition => {
512                f.write_str("This server does not host this topic-partition.")
513            },
514            ErrorCode::InvalidFetchSize => f.write_str("The requested fetch size is invalid."),
515            ErrorCode::LeaderNotAvailable => f.write_str(
516                "There is no leader for this topic-partition as we are in the middle of a \
517                 leadership election.",
518            ),
519            ErrorCode::NotLeaderOrFollower => f.write_str(
520                "For requests intended only for the leader, this error indicates that the broker \
521                 is not the current leader. For requests intended for any replica, this error \
522                 indicates that the broker is not a replica of the topic partition.",
523            ),
524            ErrorCode::RequestTimedOut => f.write_str("The request timed out."),
525            ErrorCode::BrokerNotAvailable => f.write_str("The broker is not available."),
526            ErrorCode::ReplicaNotAvailable => f.write_str(
527                "The replica is not available for the requested topic-partition. Produce/Fetch \
528                 requests and other requests intended only for the leader or follower return \
529                 NOT_LEADER_OR_FOLLOWER if the broker is not a replica of the topic-partition.",
530            ),
531            ErrorCode::MessageTooLarge => f.write_str(
532                "The request included a message larger than the max message size the server will \
533                 accept.",
534            ),
535            ErrorCode::StaleControllerEpoch => {
536                f.write_str("The controller moved to another broker.")
537            },
538            ErrorCode::OffsetMetadataTooLarge => {
539                f.write_str("The metadata field of the offset request was too large.")
540            },
541            ErrorCode::NetworkException => {
542                f.write_str("The server disconnected before a response was received.")
543            },
544            ErrorCode::CoordinatorLoadInProgress => {
545                f.write_str("The coordinator is loading and hence can't process requests.")
546            },
547            ErrorCode::CoordinatorNotAvailable => f.write_str("The coordinator is not available."),
548            ErrorCode::NotCoordinator => f.write_str("This is not the correct coordinator."),
549            ErrorCode::InvalidTopicException => {
550                f.write_str("The request attempted to perform an operation on an invalid topic.")
551            },
552            ErrorCode::RecordListTooLarge => f.write_str(
553                "The request included message batch larger than the configured segment size on \
554                 the server.",
555            ),
556            ErrorCode::NotEnoughReplicas => f.write_str(
557                "Messages are rejected since there are fewer in-sync replicas than required.",
558            ),
559            ErrorCode::NotEnoughReplicasAfterAppend => f.write_str(
560                "Messages are written to the log, but to fewer in-sync replicas than required.",
561            ),
562            ErrorCode::InvalidRequiredAcks => {
563                f.write_str("Produce request specified an invalid value for required acks.")
564            },
565            ErrorCode::IllegalGeneration => {
566                f.write_str("Specified group generation id is not valid.")
567            },
568            ErrorCode::InconsistentGroupProtocol => f.write_str(
569                "The group member's supported protocols are incompatible with those of existing \
570                 members or first group member tried to join with empty protocol type or empty \
571                 protocol list.",
572            ),
573            ErrorCode::InvalidGroupId => f.write_str("The group id is invalid."),
574            ErrorCode::UnknownMemberId => {
575                f.write_str("The coordinator is not aware of this member.")
576            },
577            ErrorCode::InvalidSessionTimeout => f.write_str(
578                "The session timeout is not within the range allowed by the broker (as configured \
579                 by group.min.session.timeout.ms and group.max.session.timeout.ms).",
580            ),
581            ErrorCode::RebalanceInProgress => {
582                f.write_str("The group is rebalancing, so a rejoin is needed.")
583            },
584            ErrorCode::InvalidCommitOffsetSize => {
585                f.write_str("The committing offset data size is not valid.")
586            },
587            ErrorCode::TopicAuthorizationFailed => f.write_str("Topic authorization failed."),
588            ErrorCode::GroupAuthorizationFailed => f.write_str("Group authorization failed."),
589            ErrorCode::ClusterAuthorizationFailed => f.write_str("Cluster authorization failed."),
590            ErrorCode::InvalidTimestamp => {
591                f.write_str("The timestamp of the message is out of acceptable range.")
592            },
593            ErrorCode::UnsupportedSaslMechanism => {
594                f.write_str("The broker does not support the requested SASL mechanism.")
595            },
596            ErrorCode::IllegalSaslState => {
597                f.write_str("Request is not valid given the current SASL state.")
598            },
599            ErrorCode::UnsupportedVersion => f.write_str("The version of API is not supported."),
600            ErrorCode::TopicAlreadyExists => f.write_str("Topic with this name already exists."),
601            ErrorCode::InvalidPartitions => f.write_str("Number of partitions is below 1."),
602            ErrorCode::InvalidReplicationFactor => f.write_str(
603                "Replication factor is below 1 or larger than the number of available brokers.",
604            ),
605            ErrorCode::InvalidReplicaAssignment => f.write_str("Replica assignment is invalid."),
606            ErrorCode::InvalidConfig => f.write_str("Configuration is invalid."),
607            ErrorCode::NotController => {
608                f.write_str("This is not the correct controller for this cluster.")
609            },
610            ErrorCode::InvalidRequest => f.write_str(
611                "This most likely occurs because of a request being malformed by the client \
612                 library or the message was sent to an incompatible broker. See the broker logs \
613                 for more details.",
614            ),
615            ErrorCode::UnsupportedForMessageFormat => f.write_str(
616                "The message format version on the broker does not support the request.",
617            ),
618            ErrorCode::PolicyViolation => {
619                f.write_str("Request parameters do not satisfy the configured policy.")
620            },
621            ErrorCode::OutOfOrderSequenceNumber => {
622                f.write_str("The broker received an out of order sequence number.")
623            },
624            ErrorCode::DuplicateSequenceNumber => {
625                f.write_str("The broker received a duplicate sequence number.")
626            },
627            ErrorCode::InvalidProducerEpoch => {
628                f.write_str("Producer attempted to produce with an old epoch.")
629            },
630            ErrorCode::InvalidTxnState => {
631                f.write_str("The producer attempted a transactional operation in an invalid state.")
632            },
633            ErrorCode::InvalidProducerIdMapping => f.write_str(
634                "The producer attempted to use a producer id which is not currently assigned to \
635                 its transactional id.",
636            ),
637            ErrorCode::InvalidTransactionTimeout => f.write_str(
638                "The transaction timeout is larger than the maximum value allowed by the broker \
639                 (as configured by transaction.max.timeout.ms).",
640            ),
641            ErrorCode::ConcurrentTransactions => f.write_str(
642                "The producer attempted to update a transaction while another concurrent \
643                 operation on the same transaction was ongoing.",
644            ),
645            ErrorCode::TransactionCoordinatorFenced => f.write_str(
646                "Indicates that the transaction coordinator sending a WriteTxnMarker is no longer \
647                 the current coordinator for a given producer.",
648            ),
649            ErrorCode::TransactionalIdAuthorizationFailed => {
650                f.write_str("Transactional Id authorization failed.")
651            },
652            ErrorCode::SecurityDisabled => f.write_str("Security features are disabled."),
653            ErrorCode::OperationNotAttempted => f.write_str(
654                "The broker did not attempt to execute this operation. This may happen for \
655                 batched RPCs where some operations in the batch failed, causing the broker to \
656                 respond without trying the rest.",
657            ),
658            ErrorCode::KafkaStorageError => {
659                f.write_str("Disk error when trying to access log file on the disk.")
660            },
661            ErrorCode::LogDirNotFound => {
662                f.write_str("The user-specified log directory is not found in the broker config.")
663            },
664            ErrorCode::SaslAuthenticationFailed => f.write_str("SASL Authentication failed."),
665            ErrorCode::UnknownProducerId => f.write_str(
666                "This exception is raised by the broker if it could not locate the producer \
667                 metadata associated with the producerId in question. This could happen if, for \
668                 instance, the producer's records were deleted because their retention time had \
669                 elapsed. Once the last records of the producerId are removed, the producer's \
670                 metadata is removed from the broker, and future appends by the producer will \
671                 return this exception.",
672            ),
673            ErrorCode::ReassignmentInProgress => {
674                f.write_str("A partition reassignment is in progress.")
675            },
676            ErrorCode::DelegationTokenAuthDisabled => {
677                f.write_str("Delegation Token feature is not enabled.")
678            },
679            ErrorCode::DelegationTokenNotFound => {
680                f.write_str("Delegation Token is not found on server.")
681            },
682            ErrorCode::DelegationTokenOwnerMismatch => {
683                f.write_str("Specified Principal is not valid Owner/Renewer.")
684            },
685            ErrorCode::DelegationTokenRequestNotAllowed => f.write_str(
686                "Delegation Token requests are not allowed on PLAINTEXT/1-way SSL channels and on \
687                 delegation token authenticated channels.",
688            ),
689            ErrorCode::DelegationTokenAuthorizationFailed => {
690                f.write_str("Delegation Token authorization failed.")
691            },
692            ErrorCode::DelegationTokenExpired => f.write_str("Delegation Token is expired."),
693            ErrorCode::InvalidPrincipalType => {
694                f.write_str("Supplied principalType is not supported.")
695            },
696            ErrorCode::NonEmptyGroup => f.write_str("The group is not empty."),
697            ErrorCode::GroupIdNotFound => f.write_str("The group id does not exist."),
698            ErrorCode::FetchSessionIdNotFound => f.write_str("The fetch session ID was not found."),
699            ErrorCode::InvalidFetchSessionEpoch => {
700                f.write_str("The fetch session epoch is invalid.")
701            },
702            ErrorCode::ListenerNotFound => f.write_str(
703                "There is no listener on the leader broker that matches the listener on which \
704                 metadata request was processed.",
705            ),
706            ErrorCode::TopicDeletionDisabled => f.write_str("Topic deletion is disabled."),
707            ErrorCode::FencedLeaderEpoch => f.write_str(
708                "The leader epoch in the request is older than the epoch on the broker.",
709            ),
710            ErrorCode::UnknownLeaderEpoch => f.write_str(
711                "The leader epoch in the request is newer than the epoch on the broker.",
712            ),
713            ErrorCode::UnsupportedCompressionType => f.write_str(
714                "The requesting client does not support the compression type of given partition.",
715            ),
716            ErrorCode::StaleBrokerEpoch => f.write_str("Broker epoch has changed."),
717            ErrorCode::OffsetNotAvailable => f.write_str(
718                "The leader high watermark has not caught up from a recent leader election so the \
719                 offsets cannot be guaranteed to be monotonically increasing.",
720            ),
721            ErrorCode::MemberIdRequired => f.write_str(
722                "The group member needs to have a valid member id before actually entering a \
723                 consumer group.",
724            ),
725            ErrorCode::PreferredLeaderNotAvailable => {
726                f.write_str("The preferred leader was not available.")
727            },
728            ErrorCode::GroupMaxSizeReached => {
729                f.write_str("The group has reached its maximum size.")
730            },
731            ErrorCode::FencedInstanceId => f.write_str(
732                "The broker rejected this static consumer since another consumer with the same \
733                 group.instance.id has registered with a different member.id.",
734            ),
735            ErrorCode::EligibleLeadersNotAvailable => {
736                f.write_str("Eligible topic partition leaders are not available.")
737            },
738            ErrorCode::ElectionNotNeeded => {
739                f.write_str("Leader election not needed for topic partition.")
740            },
741            ErrorCode::NoReassignmentInProgress => {
742                f.write_str("No partition reassignment is in progress.")
743            },
744            ErrorCode::GroupSubscribedToTopic => f.write_str(
745                "Deleting offsets of a topic is forbidden while the consumer group is actively \
746                 subscribed to it.",
747            ),
748            ErrorCode::InvalidRecord => f.write_str(
749                "This record has failed the validation on broker and hence will be rejected.",
750            ),
751            ErrorCode::UnstableOffsetCommit => {
752                f.write_str("There are unstable offsets that need to be cleared.")
753            },
754            ErrorCode::ThrottlingQuotaExceeded => {
755                f.write_str("The throttling quota has been exceeded.")
756            },
757            ErrorCode::ProducerFenced => f.write_str(
758                "There is a newer producer with the same transactionalId which fences the current \
759                 one.",
760            ),
761            ErrorCode::ResourceNotFound => {
762                f.write_str("A request illegally referred to a resource that does not exist.")
763            },
764            ErrorCode::DuplicateResource => {
765                f.write_str("A request illegally referred to the same resource twice.")
766            },
767            ErrorCode::UnacceptableCredential => {
768                f.write_str("Requested credential would not meet criteria for acceptability.")
769            },
770            ErrorCode::InconsistentVoterSet => f.write_str(
771                "Indicates that the either the sender or recipient of a voter-only request is not \
772                 one of the expected voters.",
773            ),
774            ErrorCode::InvalidUpdateVersion => f.write_str("The given update version was invalid."),
775            ErrorCode::FeatureUpdateFailed => f.write_str(
776                "Unable to update finalized features due to an unexpected server error.",
777            ),
778            ErrorCode::PrincipalDeserializationFailure => f.write_str(
779                "Request principal deserialization failed during forwarding. This indicates an \
780                 internal error on the broker cluster security setup.",
781            ),
782            ErrorCode::SnapshotNotFound => f.write_str("Requested snapshot was not found."),
783            ErrorCode::PositionOutOfRange => f.write_str(
784                "Requested position is not greater than or equal to zero, and less than the size \
785                 of the snapshot.",
786            ),
787            ErrorCode::UnknownTopicId => f.write_str("This server does not host this topic ID."),
788            ErrorCode::DuplicateBrokerRegistration => {
789                f.write_str("This broker ID is already in use.")
790            },
791            ErrorCode::BrokerIdNotRegistered => {
792                f.write_str("The given broker ID was not registered.")
793            },
794            ErrorCode::InconsistentTopicId => {
795                f.write_str("The log's topic ID did not match the topic ID in the request.")
796            },
797            ErrorCode::InconsistentClusterId => {
798                f.write_str("The clusterId in the request does not match that found on the server.")
799            },
800            ErrorCode::TransactionalIdNotFound => {
801                f.write_str("The transactionalId could not be found.")
802            },
803            ErrorCode::FetchSessionTopicIdError => {
804                f.write_str("The fetch session encountered inconsistent topic ID usage.")
805            },
806            ErrorCode::IneligibleReplica => {
807                f.write_str("The new ISR contains at least one ineligible replica.")
808            },
809            ErrorCode::NewLeaderElected => f.write_str(
810                "The AlterPartition request successfully updated the partition state but the \
811                 leader has changed.",
812            ),
813            ErrorCode::OffsetMovedToTieredStorage => {
814                f.write_str("The requested offset is moved to tiered storage.")
815            },
816            ErrorCode::FencedMemberEpoch => f.write_str(
817                "The member epoch is fenced by the group coordinator. The member must abandon all \
818                 its partitions and rejoin.",
819            ),
820            ErrorCode::UnreleasedInstanceId => f.write_str(
821                "The instance ID is still used by another member in the consumer group. That \
822                 member must leave first.",
823            ),
824            ErrorCode::UnsupportedAssignor => f.write_str(
825                "The assignor or its version range is not supported by the consumer group.",
826            ),
827            ErrorCode::StaleMemberEpoch => f.write_str(
828                "The member epoch is stale. The member must retry after receiving its updated \
829                 member epoch via the ConsumerGroupHeartbeat API.",
830            ),
831            ErrorCode::MismatchedEndpointType => {
832                f.write_str("The request was sent to an endpoint of the wrong type.")
833            },
834            ErrorCode::UnsupportedEndpointType => {
835                f.write_str("This endpoint type is not supported yet.")
836            },
837            ErrorCode::UnknownControllerId => f.write_str("This controller ID is not known."),
838            ErrorCode::UnknownSubscriptionId => f.write_str(
839                "Client sent a push telemetry request with an invalid or outdated subscription ID.",
840            ),
841            ErrorCode::TelemetryTooLarge => f.write_str(
842                "Client sent a push telemetry request larger than the maximum size the broker \
843                 will accept.",
844            ),
845            ErrorCode::InvalidRegistration => {
846                f.write_str("The controller has considered the broker registration to be invalid.")
847            },
848            ErrorCode::TransactionAbortable => f.write_str(
849                "The server encountered an error with the transaction. The client can abort the \
850                 transaction to continue using this transactional ID.",
851            ),
852            ErrorCode::InvalidRecordState => f.write_str(
853                "The record state is invalid. The acknowledgement of delivery could not be \
854                 completed.",
855            ),
856            ErrorCode::ShareSessionNotFound => f.write_str("The share session was not found."),
857            ErrorCode::InvalidShareSessionEpoch => {
858                f.write_str("The share session epoch is invalid.")
859            },
860            ErrorCode::FencedStateEpoch => f.write_str(
861                "The share coordinator rejected the request because the share-group state epoch \
862                 did not match.",
863            ),
864            ErrorCode::InvalidVoterKey => {
865                f.write_str("The voter key doesn't match the receiving replica's key.")
866            },
867            ErrorCode::DuplicateVoter => {
868                f.write_str("The voter is already part of the set of voters.")
869            },
870            ErrorCode::VoterNotFound => f.write_str("The voter is not part of the set of voters."),
871            ErrorCode::InvalidRegularExpression => {
872                f.write_str("The regular expression is not valid.")
873            },
874            ErrorCode::RebootstrapRequired => f.write_str(
875                "Client metadata is stale. The client should rebootstrap to obtain new metadata.",
876            ),
877            ErrorCode::StreamsInvalidTopology => f.write_str("The supplied topology is invalid."),
878            ErrorCode::StreamsInvalidTopologyEpoch => {
879                f.write_str("The supplied topology epoch is invalid.")
880            },
881            ErrorCode::StreamsTopologyFenced => {
882                f.write_str("The supplied topology epoch is outdated.")
883            },
884            ErrorCode::ShareSessionLimitReached => {
885                f.write_str("The limit of share sessions has been reached.")
886            },
887            ErrorCode::Unknown(code) => write!(f, "Unknown error code: {}", code),
888        }
889    }
890}