confluent_kafka/common/error.rs
1// Copyright 2025 Confluent Inc.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15//! The crate's flat base error type and the machinery behind it.
16//!
17//! [`Error`] is the single type every fallible API returns. It has no Java
18//! counterpart: Rust cannot express Java's exception hierarchy, so one enum
19//! holds both `KafkaException`'s subclasses and the generic `java.lang` /
20//! `java.util` runtime exceptions that sit beside it (CLAUDE.md §12.3).
21//!
22//! Flattening the hierarchy destroys the `extends` chain, so the traits and
23//! macros that reconstruct it live here too, next to the enum they serve:
24//!
25//! - [`ErrorHierarchy`] recovers each intermediate Java class as a predicate;
26//! [`ErrorCode`], [`ErrorName`], [`ErrorMessage`] and [`ErrorSource`] are the
27//! per-payload answers [`Error`] delegates to.
28//! - [`kafka_error_type`] and [`message_only_error`] declare the two shapes of
29//! error class that carry nothing beyond a message, one per Java class.
30//!
31//! Java's `KafkaException` base class is a *different* type: the `KafkaError`
32//! struct, which every specific error struct embeds and which is re-exported
33//! alongside this enum as [`crate::common::KafkaError`].
34//! [`Error::KafkaError`](Error::KafkaError) is therefore the variant for a
35//! *bare* `KafkaException` — one with no subclass-specific fields. It is NOT
36//! "the variant for Kafka errors"; [`Error::Timeout`](Error::Timeout) and the
37//! rest are Kafka errors too. See [`Error::is_kafka_error`] for that test.
38
39// `#[delegatable_trait_remote]` (below) expands to a helper trait,
40// `MatchDisplay`, that the `Delegate` derive on `Error` makes reachable without
41// being nameable. It is macro plumbing, not API, and ambassador neither forwards
42// attributes to it nor lets it move into a submodule, so the allowance is
43// file-wide. It covers only items defined in this file: a crate-private type
44// leaking from elsewhere is still reported at its own definition.
45#![expect(unnameable_types)]
46
47use std::collections::HashSet;
48use std::ffi::c_void;
49// Imported unqualified so that `#[delegate(Display)]` on `Error` resolves to
50// the std trait; the `#[delegatable_trait_remote]` stub below only registers
51// the signature with ambassador, it does not define a trait.
52use std::fmt::Display;
53
54use ambassador::{Delegate, delegatable_trait, delegatable_trait_remote};
55
56use super::protocol::Errors;
57use crate::common::InvalidRecordError;
58use crate::common::KafkaError;
59use crate::common::LocalCallbackError;
60use crate::common::LocalConcurrentModificationError;
61use crate::common::LocalIllegalArgumentError;
62use crate::common::LocalIllegalStateError;
63use crate::common::LocalNullPointerError;
64use crate::common::LocalTimeoutError;
65use crate::common::LocalUnsupportedOperationError;
66use crate::common::config::ConfigError;
67use crate::common::errors::{
68 ApiError, AuthenticationError, AuthorizationError, AuthorizerNotReadyError, BootstrapResolutionError,
69 BrokerIdNotRegisteredError, BrokerNotAvailableError, ClusterAuthorizationError, ConcurrentTransactionsError,
70 ControllerIdNotRegisteredError, ControllerMovedError, CoordinatorLoadInProgressError, CoordinatorNotAvailableError,
71 CorruptRecordError, DelegationTokenAuthorizationError, DelegationTokenDisabledError, DelegationTokenExpiredError,
72 DelegationTokenNotFoundError, DelegationTokenOwnerMismatchError, DisconnectError, DuplicateBrokerRegistrationError,
73 DuplicateResourceError, DuplicateSequenceError, DuplicateVoterError, ElectionNotNeededError,
74 EligibleLeadersNotAvailableError, FeatureUpdateFailedError, FencedInstanceIdError, FencedLeaderEpochError,
75 FencedMemberEpochError, FencedStateEpochError, FetchSessionIdNotFoundError, FetchSessionTopicIdError,
76 GroupAuthorizationError, GroupDeletionFailedError, GroupIdNotFoundError, GroupMaxSizeReachedError,
77 GroupNotEmptyError, GroupSubscribedToTopicError, IllegalGenerationError, IllegalSaslStateError,
78 InconsistentClusterIdError, InconsistentGroupProtocolError, InconsistentTopicIdError, InconsistentVoterSetError,
79 IneligibleReplicaError, InterruptError, InvalidCommitOffsetSizeError, InvalidConfigurationError,
80 InvalidFetchSessionEpochError, InvalidFetchSizeError, InvalidGroupIdError, InvalidOffsetError,
81 InvalidPartitionsError, InvalidPidMappingError, InvalidPrincipalTypeError, InvalidProducerEpochError,
82 InvalidRecordStateError, InvalidRegistrationError, InvalidRegularExpression, InvalidReplicaAssignmentError,
83 InvalidReplicationFactorError, InvalidRequestError, InvalidRequiredAcksError, InvalidSessionTimeoutError,
84 InvalidShareSessionEpochError, InvalidTimestampError, InvalidTopicError, InvalidTxnStateError,
85 InvalidTxnTimeoutError, InvalidUpdateVersionError, InvalidVoterKeyError, KafkaStorageError,
86 LeaderNotAvailableError, ListenerNotFoundError, LogDirNotFoundError, MemberIdRequiredError,
87 MismatchedEndpointTypeError, NetworkError, NewLeaderElectedError, NoReassignmentInProgressError,
88 NotControllerError, NotCoordinatorError, NotEnoughReplicasAfterAppendError, NotEnoughReplicasError,
89 NotLeaderOrFollowerError, OffsetMetadataTooLarge, OffsetMovedToTieredStorageError, OffsetNotAvailableError,
90 OffsetOutOfRangeError, OperationNotAttemptedError, OutOfOrderSequenceError, PolicyViolationError,
91 PositionOutOfRangeError, PreferredLeaderNotAvailableError, PrincipalDeserializationError, ProducerFencedError,
92 ReassignmentInProgressError, RebalanceInProgressError, RebootstrapRequiredError, RecordBatchTooLargeError,
93 RecordDeserializationError, RecordTooLargeError, ReplicaNotAvailableError, ResourceNotFoundError,
94 SaslAuthenticationError, SecurityDisabledError, SerializationError, ShareSessionLimitReachedError,
95 ShareSessionNotFoundError, SnapshotNotFoundError, SslAuthenticationError, StaleBrokerEpochError,
96 StaleMemberEpochError, StreamsInvalidTopologyEpochError, StreamsInvalidTopologyError,
97 StreamsTopologyDescriptionUpdateFailedError, StreamsTopologyFencedError, TelemetryTooLargeError,
98 ThrottlingQuotaExceededError, TimeoutError, TopicAuthorizationError, TopicDeletionDisabledError, TopicExistsError,
99 TransactionAbortableError, TransactionAbortedError, TransactionCoordinatorFencedError,
100 TransactionalIdAuthorizationError, TransactionalIdNotFoundError, UnacceptableCredentialError,
101 UnknownControllerIdError, UnknownLeaderEpochError, UnknownMemberIdError, UnknownProducerIdError,
102 UnknownServerError, UnknownSubscriptionIdError, UnknownTopicIdError, UnknownTopicOrPartitionError,
103 UnreleasedInstanceIdError, UnstableOffsetCommitError, UnsupportedAssignorError, UnsupportedByAuthenticationError,
104 UnsupportedCompressionTypeError, UnsupportedEndpointTypeError, UnsupportedForMessageFormatError,
105 UnsupportedSaslMechanismError, UnsupportedVersionError, VoterNotFoundError, WakeupError,
106};
107use crate::common::metrics::QuotaViolationError;
108use crate::common::network::InvalidReceiveError;
109use crate::common::protocol::types::SchemaError;
110use crate::common::requests::CorrelationIdMismatchError;
111use crate::consumer::{
112 ConsumerCommitFailedError, ConsumerLogTruncationError, ConsumerNoOffsetForPartitionError,
113 ConsumerOffsetOutOfRangeError, ConsumerRetriableCommitFailedError,
114};
115use crate::producer::ProducerBufferExhaustedError;
116
117/// Registers `std::fmt::Display` for delegation.
118///
119/// Ambassador cannot see a foreign trait's signature, so it is restated here.
120/// This declaration defines nothing — the attribute consumes it and emits only
121/// the delegation macro, which is why `Display` above still refers to the std
122/// trait.
123#[delegatable_trait_remote]
124trait Display {
125 fn fmt(&self, f: &mut ::std::fmt::Formatter) -> Result<(), ::std::fmt::Error>;
126}
127
128// ---------------------------------------------------------------------------
129// The exception hierarchy, as a trait
130// ---------------------------------------------------------------------------
131
132/// Java's exception hierarchy, recovered as a set of predicates.
133///
134/// **Mechanism, not API.** This trait is `pub(crate)`: it exists so each error
135/// payload can declare its ancestry once, and so ambassador can generate
136/// [`Error`]'s forwarding. Callers use the inherent methods on [`Error`], which
137/// carry the public documentation for each predicate.
138///
139/// It has no Java counterpart — it is the Rust encoding of the `extends` chain
140/// that [`Error`] flattens away (CLAUDE.md §12.3/§12.4). One method per
141/// **intermediate** class in Java's tree, then one *class predicate* per
142/// [`Error`] variant whose class is not already among them (CLAUDE.md §3).
143/// Leaf classes get one too: a Java release may add a subclass to any class,
144/// which becomes a new variant here, and a caller testing the predicate keeps
145/// matching it where a variant match would not.
146///
147/// Every method defaults to `false`, so each concrete error type declares its
148/// ancestry by overriding exactly the predicates that are `true` for it. The
149/// override list of an `impl` therefore reads as that type's Java `extends`
150/// chain, which is the property a flat enum otherwise destroys:
151///
152/// ```text
153/// TimeoutException extends RetriableException extends ApiException extends KafkaException
154/// => is_retriable_error + is_api_error + is_kafka_error are overridden to true
155/// ```
156///
157/// [`Error`] implements this trait through ambassador's `#[derive(Delegate)]`,
158/// which generates the `match` forwarding each predicate to the variant's
159/// payload. That is why every variant carries a distinct payload type: the
160/// payload — not the variant — is what answers the question, and two variants
161/// sharing one type could only ever give one answer.
162///
163/// Predicates are NOT complements of one another. [`SerializationError`] and
164/// [`WakeupError`] are `KafkaException`s that are not `ApiException`s, so they
165/// answer `true` to [`is_kafka_error`](Self::is_kafka_error) and `false` to
166/// [`is_api_error`](Self::is_api_error).
167#[delegatable_trait]
168pub(crate) trait ErrorHierarchy {
169 /// Whether this is a Kafka error rather than a generic programming error —
170 /// Java's `t instanceof KafkaException`.
171 ///
172 /// `false` for exactly the generic `java.lang` / `java.util` runtime
173 /// exceptions, which are siblings of `KafkaException` rather than
174 /// subclasses (`org.apache.kafka.common.KafkaException` extends `RuntimeException`): [`LocalIllegalArgumentError`],
175 /// [`LocalIllegalStateError`], [`LocalConcurrentModificationError`],
176 /// [`LocalTimeoutError`], [`LocalUnsupportedOperationError`],
177 /// [`LocalNullPointerError`] — and
178 /// [`LocalCallbackError`], which has no Java class
179 /// but stands in for a foreign callback's `Throwable`.
180 ///
181 /// Two call sites depend on this: `ConsumerUtils.maybeWrapAsKafkaException`
182 /// (a Kafka error passes through unchanged, a generic one gets wrapped),
183 /// and `FetchCollector`, whose Java `catch (KafkaException e)` cannot catch
184 /// a generic error.
185 fn is_kafka_error(&self) -> bool {
186 false
187 }
188
189 /// Whether this error's Java class extends `ApiException`.
190 ///
191 /// Narrower than [`is_kafka_error`](Self::is_kafka_error):
192 /// `SerializationException` and `WakeupException` extend `KafkaException`
193 /// directly, bypassing `ApiException`. `KafkaProducer.doSend()` catches
194 /// `ApiException` and fails the record's future; anything else propagates.
195 fn is_api_error(&self) -> bool {
196 false
197 }
198
199 /// Whether this error's Java class extends `RetriableException` — i.e.
200 /// whether re-sending the failed request can succeed.
201 fn is_retriable_error(&self) -> bool {
202 false
203 }
204
205 /// Whether this error's Java class extends `RefreshRetriableException` —
206 /// retriable, and a metadata / coordinator refresh is what clears it.
207 fn is_refresh_retriable_error(&self) -> bool {
208 false
209 }
210
211 /// Whether this error's Java class extends `TimeoutException`.
212 ///
213 /// Intermediate because `BufferExhaustedException extends TimeoutException`
214 /// (`clients/producer/BufferExhaustedException.java`), so Java's
215 /// `catch (TimeoutException e)` catches the buffer-exhausted case too.
216 fn is_timeout_error(&self) -> bool {
217 false
218 }
219
220 /// Whether this error's Java class extends `InvalidMetadataException` — the
221 /// client's cached metadata may be stale.
222 fn is_invalid_metadata_error(&self) -> bool {
223 false
224 }
225
226 /// Whether this error's Java class extends `InvalidConfigurationException`.
227 ///
228 /// Parent of BOTH [`is_authentication_error`](Self::is_authentication_error)
229 /// and [`is_authorization_error`](Self::is_authorization_error) — in Kafka
230 /// 4.2 those two extend `InvalidConfigurationException`, not `ApiException`
231 /// directly, so anything answering `true` to either must answer `true` here.
232 fn is_invalid_configuration_error(&self) -> bool {
233 false
234 }
235
236 /// Whether this error's Java class extends `ApplicationRecoverableException`
237 /// — the application can recover by re-initialising its producer or
238 /// rejoining its group, but the current epoch / session is lost.
239 fn is_application_recoverable_error(&self) -> bool {
240 false
241 }
242
243 /// Whether this error's Java class extends `InvalidOffsetException`.
244 fn is_invalid_offset_error(&self) -> bool {
245 false
246 }
247
248 /// Whether this error's Java class extends
249 /// `org.apache.kafka.clients.consumer.InvalidOffsetException`.
250 ///
251 /// A **different** class from the one
252 /// [`is_invalid_offset_error`](Self::is_invalid_offset_error) tests: the
253 /// consumer package has its own abstract `InvalidOffsetException` extending
254 /// `KafkaException`, whereas `common.errors`' is concrete and extends
255 /// `ApiException`. Java keeps them apart by package; this flat namespace
256 /// cannot, so the package is carried in the name.
257 fn is_consumer_invalid_offset_error(&self) -> bool {
258 false
259 }
260
261 /// Whether this error's Java class extends
262 /// `org.apache.kafka.clients.consumer.OffsetOutOfRangeException`.
263 ///
264 /// Intermediate because `LogTruncationException` extends it
265 /// (`clients/consumer/LogTruncationException.java`). Nested inside
266 /// [`is_consumer_invalid_offset_error`](Self::is_consumer_invalid_offset_error),
267 /// and distinct from the `common.errors` class of the same name.
268 fn is_consumer_offset_out_of_range_error(&self) -> bool {
269 false
270 }
271
272 /// Whether this error's Java class extends `OutOfOrderSequenceException`.
273 fn is_out_of_order_sequence_error(&self) -> bool {
274 false
275 }
276
277 /// Whether this error's Java class extends `SerializationException`.
278 ///
279 /// No protocol code maps here — `SerializationException` and its subclass
280 /// `RecordDeserializationException` are raised client-side — so only the
281 /// [`SerializationError`] payload answers `true`.
282 fn is_serialization_error(&self) -> bool {
283 false
284 }
285
286 /// Whether this error's Java class extends `AuthenticationException`.
287 ///
288 /// Overridden by the five payloads whose `extends:` list names it:
289 /// [`AuthenticationError`] itself — the concrete base class, which has no
290 /// `Errors` entry of its own but reports [`Errors::InvalidConfig`] through
291 /// `forException`'s superclass walk — plus [`SaslAuthenticationError`],
292 /// [`SslAuthenticationError`], [`IllegalSaslStateError`] and
293 /// [`UnsupportedSaslMechanismError`]. Only three of the five have an entry
294 /// in `Errors`, so this is NOT "the broker-reported codes": a handshake
295 /// failure detected locally is carried, as the class it was raised as,
296 /// inside an `io::Error` (`common::network::authentication_io_error`) and
297 /// reaches the application unchanged, answering `true` here.
298 fn is_authentication_error(&self) -> bool {
299 false
300 }
301
302 /// Whether this error's Java class extends `AuthorizationException`.
303 ///
304 /// Overridden by the six payloads whose `extends:` list names it:
305 /// [`AuthorizationError`] itself — the concrete base class, which reports
306 /// [`Errors::InvalidConfig`] by inheritance and carries no
307 /// protocol code — plus [`TopicAuthorizationError`],
308 /// [`GroupAuthorizationError`], [`ClusterAuthorizationError`],
309 /// [`TransactionalIdAuthorizationError`] and
310 /// [`DelegationTokenAuthorizationError`].
311 fn is_authorization_error(&self) -> bool {
312 false
313 }
314
315 // -- Class predicates ------------------------------------------------
316 //
317 // One per `Error` variant whose class is not already an intermediate
318 // predicate above (CLAUDE.md §3: every error has its predicate). Each
319 // means "this class or any subclass": a Java subclass added later becomes
320 // a new variant whose payload lists its parent's predicate here too, so a
321 // caller testing the predicate keeps matching it where a variant match
322 // would not. `cargo xtask lint-custom` (`check-error-predicate`) keeps this
323 // list, the `Box` forwarders, the `Error` forwarders and the C exports in
324 // step with the enum.
325
326 /// Whether this error's Java class is, or extends, `java.lang.IllegalArgumentException`.
327 fn is_local_illegal_argument_error(&self) -> bool {
328 false
329 }
330
331 /// Whether this error's Java class is, or extends, `java.lang.IllegalStateException`.
332 fn is_local_illegal_state_error(&self) -> bool {
333 false
334 }
335
336 /// Whether this error's Java class is, or extends, `java.util.ConcurrentModificationException`.
337 fn is_local_concurrent_modification_error(&self) -> bool {
338 false
339 }
340
341 /// Whether this error's Java class is, or extends, `java.util.concurrent.TimeoutException`.
342 fn is_local_timeout_error(&self) -> bool {
343 false
344 }
345
346 /// Whether this error's Java class is, or extends, `java.lang.UnsupportedOperationException`.
347 fn is_local_unsupported_operation_error(&self) -> bool {
348 false
349 }
350
351 /// Whether this error's Java class is, or extends, `java.lang.NullPointerException`.
352 fn is_local_null_pointer_error(&self) -> bool {
353 false
354 }
355
356 /// Whether this is an error raised by a callback written in another
357 /// language ([`LocalCallbackError`]; no Java class).
358 fn is_local_callback_error(&self) -> bool {
359 false
360 }
361
362 /// Whether this error's Java class is, or extends,
363 /// `org.apache.kafka.common.errors.AuthorizerNotReadyException`.
364 fn is_authorizer_not_ready_error(&self) -> bool {
365 false
366 }
367
368 /// Whether this error's Java class is, or extends,
369 /// `org.apache.kafka.common.errors.BootstrapResolutionException`.
370 fn is_bootstrap_resolution_error(&self) -> bool {
371 false
372 }
373
374 /// Whether this error's Java class is, or extends,
375 /// `org.apache.kafka.common.errors.BrokerIdNotRegisteredException`.
376 fn is_broker_id_not_registered_error(&self) -> bool {
377 false
378 }
379
380 /// Whether this error's Java class is, or extends,
381 /// `org.apache.kafka.common.errors.BrokerNotAvailableException`.
382 fn is_broker_not_available_error(&self) -> bool {
383 false
384 }
385
386 /// Whether this error's Java class is, or extends,
387 /// `org.apache.kafka.clients.producer.BufferExhaustedException`.
388 fn is_producer_buffer_exhausted_error(&self) -> bool {
389 false
390 }
391
392 /// Whether this error's Java class is, or extends,
393 /// `org.apache.kafka.common.errors.ClusterAuthorizationException`.
394 fn is_cluster_authorization_error(&self) -> bool {
395 false
396 }
397
398 /// Whether this error's Java class is, or extends,
399 /// `org.apache.kafka.common.errors.ConcurrentTransactionsException`.
400 fn is_concurrent_transactions_error(&self) -> bool {
401 false
402 }
403
404 /// Whether this error's Java class is, or extends,
405 /// `org.apache.kafka.common.errors.ControllerIdNotRegisteredException`.
406 fn is_controller_id_not_registered_error(&self) -> bool {
407 false
408 }
409
410 /// Whether this error's Java class is, or extends,
411 /// `org.apache.kafka.common.errors.ControllerMovedException`.
412 fn is_controller_moved_error(&self) -> bool {
413 false
414 }
415
416 /// Whether this error's Java class is, or extends,
417 /// `org.apache.kafka.common.errors.CoordinatorLoadInProgressException`.
418 fn is_coordinator_load_in_progress_error(&self) -> bool {
419 false
420 }
421
422 /// Whether this error's Java class is, or extends,
423 /// `org.apache.kafka.common.errors.CoordinatorNotAvailableException`.
424 fn is_coordinator_not_available_error(&self) -> bool {
425 false
426 }
427
428 /// Whether this error's Java class is, or extends,
429 /// `org.apache.kafka.common.requests.CorrelationIdMismatchException`.
430 fn is_correlation_id_mismatch_error(&self) -> bool {
431 false
432 }
433
434 /// Whether this error's Java class is, or extends,
435 /// `org.apache.kafka.common.errors.CorruptRecordException`.
436 fn is_corrupt_record_error(&self) -> bool {
437 false
438 }
439
440 /// Whether this error's Java class is, or extends,
441 /// `org.apache.kafka.common.errors.DelegationTokenAuthorizationException`.
442 fn is_delegation_token_authorization_error(&self) -> bool {
443 false
444 }
445
446 /// Whether this error's Java class is, or extends,
447 /// `org.apache.kafka.common.errors.DelegationTokenDisabledException`.
448 fn is_delegation_token_disabled_error(&self) -> bool {
449 false
450 }
451
452 /// Whether this error's Java class is, or extends,
453 /// `org.apache.kafka.common.errors.DelegationTokenExpiredException`.
454 fn is_delegation_token_expired_error(&self) -> bool {
455 false
456 }
457
458 /// Whether this error's Java class is, or extends,
459 /// `org.apache.kafka.common.errors.DelegationTokenNotFoundException`.
460 fn is_delegation_token_not_found_error(&self) -> bool {
461 false
462 }
463
464 /// Whether this error's Java class is, or extends,
465 /// `org.apache.kafka.common.errors.DelegationTokenOwnerMismatchException`.
466 fn is_delegation_token_owner_mismatch_error(&self) -> bool {
467 false
468 }
469
470 /// Whether this error's Java class is, or extends,
471 /// `org.apache.kafka.common.errors.DisconnectException`.
472 fn is_disconnect_error(&self) -> bool {
473 false
474 }
475
476 /// Whether this error's Java class is, or extends,
477 /// `org.apache.kafka.common.errors.DuplicateBrokerRegistrationException`.
478 fn is_duplicate_broker_registration_error(&self) -> bool {
479 false
480 }
481
482 /// Whether this error's Java class is, or extends,
483 /// `org.apache.kafka.common.errors.DuplicateResourceException`.
484 fn is_duplicate_resource_error(&self) -> bool {
485 false
486 }
487
488 /// Whether this error's Java class is, or extends,
489 /// `org.apache.kafka.common.errors.DuplicateSequenceException`.
490 fn is_duplicate_sequence_error(&self) -> bool {
491 false
492 }
493
494 /// Whether this error's Java class is, or extends,
495 /// `org.apache.kafka.common.errors.DuplicateVoterException`.
496 fn is_duplicate_voter_error(&self) -> bool {
497 false
498 }
499
500 /// Whether this error's Java class is, or extends,
501 /// `org.apache.kafka.common.errors.ElectionNotNeededException`.
502 fn is_election_not_needed_error(&self) -> bool {
503 false
504 }
505
506 /// Whether this error's Java class is, or extends,
507 /// `org.apache.kafka.common.errors.EligibleLeadersNotAvailableException`.
508 fn is_eligible_leaders_not_available_error(&self) -> bool {
509 false
510 }
511
512 /// Whether this error's Java class is, or extends,
513 /// `org.apache.kafka.common.errors.FeatureUpdateFailedException`.
514 fn is_feature_update_failed_error(&self) -> bool {
515 false
516 }
517
518 /// Whether this error's Java class is, or extends,
519 /// `org.apache.kafka.common.errors.FencedInstanceIdException`.
520 fn is_fenced_instance_id_error(&self) -> bool {
521 false
522 }
523
524 /// Whether this error's Java class is, or extends,
525 /// `org.apache.kafka.common.errors.FencedLeaderEpochException`.
526 fn is_fenced_leader_epoch_error(&self) -> bool {
527 false
528 }
529
530 /// Whether this error's Java class is, or extends,
531 /// `org.apache.kafka.common.errors.FencedMemberEpochException`.
532 fn is_fenced_member_epoch_error(&self) -> bool {
533 false
534 }
535
536 /// Whether this error's Java class is, or extends,
537 /// `org.apache.kafka.common.errors.FencedStateEpochException`.
538 fn is_fenced_state_epoch_error(&self) -> bool {
539 false
540 }
541
542 /// Whether this error's Java class is, or extends,
543 /// `org.apache.kafka.common.errors.FetchSessionIdNotFoundException`.
544 fn is_fetch_session_id_not_found_error(&self) -> bool {
545 false
546 }
547
548 /// Whether this error's Java class is, or extends,
549 /// `org.apache.kafka.common.errors.FetchSessionTopicIdException`.
550 fn is_fetch_session_topic_id_error(&self) -> bool {
551 false
552 }
553
554 /// Whether this error's Java class is, or extends,
555 /// `org.apache.kafka.common.errors.GroupAuthorizationException`.
556 fn is_group_authorization_error(&self) -> bool {
557 false
558 }
559
560 /// Whether this error's Java class is, or extends,
561 /// `org.apache.kafka.common.errors.GroupDeletionFailedException`.
562 fn is_group_deletion_failed_error(&self) -> bool {
563 false
564 }
565
566 /// Whether this error's Java class is, or extends,
567 /// `org.apache.kafka.common.errors.GroupIdNotFoundException`.
568 fn is_group_id_not_found_error(&self) -> bool {
569 false
570 }
571
572 /// Whether this error's Java class is, or extends,
573 /// `org.apache.kafka.common.errors.GroupMaxSizeReachedException`.
574 fn is_group_max_size_reached_error(&self) -> bool {
575 false
576 }
577
578 /// Whether this error's Java class is, or extends,
579 /// `org.apache.kafka.common.errors.GroupNotEmptyException`.
580 fn is_group_not_empty_error(&self) -> bool {
581 false
582 }
583
584 /// Whether this error's Java class is, or extends,
585 /// `org.apache.kafka.common.errors.GroupSubscribedToTopicException`.
586 fn is_group_subscribed_to_topic_error(&self) -> bool {
587 false
588 }
589
590 /// Whether this error's Java class is, or extends,
591 /// `org.apache.kafka.common.errors.IllegalGenerationException`.
592 fn is_illegal_generation_error(&self) -> bool {
593 false
594 }
595
596 /// Whether this error's Java class is, or extends,
597 /// `org.apache.kafka.common.errors.IllegalSaslStateException`.
598 fn is_illegal_sasl_state_error(&self) -> bool {
599 false
600 }
601
602 /// Whether this error's Java class is, or extends,
603 /// `org.apache.kafka.common.errors.InconsistentClusterIdException`.
604 fn is_inconsistent_cluster_id_error(&self) -> bool {
605 false
606 }
607
608 /// Whether this error's Java class is, or extends,
609 /// `org.apache.kafka.common.errors.InconsistentGroupProtocolException`.
610 fn is_inconsistent_group_protocol_error(&self) -> bool {
611 false
612 }
613
614 /// Whether this error's Java class is, or extends,
615 /// `org.apache.kafka.common.errors.InconsistentTopicIdException`.
616 fn is_inconsistent_topic_id_error(&self) -> bool {
617 false
618 }
619
620 /// Whether this error's Java class is, or extends,
621 /// `org.apache.kafka.common.errors.InconsistentVoterSetException`.
622 fn is_inconsistent_voter_set_error(&self) -> bool {
623 false
624 }
625
626 /// Whether this error's Java class is, or extends,
627 /// `org.apache.kafka.common.errors.IneligibleReplicaException`.
628 fn is_ineligible_replica_error(&self) -> bool {
629 false
630 }
631
632 /// Whether this error's Java class is, or extends,
633 /// `org.apache.kafka.common.errors.InterruptException`.
634 fn is_interrupt_error(&self) -> bool {
635 false
636 }
637
638 /// Whether this error's Java class is, or extends,
639 /// `org.apache.kafka.common.errors.InvalidCommitOffsetSizeException`.
640 fn is_invalid_commit_offset_size_error(&self) -> bool {
641 false
642 }
643
644 /// Whether this error's Java class is, or extends,
645 /// `org.apache.kafka.common.errors.InvalidFetchSessionEpochException`.
646 fn is_invalid_fetch_session_epoch_error(&self) -> bool {
647 false
648 }
649
650 /// Whether this error's Java class is, or extends,
651 /// `org.apache.kafka.common.errors.InvalidFetchSizeException`.
652 fn is_invalid_fetch_size_error(&self) -> bool {
653 false
654 }
655
656 /// Whether this error's Java class is, or extends,
657 /// `org.apache.kafka.common.errors.InvalidGroupIdException`.
658 fn is_invalid_group_id_error(&self) -> bool {
659 false
660 }
661
662 /// Whether this error's Java class is, or extends,
663 /// `org.apache.kafka.common.errors.InvalidPartitionsException`.
664 fn is_invalid_partitions_error(&self) -> bool {
665 false
666 }
667
668 /// Whether this error's Java class is, or extends,
669 /// `org.apache.kafka.common.errors.InvalidPidMappingException`.
670 fn is_invalid_pid_mapping_error(&self) -> bool {
671 false
672 }
673
674 /// Whether this error's Java class is, or extends,
675 /// `org.apache.kafka.common.errors.InvalidPrincipalTypeException`.
676 fn is_invalid_principal_type_error(&self) -> bool {
677 false
678 }
679
680 /// Whether this error's Java class is, or extends,
681 /// `org.apache.kafka.common.errors.InvalidProducerEpochException`.
682 fn is_invalid_producer_epoch_error(&self) -> bool {
683 false
684 }
685
686 /// Whether this error's Java class is, or extends,
687 /// `org.apache.kafka.common.InvalidRecordException`.
688 fn is_invalid_record_error(&self) -> bool {
689 false
690 }
691
692 /// Whether this error's Java class is, or extends,
693 /// `org.apache.kafka.common.errors.InvalidRecordStateException`.
694 fn is_invalid_record_state_error(&self) -> bool {
695 false
696 }
697
698 /// Whether this error's Java class is, or extends,
699 /// `org.apache.kafka.common.errors.InvalidRegistrationException`.
700 fn is_invalid_registration_error(&self) -> bool {
701 false
702 }
703
704 /// Whether this error's Java class is, or extends,
705 /// `org.apache.kafka.common.errors.InvalidRegularExpression`.
706 fn is_invalid_regular_expression_error(&self) -> bool {
707 false
708 }
709
710 /// Whether this error's Java class is, or extends,
711 /// `org.apache.kafka.common.errors.InvalidReplicaAssignmentException`.
712 fn is_invalid_replica_assignment_error(&self) -> bool {
713 false
714 }
715
716 /// Whether this error's Java class is, or extends,
717 /// `org.apache.kafka.common.errors.InvalidReplicationFactorException`.
718 fn is_invalid_replication_factor_error(&self) -> bool {
719 false
720 }
721
722 /// Whether this error's Java class is, or extends,
723 /// `org.apache.kafka.common.errors.InvalidRequestException`.
724 fn is_invalid_request_error(&self) -> bool {
725 false
726 }
727
728 /// Whether this error's Java class is, or extends,
729 /// `org.apache.kafka.common.errors.InvalidRequiredAcksException`.
730 fn is_invalid_required_acks_error(&self) -> bool {
731 false
732 }
733
734 /// Whether this error's Java class is, or extends,
735 /// `org.apache.kafka.common.errors.InvalidSessionTimeoutException`.
736 fn is_invalid_session_timeout_error(&self) -> bool {
737 false
738 }
739
740 /// Whether this error's Java class is, or extends,
741 /// `org.apache.kafka.common.errors.InvalidShareSessionEpochException`.
742 fn is_invalid_share_session_epoch_error(&self) -> bool {
743 false
744 }
745
746 /// Whether this error's Java class is, or extends,
747 /// `org.apache.kafka.common.errors.InvalidTimestampException`.
748 fn is_invalid_timestamp_error(&self) -> bool {
749 false
750 }
751
752 /// Whether this error's Java class is, or extends,
753 /// `org.apache.kafka.common.errors.InvalidTopicException`.
754 fn is_invalid_topic_error(&self) -> bool {
755 false
756 }
757
758 /// Whether this error's Java class is, or extends,
759 /// `org.apache.kafka.common.errors.InvalidTxnStateException`.
760 fn is_invalid_txn_state_error(&self) -> bool {
761 false
762 }
763
764 /// Whether this error's Java class is, or extends,
765 /// `org.apache.kafka.common.errors.InvalidTxnTimeoutException`.
766 fn is_invalid_txn_timeout_error(&self) -> bool {
767 false
768 }
769
770 /// Whether this error's Java class is, or extends,
771 /// `org.apache.kafka.common.errors.InvalidUpdateVersionException`.
772 fn is_invalid_update_version_error(&self) -> bool {
773 false
774 }
775
776 /// Whether this error's Java class is, or extends,
777 /// `org.apache.kafka.common.errors.InvalidVoterKeyException`.
778 fn is_invalid_voter_key_error(&self) -> bool {
779 false
780 }
781
782 /// Whether this error's Java class is, or extends,
783 /// `org.apache.kafka.common.errors.KafkaStorageException`.
784 fn is_kafka_storage_error(&self) -> bool {
785 false
786 }
787
788 /// Whether this error's Java class is, or extends,
789 /// `org.apache.kafka.common.errors.LeaderNotAvailableException`.
790 fn is_leader_not_available_error(&self) -> bool {
791 false
792 }
793
794 /// Whether this error's Java class is, or extends,
795 /// `org.apache.kafka.common.errors.ListenerNotFoundException`.
796 fn is_listener_not_found_error(&self) -> bool {
797 false
798 }
799
800 /// Whether this error's Java class is, or extends,
801 /// `org.apache.kafka.common.errors.LogDirNotFoundException`.
802 fn is_log_dir_not_found_error(&self) -> bool {
803 false
804 }
805
806 /// Whether this error's Java class is, or extends,
807 /// `org.apache.kafka.common.errors.MemberIdRequiredException`.
808 fn is_member_id_required_error(&self) -> bool {
809 false
810 }
811
812 /// Whether this error's Java class is, or extends,
813 /// `org.apache.kafka.common.errors.MismatchedEndpointTypeException`.
814 fn is_mismatched_endpoint_type_error(&self) -> bool {
815 false
816 }
817
818 /// Whether this error's Java class is, or extends,
819 /// `org.apache.kafka.common.errors.NetworkException`.
820 fn is_network_error(&self) -> bool {
821 false
822 }
823
824 /// Whether this error's Java class is, or extends,
825 /// `org.apache.kafka.common.errors.NewLeaderElectedException`.
826 fn is_new_leader_elected_error(&self) -> bool {
827 false
828 }
829
830 /// Whether this error's Java class is, or extends,
831 /// `org.apache.kafka.common.errors.NoReassignmentInProgressException`.
832 fn is_no_reassignment_in_progress_error(&self) -> bool {
833 false
834 }
835
836 /// Whether this error's Java class is, or extends,
837 /// `org.apache.kafka.common.errors.NotControllerException`.
838 fn is_not_controller_error(&self) -> bool {
839 false
840 }
841
842 /// Whether this error's Java class is, or extends,
843 /// `org.apache.kafka.common.errors.NotCoordinatorException`.
844 fn is_not_coordinator_error(&self) -> bool {
845 false
846 }
847
848 /// Whether this error's Java class is, or extends,
849 /// `org.apache.kafka.common.errors.NotEnoughReplicasException`.
850 fn is_not_enough_replicas_error(&self) -> bool {
851 false
852 }
853
854 /// Whether this error's Java class is, or extends,
855 /// `org.apache.kafka.common.errors.NotEnoughReplicasAfterAppendException`.
856 fn is_not_enough_replicas_after_append_error(&self) -> bool {
857 false
858 }
859
860 /// Whether this error's Java class is, or extends,
861 /// `org.apache.kafka.common.errors.NotLeaderOrFollowerException`.
862 fn is_not_leader_or_follower_error(&self) -> bool {
863 false
864 }
865
866 /// Whether this error's Java class is, or extends,
867 /// `org.apache.kafka.common.errors.OffsetMetadataTooLarge`.
868 fn is_offset_metadata_too_large_error(&self) -> bool {
869 false
870 }
871
872 /// Whether this error's Java class is, or extends,
873 /// `org.apache.kafka.common.errors.OffsetMovedToTieredStorageException`.
874 fn is_offset_moved_to_tiered_storage_error(&self) -> bool {
875 false
876 }
877
878 /// Whether this error's Java class is, or extends,
879 /// `org.apache.kafka.common.errors.OffsetNotAvailableException`.
880 fn is_offset_not_available_error(&self) -> bool {
881 false
882 }
883
884 /// Whether this error's Java class is, or extends,
885 /// `org.apache.kafka.common.errors.OffsetOutOfRangeException`.
886 fn is_offset_out_of_range_error(&self) -> bool {
887 false
888 }
889
890 /// Whether this error's Java class is, or extends,
891 /// `org.apache.kafka.common.errors.OperationNotAttemptedException`.
892 fn is_operation_not_attempted_error(&self) -> bool {
893 false
894 }
895
896 /// Whether this error's Java class is, or extends,
897 /// `org.apache.kafka.common.errors.PolicyViolationException`.
898 fn is_policy_violation_error(&self) -> bool {
899 false
900 }
901
902 /// Whether this error's Java class is, or extends,
903 /// `org.apache.kafka.common.errors.PositionOutOfRangeException`.
904 fn is_position_out_of_range_error(&self) -> bool {
905 false
906 }
907
908 /// Whether this error's Java class is, or extends,
909 /// `org.apache.kafka.common.errors.PreferredLeaderNotAvailableException`.
910 fn is_preferred_leader_not_available_error(&self) -> bool {
911 false
912 }
913
914 /// Whether this error's Java class is, or extends,
915 /// `org.apache.kafka.common.errors.PrincipalDeserializationException`.
916 fn is_principal_deserialization_error(&self) -> bool {
917 false
918 }
919
920 /// Whether this error's Java class is, or extends,
921 /// `org.apache.kafka.common.errors.ProducerFencedException`.
922 fn is_producer_fenced_error(&self) -> bool {
923 false
924 }
925
926 /// Whether this error's Java class is, or extends,
927 /// `org.apache.kafka.common.metrics.QuotaViolationException`.
928 fn is_quota_violation_error(&self) -> bool {
929 false
930 }
931
932 /// Whether this error's Java class is, or extends,
933 /// `org.apache.kafka.common.errors.ReassignmentInProgressException`.
934 fn is_reassignment_in_progress_error(&self) -> bool {
935 false
936 }
937
938 /// Whether this error's Java class is, or extends,
939 /// `org.apache.kafka.common.errors.RebalanceInProgressException`.
940 fn is_rebalance_in_progress_error(&self) -> bool {
941 false
942 }
943
944 /// Whether this error's Java class is, or extends,
945 /// `org.apache.kafka.common.errors.RebootstrapRequiredException`.
946 fn is_rebootstrap_required_error(&self) -> bool {
947 false
948 }
949
950 /// Whether this error's Java class is, or extends,
951 /// `org.apache.kafka.common.errors.RecordBatchTooLargeException`.
952 fn is_record_batch_too_large_error(&self) -> bool {
953 false
954 }
955
956 /// Whether this error's Java class is, or extends,
957 /// `org.apache.kafka.common.errors.RecordDeserializationException`.
958 fn is_record_deserialization_error(&self) -> bool {
959 false
960 }
961
962 /// Whether this error's Java class is, or extends,
963 /// `org.apache.kafka.common.errors.RecordTooLargeException`.
964 fn is_record_too_large_error(&self) -> bool {
965 false
966 }
967
968 /// Whether this error's Java class is, or extends,
969 /// `org.apache.kafka.common.network.InvalidReceiveException`.
970 fn is_invalid_receive_error(&self) -> bool {
971 false
972 }
973
974 /// Whether this error's Java class is, or extends,
975 /// `org.apache.kafka.common.config.ConfigException`.
976 fn is_config_error(&self) -> bool {
977 false
978 }
979
980 /// Whether this error's Java class is, or extends,
981 /// `org.apache.kafka.clients.consumer.RetriableCommitFailedException`.
982 fn is_consumer_retriable_commit_failed_error(&self) -> bool {
983 false
984 }
985
986 /// Whether this error's Java class is, or extends,
987 /// `org.apache.kafka.clients.consumer.CommitFailedException`.
988 fn is_consumer_commit_failed_error(&self) -> bool {
989 false
990 }
991
992 /// Whether this error's Java class is, or extends,
993 /// `org.apache.kafka.clients.consumer.NoOffsetForPartitionException`.
994 fn is_consumer_no_offset_for_partition_error(&self) -> bool {
995 false
996 }
997
998 /// Whether this error's Java class is, or extends,
999 /// `org.apache.kafka.clients.consumer.LogTruncationException`.
1000 fn is_consumer_log_truncation_error(&self) -> bool {
1001 false
1002 }
1003
1004 /// Whether this error's Java class is, or extends,
1005 /// `org.apache.kafka.common.errors.ReplicaNotAvailableException`.
1006 fn is_replica_not_available_error(&self) -> bool {
1007 false
1008 }
1009
1010 /// Whether this error's Java class is, or extends,
1011 /// `org.apache.kafka.common.errors.ResourceNotFoundException`.
1012 fn is_resource_not_found_error(&self) -> bool {
1013 false
1014 }
1015
1016 /// Whether this error's Java class is, or extends,
1017 /// `org.apache.kafka.common.errors.SaslAuthenticationException`.
1018 fn is_sasl_authentication_error(&self) -> bool {
1019 false
1020 }
1021
1022 /// Whether this error's Java class is, or extends,
1023 /// `org.apache.kafka.common.protocol.types.SchemaException`.
1024 fn is_schema_error(&self) -> bool {
1025 false
1026 }
1027
1028 /// Whether this error's Java class is, or extends,
1029 /// `org.apache.kafka.common.errors.SecurityDisabledException`.
1030 fn is_security_disabled_error(&self) -> bool {
1031 false
1032 }
1033
1034 /// Whether this error's Java class is, or extends,
1035 /// `org.apache.kafka.common.errors.ShareSessionLimitReachedException`.
1036 fn is_share_session_limit_reached_error(&self) -> bool {
1037 false
1038 }
1039
1040 /// Whether this error's Java class is, or extends,
1041 /// `org.apache.kafka.common.errors.ShareSessionNotFoundException`.
1042 fn is_share_session_not_found_error(&self) -> bool {
1043 false
1044 }
1045
1046 /// Whether this error's Java class is, or extends,
1047 /// `org.apache.kafka.common.errors.SnapshotNotFoundException`.
1048 fn is_snapshot_not_found_error(&self) -> bool {
1049 false
1050 }
1051
1052 /// Whether this error's Java class is, or extends,
1053 /// `org.apache.kafka.common.errors.SslAuthenticationException`.
1054 fn is_ssl_authentication_error(&self) -> bool {
1055 false
1056 }
1057
1058 /// Whether this error's Java class is, or extends,
1059 /// `org.apache.kafka.common.errors.StaleBrokerEpochException`.
1060 fn is_stale_broker_epoch_error(&self) -> bool {
1061 false
1062 }
1063
1064 /// Whether this error's Java class is, or extends,
1065 /// `org.apache.kafka.common.errors.StaleMemberEpochException`.
1066 fn is_stale_member_epoch_error(&self) -> bool {
1067 false
1068 }
1069
1070 /// Whether this error's Java class is, or extends,
1071 /// `org.apache.kafka.common.errors.StreamsInvalidTopologyException`.
1072 fn is_streams_invalid_topology_error(&self) -> bool {
1073 false
1074 }
1075
1076 /// Whether this error's Java class is, or extends,
1077 /// `org.apache.kafka.common.errors.StreamsInvalidTopologyEpochException`.
1078 fn is_streams_invalid_topology_epoch_error(&self) -> bool {
1079 false
1080 }
1081
1082 /// Whether this error's Java class is, or extends,
1083 /// `org.apache.kafka.common.errors.StreamsTopologyDescriptionUpdateFailedException`.
1084 fn is_streams_topology_description_update_failed_error(&self) -> bool {
1085 false
1086 }
1087
1088 /// Whether this error's Java class is, or extends,
1089 /// `org.apache.kafka.common.errors.StreamsTopologyFencedException`.
1090 fn is_streams_topology_fenced_error(&self) -> bool {
1091 false
1092 }
1093
1094 /// Whether this error's Java class is, or extends,
1095 /// `org.apache.kafka.common.errors.TelemetryTooLargeException`.
1096 fn is_telemetry_too_large_error(&self) -> bool {
1097 false
1098 }
1099
1100 /// Whether this error's Java class is, or extends,
1101 /// `org.apache.kafka.common.errors.ThrottlingQuotaExceededException`.
1102 fn is_throttling_quota_exceeded_error(&self) -> bool {
1103 false
1104 }
1105
1106 /// Whether this error's Java class is, or extends,
1107 /// `org.apache.kafka.common.errors.TopicAuthorizationException`.
1108 fn is_topic_authorization_error(&self) -> bool {
1109 false
1110 }
1111
1112 /// Whether this error's Java class is, or extends,
1113 /// `org.apache.kafka.common.errors.TopicDeletionDisabledException`.
1114 fn is_topic_deletion_disabled_error(&self) -> bool {
1115 false
1116 }
1117
1118 /// Whether this error's Java class is, or extends,
1119 /// `org.apache.kafka.common.errors.TopicExistsException`.
1120 fn is_topic_exists_error(&self) -> bool {
1121 false
1122 }
1123
1124 /// Whether this error's Java class is, or extends,
1125 /// `org.apache.kafka.common.errors.TransactionAbortableException`.
1126 fn is_transaction_abortable_error(&self) -> bool {
1127 false
1128 }
1129
1130 /// Whether this error's Java class is, or extends,
1131 /// `org.apache.kafka.common.errors.TransactionAbortedException`.
1132 fn is_transaction_aborted_error(&self) -> bool {
1133 false
1134 }
1135
1136 /// Whether this error's Java class is, or extends,
1137 /// `org.apache.kafka.common.errors.TransactionCoordinatorFencedException`.
1138 fn is_transaction_coordinator_fenced_error(&self) -> bool {
1139 false
1140 }
1141
1142 /// Whether this error's Java class is, or extends,
1143 /// `org.apache.kafka.common.errors.TransactionalIdAuthorizationException`.
1144 fn is_transactional_id_authorization_error(&self) -> bool {
1145 false
1146 }
1147
1148 /// Whether this error's Java class is, or extends,
1149 /// `org.apache.kafka.common.errors.TransactionalIdNotFoundException`.
1150 fn is_transactional_id_not_found_error(&self) -> bool {
1151 false
1152 }
1153
1154 /// Whether this error's Java class is, or extends,
1155 /// `org.apache.kafka.common.errors.UnacceptableCredentialException`.
1156 fn is_unacceptable_credential_error(&self) -> bool {
1157 false
1158 }
1159
1160 /// Whether this error's Java class is, or extends,
1161 /// `org.apache.kafka.common.errors.UnknownControllerIdException`.
1162 fn is_unknown_controller_id_error(&self) -> bool {
1163 false
1164 }
1165
1166 /// Whether this error's Java class is, or extends,
1167 /// `org.apache.kafka.common.errors.UnknownLeaderEpochException`.
1168 fn is_unknown_leader_epoch_error(&self) -> bool {
1169 false
1170 }
1171
1172 /// Whether this error's Java class is, or extends,
1173 /// `org.apache.kafka.common.errors.UnknownMemberIdException`.
1174 fn is_unknown_member_id_error(&self) -> bool {
1175 false
1176 }
1177
1178 /// Whether this error's Java class is, or extends,
1179 /// `org.apache.kafka.common.errors.UnknownProducerIdException`.
1180 fn is_unknown_producer_id_error(&self) -> bool {
1181 false
1182 }
1183
1184 /// Whether this error's Java class is, or extends,
1185 /// `org.apache.kafka.common.errors.UnknownServerException`.
1186 fn is_unknown_server_error(&self) -> bool {
1187 false
1188 }
1189
1190 /// Whether this error's Java class is, or extends,
1191 /// `org.apache.kafka.common.errors.UnknownSubscriptionIdException`.
1192 fn is_unknown_subscription_id_error(&self) -> bool {
1193 false
1194 }
1195
1196 /// Whether this error's Java class is, or extends,
1197 /// `org.apache.kafka.common.errors.UnknownTopicIdException`.
1198 fn is_unknown_topic_id_error(&self) -> bool {
1199 false
1200 }
1201
1202 /// Whether this error's Java class is, or extends,
1203 /// `org.apache.kafka.common.errors.UnknownTopicOrPartitionException`.
1204 fn is_unknown_topic_or_partition_error(&self) -> bool {
1205 false
1206 }
1207
1208 /// Whether this error's Java class is, or extends,
1209 /// `org.apache.kafka.common.errors.UnreleasedInstanceIdException`.
1210 fn is_unreleased_instance_id_error(&self) -> bool {
1211 false
1212 }
1213
1214 /// Whether this error's Java class is, or extends,
1215 /// `org.apache.kafka.common.errors.UnstableOffsetCommitException`.
1216 fn is_unstable_offset_commit_error(&self) -> bool {
1217 false
1218 }
1219
1220 /// Whether this error's Java class is, or extends,
1221 /// `org.apache.kafka.common.errors.UnsupportedAssignorException`.
1222 fn is_unsupported_assignor_error(&self) -> bool {
1223 false
1224 }
1225
1226 /// Whether this error's Java class is, or extends,
1227 /// `org.apache.kafka.common.errors.UnsupportedByAuthenticationException`.
1228 fn is_unsupported_by_authentication_error(&self) -> bool {
1229 false
1230 }
1231
1232 /// Whether this error's Java class is, or extends,
1233 /// `org.apache.kafka.common.errors.UnsupportedCompressionTypeException`.
1234 fn is_unsupported_compression_type_error(&self) -> bool {
1235 false
1236 }
1237
1238 /// Whether this error's Java class is, or extends,
1239 /// `org.apache.kafka.common.errors.UnsupportedEndpointTypeException`.
1240 fn is_unsupported_endpoint_type_error(&self) -> bool {
1241 false
1242 }
1243
1244 /// Whether this error's Java class is, or extends,
1245 /// `org.apache.kafka.common.errors.UnsupportedForMessageFormatException`.
1246 fn is_unsupported_for_message_format_error(&self) -> bool {
1247 false
1248 }
1249
1250 /// Whether this error's Java class is, or extends,
1251 /// `org.apache.kafka.common.errors.UnsupportedSaslMechanismException`.
1252 fn is_unsupported_sasl_mechanism_error(&self) -> bool {
1253 false
1254 }
1255
1256 /// Whether this error's Java class is, or extends,
1257 /// `org.apache.kafka.common.errors.UnsupportedVersionException`.
1258 ///
1259 /// Kafka 4.4's `common.internals.UnsupportedProtocolFieldException` extends
1260 /// it (as the `NoBatchedFindCoordinatorsException` /
1261 /// `NoBatchedOffsetFetchRequestException` nested in the request classes
1262 /// already did). None of those subclasses is public, so they share the one
1263 /// [`UnsupportedVersionError`] payload and only it answers `true`.
1264 fn is_unsupported_version_error(&self) -> bool {
1265 false
1266 }
1267
1268 /// Whether this error's Java class is, or extends,
1269 /// `org.apache.kafka.common.errors.VoterNotFoundException`.
1270 fn is_voter_not_found_error(&self) -> bool {
1271 false
1272 }
1273
1274 /// Whether this error's Java class is, or extends,
1275 /// `org.apache.kafka.common.errors.WakeupException`.
1276 fn is_wakeup_error(&self) -> bool {
1277 false
1278 }
1279}
1280
1281/// The protocol error code an error corresponds to.
1282///
1283/// **Mechanism, not API**, like [`ErrorHierarchy`]. Java's exceptions do not
1284/// store their code; `Errors` keeps a `CLASS_TO_ERROR` map and
1285/// `Errors.forException(t)` looks the class up in it
1286/// (`org.apache.kafka.common.protocol.Errors#forException`). This trait is that map inverted into a
1287/// per-type answer, which is the only form the compiler can check.
1288///
1289/// The default is [`Errors::UnknownServerError`], matching what
1290/// [`Error::error`] has always returned for payloads that carry no protocol
1291/// code — the generic `java.lang` errors and the client-side-only
1292/// `KafkaException` subclasses.
1293#[delegatable_trait]
1294pub(crate) trait ErrorCode {
1295 /// The protocol error code for this error's Java class.
1296 fn error(&self) -> Errors {
1297 Errors::UnknownServerError
1298 }
1299}
1300
1301/// The name of the error's own class, translating Java's
1302/// `getClass().getName()`.
1303///
1304/// **Mechanism, not API**, like [`ErrorMessage`]: it exists so
1305/// [`Errors::error_name`] can answer without matching on 138 codes a second
1306/// time. Callers use [`Errors::error_name`], which translates
1307/// `org.apache.kafka.common.protocol.Errors#exceptionName`.
1308///
1309/// Java returns the *fully qualified* class name
1310/// (`"org.apache.kafka.common.errors.UnknownServerException"`). Rust has no Java
1311/// package to report, so this returns the bare type name
1312/// (`"UnknownServerError"`) — the same string [`std::fmt::Display`] prefixes, which
1313/// is the translation of `Throwable.toString()`'s `getClass().getName()` and so
1314/// keeps the two consistent.
1315///
1316/// The method is **required**, with no default, for the same reason
1317/// [`ErrorMessage::message`] is: a wrong-but-plausible default would let a new
1318/// payload silently report the wrong class instead of failing to compile.
1319#[delegatable_trait]
1320pub(crate) trait ErrorName {
1321 /// The error's own type name, without a module path.
1322 fn name(&self) -> &'static str;
1323}
1324
1325/// Declares one Java exception class from `org.apache.kafka.common.errors`.
1326///
1327/// Generates the struct (message only), its `Display` (`"<TypeName>: <message>"`,
1328/// mirroring Java's `Throwable.toString()`), and the [`ErrorMessage`],
1329/// [`ErrorCode`] and [`ErrorHierarchy`] impls.
1330///
1331/// The `extends:` list is the class's Java `extends` chain, written as the
1332/// predicates it makes true. Everything omitted inherits the trait's `false`, so
1333/// the list is the whole statement of the type's ancestry and can be diffed
1334/// against the Java file directly:
1335///
1336/// ```text
1337/// NetworkException extends InvalidMetadataException extends RefreshRetriableException
1338/// extends RetriableException extends ApiException extends KafkaException
1339/// => extends: [is_kafka_error, is_api_error, is_retriable_error,
1340/// is_refresh_retriable_error, is_invalid_metadata_error]
1341/// ```
1342///
1343/// An optional `kind: <Type>,` (after `code:`) adds a crate-private field of that
1344/// type, starting at its `Default`, read with `kind()` and set with `with_kind()`.
1345/// It lets one public variant stand for a Java class *and* crate-private
1346/// subclasses of it that the public `Error` surface does not name — the case of
1347/// `UnsupportedVersionException` and `common.internals.UnsupportedProtocolFieldException`.
1348macro_rules! kafka_error_type {
1349 // No `code:` — the class has no entry in `Errors.java`, and walking its
1350 // superclasses (Java's `Errors.forException`) finds none either, so
1351 // `ErrorCode` takes its default of `Errors::UnknownServerError`.
1352 (
1353 $(#[$meta:meta])*
1354 $name:ident,
1355 extends: [$($predicate:ident),* $(,)?] $(,)?
1356 ) => {
1357 kafka_error_type! {
1358 $(#[$meta])*
1359 $name,
1360 code: $crate::common::protocol::Errors::UnknownServerError,
1361 extends: [$($predicate),*],
1362 }
1363 };
1364 (
1365 $(#[$meta:meta])*
1366 $name:ident,
1367 code: $code:expr,
1368 $(kind: $kind:ty,)?
1369 extends: [$($predicate:ident),* $(,)?] $(,)?
1370 ) => {
1371 $(#[$meta])*
1372 #[derive(Clone, Debug)]
1373 pub struct $name {
1374 message: String,
1375 /// The underlying cause, translating Java's `Throwable` `cause`.
1376 source: Option<Box<$crate::common::Error>>,
1377 $(
1378 /// Which crate-private Java subclass, if any, this value stands for.
1379 kind: $kind,
1380 )?
1381 }
1382
1383 $(
1384 impl $name {
1385 /// Which crate-private Java subclass, if any, this value stands for.
1386 pub(crate) fn kind(&self) -> $kind {
1387 self.kind
1388 }
1389
1390 /// Returns this error marked as the given crate-private subclass.
1391 pub(crate) fn with_kind(mut self, kind: $kind) -> Self {
1392 self.kind = kind;
1393 self
1394 }
1395 }
1396 )?
1397
1398 impl $name {
1399 /// Create the error with the given message and no cause,
1400 /// mirroring Java's `(String message)` constructor.
1401 ///
1402 /// This keeps the plain name under CLAUDE.md §2: the dominant Java
1403 /// shape among the classes this macro declares is
1404 /// `(String message)` + `(String message, Throwable cause)`, whose
1405 /// parameter-name intersection is `{message}` — matched exactly by
1406 /// `(String message)`.
1407 pub fn new(message: impl Into<String>) -> Self {
1408 Self {
1409 message: message.into(),
1410 source: None,
1411 $(kind: <$kind as ::core::default::Default>::default(),)?
1412 }
1413 }
1414
1415 /// Create the error with the given message and an underlying cause,
1416 /// mirroring Java's `(String message, Throwable cause)` constructor.
1417 ///
1418 /// Suffixed with the one parameter beyond the `{message}`
1419 /// intersection (CLAUDE.md §2) — see [`new`](Self::new).
1420 pub fn with_source(message: impl Into<String>, source: $crate::common::Error) -> Self {
1421 Self {
1422 message: message.into(),
1423 source: Some(Box::new(source)),
1424 $(kind: <$kind as ::core::default::Default>::default(),)?
1425 }
1426 }
1427
1428 /// Create the error with the default message for its error code,
1429 /// mirroring Java's `Errors.exception()`.
1430 ///
1431 /// Not a constructor overload, so CLAUDE.md §2's suffixing does not
1432 /// apply: it translates the `Errors` static factory, which fills in
1433 /// `Errors.message()` and has no Java constructor counterpart.
1434 pub fn with_default_message() -> Self {
1435 Self::new($code.message())
1436 }
1437
1438 /// The error message.
1439 pub fn message(&self) -> &str {
1440 &self.message
1441 }
1442
1443 /// The underlying cause, if any. Mirrors Java's `getCause()`.
1444 pub fn source(&self) -> Option<&$crate::common::Error> {
1445 self.source.as_deref()
1446 }
1447 }
1448
1449 impl $crate::common::error::ErrorSource for $name {
1450 fn source(&self) -> Option<&$crate::common::Error> {
1451 self.source.as_deref()
1452 }
1453 }
1454
1455 // The inherent `source()` above shadows both this and
1456 // `ErrorSource::source` for method-call syntax, so `e.source()` yields the
1457 // typed `Option<&Error>` while `StdError::source(&e)` gives the `dyn` view.
1458 impl ::std::error::Error for $name {
1459 fn source(&self) -> Option<&(dyn ::std::error::Error + 'static)> {
1460 self.source
1461 .as_deref()
1462 .map(|e| e as &(dyn ::std::error::Error + 'static))
1463 }
1464 }
1465
1466 impl ::std::fmt::Display for $name {
1467 fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result {
1468 write!(f, "{}: {}", stringify!($name), self.message)
1469 }
1470 }
1471
1472 impl $crate::common::error::ErrorMessage for $name {
1473 fn message(&self) -> &str {
1474 &self.message
1475 }
1476 }
1477
1478 impl $crate::common::error::ErrorName for $name {
1479 fn name(&self) -> &'static str {
1480 stringify!($name)
1481 }
1482 }
1483
1484 impl $crate::common::error::ErrorCode for $name {
1485 fn error(&self) -> $crate::common::protocol::Errors {
1486 $code
1487 }
1488 }
1489
1490 impl $crate::common::error::ErrorHierarchy for $name {
1491 $(
1492 fn $predicate(&self) -> bool {
1493 true
1494 }
1495 )*
1496 }
1497 };
1498}
1499
1500pub(crate) use kafka_error_type;
1501
1502/// The message an error carries, translating Java's `Throwable.getMessage()`.
1503///
1504/// **Mechanism, not API**, like [`ErrorHierarchy`]: it exists so [`Error`] can
1505/// delegate [`Error::message`] to the variant's payload instead of matching.
1506/// Callers use [`Error::message`].
1507///
1508/// Distinct from [`std::fmt::Display`], which translates `Throwable.toString()` —
1509/// Java renders that as `getClass().getName() + ": " + getLocalizedMessage()`,
1510/// so `Display` prefixes the class name and may append subclass state (the
1511/// unauthorized topics, say) while this returns the bare message. Both are
1512/// pinned by tests; do not collapse them.
1513///
1514/// The method is **required**, with no default. There is no `&str` equivalent
1515/// of the predicates' `false`, and defaulting to `""` would reintroduce exactly
1516/// what this replaces: a new payload silently getting an empty message instead
1517/// of a compile error.
1518#[delegatable_trait]
1519pub(crate) trait ErrorMessage {
1520 /// The error message, without the class-name prefix `Display` adds.
1521 fn message(&self) -> &str;
1522}
1523
1524/// The error that caused this one, translating Java's `Throwable.getCause()`.
1525///
1526/// **Mechanism, not API**, like [`ErrorMessage`]: it exists so [`Error`] can
1527/// delegate [`Error::source`] to the variant's payload instead of matching.
1528/// Callers use [`Error::source`], or [`std::error::Error::source`] for the
1529/// standard-library view.
1530///
1531/// `getCause()` is declared on `java.lang.Throwable`, so **every** exception has
1532/// a cause slot — not just `KafkaException`. Accordingly every error class in
1533/// this crate carries one, and every one answers here. Whether a class lets a
1534/// caller *set* it follows Java: 92 of the 150 `common.errors` classes expose a
1535/// `Throwable cause` constructor, and the rest inherit an always-null cause.
1536///
1537/// The method defaults to `None` — unlike [`ErrorMessage::message`], `None` is a
1538/// legitimate answer (Java's default cause is null), so a payload that genuinely
1539/// has no cause slot is not forced to state one.
1540#[delegatable_trait]
1541pub(crate) trait ErrorSource {
1542 /// The underlying cause, if any. Mirrors Java's `Throwable.getCause()`.
1543 ///
1544 /// The bare `Error` (not `crate::common::Error`) is deliberate:
1545 /// `#[delegatable_trait]` copies this signature verbatim into the generated
1546 /// `ambassador_impl_ErrorSource` macro, and a `crate::` path inside a macro
1547 /// definition resolves against the *expansion* site
1548 /// (clippy::crate_in_macro_def). So every module that delegates this trait
1549 /// imports `Error`, exactly as the modules delegating [`ErrorCode`] import
1550 /// `Errors`.
1551 fn source(&self) -> Option<&Error> {
1552 None
1553 }
1554}
1555
1556// ---------------------------------------------------------------------------
1557// Boxed payloads
1558// ---------------------------------------------------------------------------
1559//
1560// NOTE: every predicate must be forwarded here. A trait method added without
1561// a matching line below silently falls back to the default (`false`) for any
1562// boxed payload — `ConsumerLogTruncation` regressed exactly that way.
1563//
1564// A variant may box its payload to keep `Error` small (see
1565// [`Error::ConsumerLogTruncation`]). Ambassador forwards to the payload by value-typed
1566// method call, so the box itself has to implement the traits — deref coercion
1567// does not satisfy a trait bound.
1568
1569impl<T: ErrorSource + ?Sized> ErrorSource for Box<T> {
1570 fn source(&self) -> Option<&Error> {
1571 (**self).source()
1572 }
1573}
1574
1575impl<T: ErrorHierarchy + ?Sized> ErrorHierarchy for Box<T> {
1576 fn is_kafka_error(&self) -> bool {
1577 (**self).is_kafka_error()
1578 }
1579 fn is_api_error(&self) -> bool {
1580 (**self).is_api_error()
1581 }
1582 fn is_retriable_error(&self) -> bool {
1583 (**self).is_retriable_error()
1584 }
1585 fn is_refresh_retriable_error(&self) -> bool {
1586 (**self).is_refresh_retriable_error()
1587 }
1588 fn is_timeout_error(&self) -> bool {
1589 (**self).is_timeout_error()
1590 }
1591 fn is_invalid_metadata_error(&self) -> bool {
1592 (**self).is_invalid_metadata_error()
1593 }
1594 fn is_invalid_configuration_error(&self) -> bool {
1595 (**self).is_invalid_configuration_error()
1596 }
1597 fn is_application_recoverable_error(&self) -> bool {
1598 (**self).is_application_recoverable_error()
1599 }
1600 fn is_invalid_offset_error(&self) -> bool {
1601 (**self).is_invalid_offset_error()
1602 }
1603 fn is_consumer_invalid_offset_error(&self) -> bool {
1604 (**self).is_consumer_invalid_offset_error()
1605 }
1606 fn is_consumer_offset_out_of_range_error(&self) -> bool {
1607 (**self).is_consumer_offset_out_of_range_error()
1608 }
1609 fn is_out_of_order_sequence_error(&self) -> bool {
1610 (**self).is_out_of_order_sequence_error()
1611 }
1612 fn is_serialization_error(&self) -> bool {
1613 (**self).is_serialization_error()
1614 }
1615 fn is_authentication_error(&self) -> bool {
1616 (**self).is_authentication_error()
1617 }
1618 fn is_authorization_error(&self) -> bool {
1619 (**self).is_authorization_error()
1620 }
1621 fn is_local_illegal_argument_error(&self) -> bool {
1622 (**self).is_local_illegal_argument_error()
1623 }
1624 fn is_local_illegal_state_error(&self) -> bool {
1625 (**self).is_local_illegal_state_error()
1626 }
1627 fn is_local_concurrent_modification_error(&self) -> bool {
1628 (**self).is_local_concurrent_modification_error()
1629 }
1630 fn is_local_timeout_error(&self) -> bool {
1631 (**self).is_local_timeout_error()
1632 }
1633 fn is_local_unsupported_operation_error(&self) -> bool {
1634 (**self).is_local_unsupported_operation_error()
1635 }
1636 fn is_local_null_pointer_error(&self) -> bool {
1637 (**self).is_local_null_pointer_error()
1638 }
1639 fn is_local_callback_error(&self) -> bool {
1640 (**self).is_local_callback_error()
1641 }
1642 fn is_authorizer_not_ready_error(&self) -> bool {
1643 (**self).is_authorizer_not_ready_error()
1644 }
1645 fn is_bootstrap_resolution_error(&self) -> bool {
1646 (**self).is_bootstrap_resolution_error()
1647 }
1648 fn is_broker_id_not_registered_error(&self) -> bool {
1649 (**self).is_broker_id_not_registered_error()
1650 }
1651 fn is_broker_not_available_error(&self) -> bool {
1652 (**self).is_broker_not_available_error()
1653 }
1654 fn is_producer_buffer_exhausted_error(&self) -> bool {
1655 (**self).is_producer_buffer_exhausted_error()
1656 }
1657 fn is_cluster_authorization_error(&self) -> bool {
1658 (**self).is_cluster_authorization_error()
1659 }
1660 fn is_concurrent_transactions_error(&self) -> bool {
1661 (**self).is_concurrent_transactions_error()
1662 }
1663 fn is_controller_id_not_registered_error(&self) -> bool {
1664 (**self).is_controller_id_not_registered_error()
1665 }
1666 fn is_controller_moved_error(&self) -> bool {
1667 (**self).is_controller_moved_error()
1668 }
1669 fn is_coordinator_load_in_progress_error(&self) -> bool {
1670 (**self).is_coordinator_load_in_progress_error()
1671 }
1672 fn is_coordinator_not_available_error(&self) -> bool {
1673 (**self).is_coordinator_not_available_error()
1674 }
1675 fn is_correlation_id_mismatch_error(&self) -> bool {
1676 (**self).is_correlation_id_mismatch_error()
1677 }
1678 fn is_corrupt_record_error(&self) -> bool {
1679 (**self).is_corrupt_record_error()
1680 }
1681 fn is_delegation_token_authorization_error(&self) -> bool {
1682 (**self).is_delegation_token_authorization_error()
1683 }
1684 fn is_delegation_token_disabled_error(&self) -> bool {
1685 (**self).is_delegation_token_disabled_error()
1686 }
1687 fn is_delegation_token_expired_error(&self) -> bool {
1688 (**self).is_delegation_token_expired_error()
1689 }
1690 fn is_delegation_token_not_found_error(&self) -> bool {
1691 (**self).is_delegation_token_not_found_error()
1692 }
1693 fn is_delegation_token_owner_mismatch_error(&self) -> bool {
1694 (**self).is_delegation_token_owner_mismatch_error()
1695 }
1696 fn is_disconnect_error(&self) -> bool {
1697 (**self).is_disconnect_error()
1698 }
1699 fn is_duplicate_broker_registration_error(&self) -> bool {
1700 (**self).is_duplicate_broker_registration_error()
1701 }
1702 fn is_duplicate_resource_error(&self) -> bool {
1703 (**self).is_duplicate_resource_error()
1704 }
1705 fn is_duplicate_sequence_error(&self) -> bool {
1706 (**self).is_duplicate_sequence_error()
1707 }
1708 fn is_duplicate_voter_error(&self) -> bool {
1709 (**self).is_duplicate_voter_error()
1710 }
1711 fn is_election_not_needed_error(&self) -> bool {
1712 (**self).is_election_not_needed_error()
1713 }
1714 fn is_eligible_leaders_not_available_error(&self) -> bool {
1715 (**self).is_eligible_leaders_not_available_error()
1716 }
1717 fn is_feature_update_failed_error(&self) -> bool {
1718 (**self).is_feature_update_failed_error()
1719 }
1720 fn is_fenced_instance_id_error(&self) -> bool {
1721 (**self).is_fenced_instance_id_error()
1722 }
1723 fn is_fenced_leader_epoch_error(&self) -> bool {
1724 (**self).is_fenced_leader_epoch_error()
1725 }
1726 fn is_fenced_member_epoch_error(&self) -> bool {
1727 (**self).is_fenced_member_epoch_error()
1728 }
1729 fn is_fenced_state_epoch_error(&self) -> bool {
1730 (**self).is_fenced_state_epoch_error()
1731 }
1732 fn is_fetch_session_id_not_found_error(&self) -> bool {
1733 (**self).is_fetch_session_id_not_found_error()
1734 }
1735 fn is_fetch_session_topic_id_error(&self) -> bool {
1736 (**self).is_fetch_session_topic_id_error()
1737 }
1738 fn is_group_authorization_error(&self) -> bool {
1739 (**self).is_group_authorization_error()
1740 }
1741 fn is_group_deletion_failed_error(&self) -> bool {
1742 (**self).is_group_deletion_failed_error()
1743 }
1744 fn is_group_id_not_found_error(&self) -> bool {
1745 (**self).is_group_id_not_found_error()
1746 }
1747 fn is_group_max_size_reached_error(&self) -> bool {
1748 (**self).is_group_max_size_reached_error()
1749 }
1750 fn is_group_not_empty_error(&self) -> bool {
1751 (**self).is_group_not_empty_error()
1752 }
1753 fn is_group_subscribed_to_topic_error(&self) -> bool {
1754 (**self).is_group_subscribed_to_topic_error()
1755 }
1756 fn is_illegal_generation_error(&self) -> bool {
1757 (**self).is_illegal_generation_error()
1758 }
1759 fn is_illegal_sasl_state_error(&self) -> bool {
1760 (**self).is_illegal_sasl_state_error()
1761 }
1762 fn is_inconsistent_cluster_id_error(&self) -> bool {
1763 (**self).is_inconsistent_cluster_id_error()
1764 }
1765 fn is_inconsistent_group_protocol_error(&self) -> bool {
1766 (**self).is_inconsistent_group_protocol_error()
1767 }
1768 fn is_inconsistent_topic_id_error(&self) -> bool {
1769 (**self).is_inconsistent_topic_id_error()
1770 }
1771 fn is_inconsistent_voter_set_error(&self) -> bool {
1772 (**self).is_inconsistent_voter_set_error()
1773 }
1774 fn is_ineligible_replica_error(&self) -> bool {
1775 (**self).is_ineligible_replica_error()
1776 }
1777 fn is_interrupt_error(&self) -> bool {
1778 (**self).is_interrupt_error()
1779 }
1780 fn is_invalid_commit_offset_size_error(&self) -> bool {
1781 (**self).is_invalid_commit_offset_size_error()
1782 }
1783 fn is_invalid_fetch_session_epoch_error(&self) -> bool {
1784 (**self).is_invalid_fetch_session_epoch_error()
1785 }
1786 fn is_invalid_fetch_size_error(&self) -> bool {
1787 (**self).is_invalid_fetch_size_error()
1788 }
1789 fn is_invalid_group_id_error(&self) -> bool {
1790 (**self).is_invalid_group_id_error()
1791 }
1792 fn is_invalid_partitions_error(&self) -> bool {
1793 (**self).is_invalid_partitions_error()
1794 }
1795 fn is_invalid_pid_mapping_error(&self) -> bool {
1796 (**self).is_invalid_pid_mapping_error()
1797 }
1798 fn is_invalid_principal_type_error(&self) -> bool {
1799 (**self).is_invalid_principal_type_error()
1800 }
1801 fn is_invalid_producer_epoch_error(&self) -> bool {
1802 (**self).is_invalid_producer_epoch_error()
1803 }
1804 fn is_invalid_record_error(&self) -> bool {
1805 (**self).is_invalid_record_error()
1806 }
1807 fn is_invalid_record_state_error(&self) -> bool {
1808 (**self).is_invalid_record_state_error()
1809 }
1810 fn is_invalid_registration_error(&self) -> bool {
1811 (**self).is_invalid_registration_error()
1812 }
1813 fn is_invalid_regular_expression_error(&self) -> bool {
1814 (**self).is_invalid_regular_expression_error()
1815 }
1816 fn is_invalid_replica_assignment_error(&self) -> bool {
1817 (**self).is_invalid_replica_assignment_error()
1818 }
1819 fn is_invalid_replication_factor_error(&self) -> bool {
1820 (**self).is_invalid_replication_factor_error()
1821 }
1822 fn is_invalid_request_error(&self) -> bool {
1823 (**self).is_invalid_request_error()
1824 }
1825 fn is_invalid_required_acks_error(&self) -> bool {
1826 (**self).is_invalid_required_acks_error()
1827 }
1828 fn is_invalid_session_timeout_error(&self) -> bool {
1829 (**self).is_invalid_session_timeout_error()
1830 }
1831 fn is_invalid_share_session_epoch_error(&self) -> bool {
1832 (**self).is_invalid_share_session_epoch_error()
1833 }
1834 fn is_invalid_timestamp_error(&self) -> bool {
1835 (**self).is_invalid_timestamp_error()
1836 }
1837 fn is_invalid_topic_error(&self) -> bool {
1838 (**self).is_invalid_topic_error()
1839 }
1840 fn is_invalid_txn_state_error(&self) -> bool {
1841 (**self).is_invalid_txn_state_error()
1842 }
1843 fn is_invalid_txn_timeout_error(&self) -> bool {
1844 (**self).is_invalid_txn_timeout_error()
1845 }
1846 fn is_invalid_update_version_error(&self) -> bool {
1847 (**self).is_invalid_update_version_error()
1848 }
1849 fn is_invalid_voter_key_error(&self) -> bool {
1850 (**self).is_invalid_voter_key_error()
1851 }
1852 fn is_kafka_storage_error(&self) -> bool {
1853 (**self).is_kafka_storage_error()
1854 }
1855 fn is_leader_not_available_error(&self) -> bool {
1856 (**self).is_leader_not_available_error()
1857 }
1858 fn is_listener_not_found_error(&self) -> bool {
1859 (**self).is_listener_not_found_error()
1860 }
1861 fn is_log_dir_not_found_error(&self) -> bool {
1862 (**self).is_log_dir_not_found_error()
1863 }
1864 fn is_member_id_required_error(&self) -> bool {
1865 (**self).is_member_id_required_error()
1866 }
1867 fn is_mismatched_endpoint_type_error(&self) -> bool {
1868 (**self).is_mismatched_endpoint_type_error()
1869 }
1870 fn is_network_error(&self) -> bool {
1871 (**self).is_network_error()
1872 }
1873 fn is_new_leader_elected_error(&self) -> bool {
1874 (**self).is_new_leader_elected_error()
1875 }
1876 fn is_no_reassignment_in_progress_error(&self) -> bool {
1877 (**self).is_no_reassignment_in_progress_error()
1878 }
1879 fn is_not_controller_error(&self) -> bool {
1880 (**self).is_not_controller_error()
1881 }
1882 fn is_not_coordinator_error(&self) -> bool {
1883 (**self).is_not_coordinator_error()
1884 }
1885 fn is_not_enough_replicas_error(&self) -> bool {
1886 (**self).is_not_enough_replicas_error()
1887 }
1888 fn is_not_enough_replicas_after_append_error(&self) -> bool {
1889 (**self).is_not_enough_replicas_after_append_error()
1890 }
1891 fn is_not_leader_or_follower_error(&self) -> bool {
1892 (**self).is_not_leader_or_follower_error()
1893 }
1894 fn is_offset_metadata_too_large_error(&self) -> bool {
1895 (**self).is_offset_metadata_too_large_error()
1896 }
1897 fn is_offset_moved_to_tiered_storage_error(&self) -> bool {
1898 (**self).is_offset_moved_to_tiered_storage_error()
1899 }
1900 fn is_offset_not_available_error(&self) -> bool {
1901 (**self).is_offset_not_available_error()
1902 }
1903 fn is_offset_out_of_range_error(&self) -> bool {
1904 (**self).is_offset_out_of_range_error()
1905 }
1906 fn is_operation_not_attempted_error(&self) -> bool {
1907 (**self).is_operation_not_attempted_error()
1908 }
1909 fn is_policy_violation_error(&self) -> bool {
1910 (**self).is_policy_violation_error()
1911 }
1912 fn is_position_out_of_range_error(&self) -> bool {
1913 (**self).is_position_out_of_range_error()
1914 }
1915 fn is_preferred_leader_not_available_error(&self) -> bool {
1916 (**self).is_preferred_leader_not_available_error()
1917 }
1918 fn is_principal_deserialization_error(&self) -> bool {
1919 (**self).is_principal_deserialization_error()
1920 }
1921 fn is_producer_fenced_error(&self) -> bool {
1922 (**self).is_producer_fenced_error()
1923 }
1924 fn is_quota_violation_error(&self) -> bool {
1925 (**self).is_quota_violation_error()
1926 }
1927 fn is_reassignment_in_progress_error(&self) -> bool {
1928 (**self).is_reassignment_in_progress_error()
1929 }
1930 fn is_rebalance_in_progress_error(&self) -> bool {
1931 (**self).is_rebalance_in_progress_error()
1932 }
1933 fn is_rebootstrap_required_error(&self) -> bool {
1934 (**self).is_rebootstrap_required_error()
1935 }
1936 fn is_record_batch_too_large_error(&self) -> bool {
1937 (**self).is_record_batch_too_large_error()
1938 }
1939 fn is_record_deserialization_error(&self) -> bool {
1940 (**self).is_record_deserialization_error()
1941 }
1942 fn is_record_too_large_error(&self) -> bool {
1943 (**self).is_record_too_large_error()
1944 }
1945 fn is_invalid_receive_error(&self) -> bool {
1946 (**self).is_invalid_receive_error()
1947 }
1948 fn is_config_error(&self) -> bool {
1949 (**self).is_config_error()
1950 }
1951 fn is_consumer_retriable_commit_failed_error(&self) -> bool {
1952 (**self).is_consumer_retriable_commit_failed_error()
1953 }
1954 fn is_consumer_commit_failed_error(&self) -> bool {
1955 (**self).is_consumer_commit_failed_error()
1956 }
1957 fn is_consumer_no_offset_for_partition_error(&self) -> bool {
1958 (**self).is_consumer_no_offset_for_partition_error()
1959 }
1960 fn is_consumer_log_truncation_error(&self) -> bool {
1961 (**self).is_consumer_log_truncation_error()
1962 }
1963 fn is_replica_not_available_error(&self) -> bool {
1964 (**self).is_replica_not_available_error()
1965 }
1966 fn is_resource_not_found_error(&self) -> bool {
1967 (**self).is_resource_not_found_error()
1968 }
1969 fn is_sasl_authentication_error(&self) -> bool {
1970 (**self).is_sasl_authentication_error()
1971 }
1972 fn is_schema_error(&self) -> bool {
1973 (**self).is_schema_error()
1974 }
1975 fn is_security_disabled_error(&self) -> bool {
1976 (**self).is_security_disabled_error()
1977 }
1978 fn is_share_session_limit_reached_error(&self) -> bool {
1979 (**self).is_share_session_limit_reached_error()
1980 }
1981 fn is_share_session_not_found_error(&self) -> bool {
1982 (**self).is_share_session_not_found_error()
1983 }
1984 fn is_snapshot_not_found_error(&self) -> bool {
1985 (**self).is_snapshot_not_found_error()
1986 }
1987 fn is_ssl_authentication_error(&self) -> bool {
1988 (**self).is_ssl_authentication_error()
1989 }
1990 fn is_stale_broker_epoch_error(&self) -> bool {
1991 (**self).is_stale_broker_epoch_error()
1992 }
1993 fn is_stale_member_epoch_error(&self) -> bool {
1994 (**self).is_stale_member_epoch_error()
1995 }
1996 fn is_streams_invalid_topology_error(&self) -> bool {
1997 (**self).is_streams_invalid_topology_error()
1998 }
1999 fn is_streams_invalid_topology_epoch_error(&self) -> bool {
2000 (**self).is_streams_invalid_topology_epoch_error()
2001 }
2002 fn is_streams_topology_description_update_failed_error(&self) -> bool {
2003 (**self).is_streams_topology_description_update_failed_error()
2004 }
2005 fn is_streams_topology_fenced_error(&self) -> bool {
2006 (**self).is_streams_topology_fenced_error()
2007 }
2008 fn is_telemetry_too_large_error(&self) -> bool {
2009 (**self).is_telemetry_too_large_error()
2010 }
2011 fn is_throttling_quota_exceeded_error(&self) -> bool {
2012 (**self).is_throttling_quota_exceeded_error()
2013 }
2014 fn is_topic_authorization_error(&self) -> bool {
2015 (**self).is_topic_authorization_error()
2016 }
2017 fn is_topic_deletion_disabled_error(&self) -> bool {
2018 (**self).is_topic_deletion_disabled_error()
2019 }
2020 fn is_topic_exists_error(&self) -> bool {
2021 (**self).is_topic_exists_error()
2022 }
2023 fn is_transaction_abortable_error(&self) -> bool {
2024 (**self).is_transaction_abortable_error()
2025 }
2026 fn is_transaction_aborted_error(&self) -> bool {
2027 (**self).is_transaction_aborted_error()
2028 }
2029 fn is_transaction_coordinator_fenced_error(&self) -> bool {
2030 (**self).is_transaction_coordinator_fenced_error()
2031 }
2032 fn is_transactional_id_authorization_error(&self) -> bool {
2033 (**self).is_transactional_id_authorization_error()
2034 }
2035 fn is_transactional_id_not_found_error(&self) -> bool {
2036 (**self).is_transactional_id_not_found_error()
2037 }
2038 fn is_unacceptable_credential_error(&self) -> bool {
2039 (**self).is_unacceptable_credential_error()
2040 }
2041 fn is_unknown_controller_id_error(&self) -> bool {
2042 (**self).is_unknown_controller_id_error()
2043 }
2044 fn is_unknown_leader_epoch_error(&self) -> bool {
2045 (**self).is_unknown_leader_epoch_error()
2046 }
2047 fn is_unknown_member_id_error(&self) -> bool {
2048 (**self).is_unknown_member_id_error()
2049 }
2050 fn is_unknown_producer_id_error(&self) -> bool {
2051 (**self).is_unknown_producer_id_error()
2052 }
2053 fn is_unknown_server_error(&self) -> bool {
2054 (**self).is_unknown_server_error()
2055 }
2056 fn is_unknown_subscription_id_error(&self) -> bool {
2057 (**self).is_unknown_subscription_id_error()
2058 }
2059 fn is_unknown_topic_id_error(&self) -> bool {
2060 (**self).is_unknown_topic_id_error()
2061 }
2062 fn is_unknown_topic_or_partition_error(&self) -> bool {
2063 (**self).is_unknown_topic_or_partition_error()
2064 }
2065 fn is_unreleased_instance_id_error(&self) -> bool {
2066 (**self).is_unreleased_instance_id_error()
2067 }
2068 fn is_unstable_offset_commit_error(&self) -> bool {
2069 (**self).is_unstable_offset_commit_error()
2070 }
2071 fn is_unsupported_assignor_error(&self) -> bool {
2072 (**self).is_unsupported_assignor_error()
2073 }
2074 fn is_unsupported_by_authentication_error(&self) -> bool {
2075 (**self).is_unsupported_by_authentication_error()
2076 }
2077 fn is_unsupported_compression_type_error(&self) -> bool {
2078 (**self).is_unsupported_compression_type_error()
2079 }
2080 fn is_unsupported_endpoint_type_error(&self) -> bool {
2081 (**self).is_unsupported_endpoint_type_error()
2082 }
2083 fn is_unsupported_for_message_format_error(&self) -> bool {
2084 (**self).is_unsupported_for_message_format_error()
2085 }
2086 fn is_unsupported_sasl_mechanism_error(&self) -> bool {
2087 (**self).is_unsupported_sasl_mechanism_error()
2088 }
2089 fn is_unsupported_version_error(&self) -> bool {
2090 (**self).is_unsupported_version_error()
2091 }
2092 fn is_voter_not_found_error(&self) -> bool {
2093 (**self).is_voter_not_found_error()
2094 }
2095 fn is_wakeup_error(&self) -> bool {
2096 (**self).is_wakeup_error()
2097 }
2098}
2099
2100impl<T: ErrorMessage + ?Sized> ErrorMessage for Box<T> {
2101 fn message(&self) -> &str {
2102 (**self).message()
2103 }
2104}
2105
2106impl<T: ErrorCode + ?Sized> ErrorCode for Box<T> {
2107 fn error(&self) -> Errors {
2108 (**self).error()
2109 }
2110}
2111
2112impl<T: ErrorName + ?Sized> ErrorName for Box<T> {
2113 fn name(&self) -> &'static str {
2114 (**self).name()
2115 }
2116}
2117
2118// ---------------------------------------------------------------------------
2119// Specific error structs — correspond to Java error subclasses
2120// ---------------------------------------------------------------------------
2121
2122/// Declares a message-only error struct — one Java class that carries nothing
2123/// but its message.
2124///
2125/// Java gives each of these its own class, which is exactly what
2126/// `#[enum_dispatch]` requires: the payload type answers the hierarchy
2127/// predicates, so `Error::Timeout` and `Error::Wakeup` cannot both carry a
2128/// `String`. The generated `Display` renders as `"<TypeName>: <message>"`,
2129/// preserving the strings the previous hand-written `Display` produced.
2130///
2131/// Every path in the expansion is `$crate`-qualified, as in
2132/// [`kafka_error_type`], so an invoking file needs nothing in scope but the
2133/// macro itself. The six JDK `Local*` classes each live in their own file per
2134/// CLAUDE.md §2 and invoke this from there.
2135///
2136/// # Constructors deliberately not modelled
2137///
2138/// The six classes stand in for JDK types (`java.lang.IllegalStateException`,
2139/// `java.lang.IllegalArgumentException`,
2140/// `java.lang.UnsupportedOperationException`,
2141/// `java.lang.NullPointerException`,
2142/// `java.util.ConcurrentModificationException`,
2143/// `java.util.concurrent.TimeoutException`), each of which really declares all
2144/// four of `()`, `(String)`, `(Throwable)`, `(String, Throwable)`. Under
2145/// CLAUDE.md §2 the no-arg form would own the plain `new` and the message form
2146/// would become `with_message`.
2147///
2148/// They are not modelled, and `new` keeps the message form, for two reasons:
2149///
2150/// - These are not translated Kafka classes but minimal stand-ins for classes
2151/// outside the repository (CLAUDE.md §1) — hence the macro's name. A
2152/// null-message constructor and a cause-only constructor would be public API
2153/// with no caller and no Kafka contract behind them (DoD #7).
2154/// - [`kafka_error_type`] cannot follow suit: it declares 145 classes from one
2155/// body, and only ~19 of their Java counterparts have a no-arg constructor.
2156/// Were `new` to mean the no-arg form here and the message form there,
2157/// `SomeError::new("msg")` would compile or not depending on which macro
2158/// declared the class, with nothing at the call site to say which.
2159macro_rules! message_only_error {
2160 ($(#[$meta:meta])* $name:ident) => {
2161 $(#[$meta])*
2162 #[derive(Clone, Debug)]
2163 pub struct $name {
2164 message: String,
2165 /// The underlying cause — `Throwable`'s `cause`, null by default.
2166 source: Option<Box<$crate::common::Error>>,
2167 }
2168
2169 impl $name {
2170 /// Create the error with the given message and no cause,
2171 /// mirroring the `(String message)` constructor.
2172 ///
2173 /// Keeps the plain name under CLAUDE.md §2, for consistency with
2174 /// `kafka_error_type!` — see the note on this macro about the
2175 /// constructors these classes deliberately do not model.
2176 /// (Deliberately not an intra-doc link: this doc comment expands
2177 /// into each declaring module, where that macro is not in scope.)
2178 pub fn new(message: impl Into<String>) -> Self {
2179 Self { message: message.into(), source: None }
2180 }
2181
2182 /// Create the error with the given message and an underlying cause,
2183 /// mirroring the `(String message, Throwable cause)` constructor.
2184 ///
2185 /// Suffixed with the one parameter beyond the `{message}`
2186 /// intersection (CLAUDE.md §2) — see [`new`](Self::new).
2187 pub fn with_source(message: impl Into<String>, source: $crate::common::Error) -> Self {
2188 Self { message: message.into(), source: Some(Box::new(source)) }
2189 }
2190
2191 /// The error message.
2192 pub fn message(&self) -> &str {
2193 &self.message
2194 }
2195
2196 /// The underlying cause, if any. Mirrors Java's `getCause()`.
2197 pub fn source(&self) -> Option<&$crate::common::Error> {
2198 self.source.as_deref()
2199 }
2200 }
2201
2202 impl $crate::common::error::ErrorSource for $name {
2203 fn source(&self) -> Option<&$crate::common::Error> {
2204 self.source.as_deref()
2205 }
2206 }
2207
2208 impl ::std::error::Error for $name {
2209 fn source(&self) -> Option<&(dyn ::std::error::Error + 'static)> {
2210 self.source
2211 .as_deref()
2212 .map(|e| e as &(dyn ::std::error::Error + 'static))
2213 }
2214 }
2215
2216 impl $crate::common::error::ErrorName for $name {
2217 fn name(&self) -> &'static str {
2218 stringify!($name)
2219 }
2220 }
2221
2222 // No protocol code: these are the generic `java.lang` / `java.util`
2223 // classes, raised only by this client and never reported by a broker, so
2224 // the trait default (`Errors::UnknownServerError`) is the right answer.
2225 impl $crate::common::error::ErrorCode for $name {}
2226
2227 impl $crate::common::error::ErrorMessage for $name {
2228 fn message(&self) -> &str {
2229 // Field access, not `self.message()`: that would resolve to the
2230 // inherent method above and is only accidentally equivalent.
2231 &self.message
2232 }
2233 }
2234
2235 impl ::std::fmt::Display for $name {
2236 fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result {
2237 write!(f, "{}: {}", stringify!($name), self.message)
2238 }
2239 }
2240 };
2241}
2242
2243pub(crate) use message_only_error;
2244
2245// ---------------------------------------------------------------------------
2246// Display — each payload renders itself, as each Java class has its own
2247// toString(). `Error`'s own Display just forwards (see `Error::as_display`).
2248// ---------------------------------------------------------------------------
2249
2250// `ErrorMessage` is not hand-written for any payload: the message-only types get
2251// it from the `message_only_error!` macro, the five that embed a [`KafkaError`]
2252// delegate to that field via `#[delegate(ErrorMessage, target = "kafka_error")]`,
2253// and [`KafkaError`] itself uses `target = "self"` over its inherent method.
2254
2255// ---------------------------------------------------------------------------
2256// ErrorName / ErrorHierarchy impls — each type's override list IS its Java
2257// `extends` chain
2258// ---------------------------------------------------------------------------
2259
2260// The fifteen payloads that are neither `kafka_error_type!` nor
2261// `message_only_error!` declarations: each adds subclass state, so it is
2262// hand-written in its own file. `ErrorName` is a crate-local trait, so the impls
2263// live here rather than in fifteen files — keeping the one place a reader can
2264// check that every payload answers, next to the trait itself. `KafkaError` is
2265// the sixteenth and answers next to its own struct, in `kafka_error.rs`.
2266macro_rules! error_name_impl {
2267 ($($name:ident),+ $(,)?) => {
2268 $(
2269 impl ErrorName for $name {
2270 fn name(&self) -> &'static str {
2271 stringify!($name)
2272 }
2273 }
2274 )+
2275 };
2276}
2277
2278error_name_impl! {
2279 CorrelationIdMismatchError,
2280 DuplicateResourceError,
2281 GroupAuthorizationError,
2282 InvalidTopicError,
2283 InvalidReceiveError,
2284 RecordDeserializationError,
2285 ResourceNotFoundError,
2286 QuotaViolationError,
2287 ThrottlingQuotaExceededError,
2288 TopicAuthorizationError,
2289 ConsumerCommitFailedError,
2290 ConsumerLogTruncationError,
2291 ConsumerNoOffsetForPartitionError,
2292 ConsumerOffsetOutOfRangeError,
2293 ConsumerRetriableCommitFailedError,
2294 LocalCallbackError,
2295}
2296
2297// `IllegalArgumentException`, `IllegalStateException`,
2298// `UnsupportedOperationException`, `NullPointerException`,
2299// `ConcurrentModificationException` and
2300// `java.util.concurrent.TimeoutException` are `java.lang` / `java.util` exceptions sitting BESIDE `KafkaException`, not
2301// below it. Every Kafka hierarchy predicate is false for them, so each overrides
2302// only its own class's predicate — the statement that they are outside the
2303// Kafka hierarchy.
2304impl ErrorHierarchy for LocalIllegalArgumentError {
2305 fn is_local_illegal_argument_error(&self) -> bool {
2306 true
2307 }
2308}
2309impl ErrorHierarchy for LocalIllegalStateError {
2310 fn is_local_illegal_state_error(&self) -> bool {
2311 true
2312 }
2313}
2314impl ErrorHierarchy for LocalConcurrentModificationError {
2315 fn is_local_concurrent_modification_error(&self) -> bool {
2316 true
2317 }
2318}
2319impl ErrorHierarchy for LocalTimeoutError {
2320 fn is_local_timeout_error(&self) -> bool {
2321 true
2322 }
2323}
2324impl ErrorHierarchy for LocalUnsupportedOperationError {
2325 fn is_local_unsupported_operation_error(&self) -> bool {
2326 true
2327 }
2328}
2329impl ErrorHierarchy for LocalNullPointerError {
2330 fn is_local_null_pointer_error(&self) -> bool {
2331 true
2332 }
2333}
2334// Beside `KafkaException` like the six above: a foreign callback's error is
2335// not a Kafka error, so the client wraps it as Java wraps a foreign `Throwable`.
2336impl ErrorHierarchy for LocalCallbackError {
2337 fn is_local_callback_error(&self) -> bool {
2338 true
2339 }
2340}
2341
2342// ---------------------------------------------------------------------------
2343// Error — unified enum for polymorphic error handling
2344// ---------------------------------------------------------------------------
2345
2346/// Unified error type for polymorphic error handling — this crate's
2347/// top-level error, returned by every fallible API.
2348///
2349/// This enum wraps the error struct hierarchy so that any error can be
2350/// stored and returned through a single type. Most variants hold a specific
2351/// error struct that embeds [`KafkaError`] as its base;
2352/// [`KafkaError`](Self::KafkaError) holds a bare one, standing for Java's
2353/// `KafkaException` with no subclass.
2354///
2355/// It also carries the generic programming errors that Java keeps OUTSIDE
2356/// the `KafkaException` hierarchy ([`LocalIllegalArgument`](Self::LocalIllegalArgument),
2357/// [`LocalIllegalState`](Self::LocalIllegalState),
2358/// [`LocalConcurrentModification`](Self::LocalConcurrentModification)); flattening two
2359/// Java families into one enum is what makes
2360/// [`is_kafka_error`](Self::is_kafka_error) necessary.
2361///
2362/// **Classify by predicate, not by variant or code.** Java callers write
2363/// `e instanceof TopicAuthorizationException`; Rust callers write
2364/// `e.is_topic_authorization_error()`. Every variant has such a predicate,
2365/// and every intermediate Java class has one too. Prefer them to
2366/// `matches!(e, Error::TopicAuthorization(_))`. A predicate means "this class
2367/// or a subclass", like `instanceof`, so it still matches a subclass a later
2368/// Java release adds, whereas a variant match would miss it.
2369/// There is no public numeric
2370/// error code: the wire-level `Errors` enum lives in `common.protocol`, a
2371/// package Java marks "not a supported API", so the crate keeps it
2372/// `pub(crate)`. The C bindings expose the class as the
2373/// `kafka_common_Error_e` enum instead.
2374///
2375/// `message()` and `is_retriable_error()` are delegated to the inner
2376/// [`KafkaError`] base. `request_utils::RequestUtils::is_fatal_error` and
2377/// `is_transaction_abortable_error()`
2378/// live only here: `KafkaError` is Java's `KafkaException`, which has
2379/// neither, so these librdkafka-style predicates belong on this enum rather
2380/// than on the Java-shaped base.
2381///
2382/// This type is used in `Result` return types and `Option` storage where
2383/// any kind of Kafka error may occur.
2384#[derive(Clone, Debug, Delegate)]
2385#[delegate(ErrorHierarchy)]
2386#[delegate(ErrorMessage)]
2387#[delegate(ErrorCode)]
2388#[delegate(ErrorName)]
2389#[delegate(ErrorSource)]
2390#[delegate(Display)]
2391#[non_exhaustive]
2392// the crate's flat base error type (CLAUDE.md §12.3)
2393#[doc(alias = "rust-only")]
2394pub enum Error {
2395 // Payloads defined in this file: the bare `KafkaException` and the
2396 // generic `java.lang` / `java.util` runtime errors, which have no
2397 // package in the Kafka source to mirror.
2398 /// A plain Kafka error carrying only the base fields — Java's bare
2399 /// `KafkaException`, with no subclass-specific context.
2400 KafkaError(KafkaError),
2401 /// Illegal argument error — an invalid argument was provided to a method.
2402 ///
2403 /// Java's `IllegalArgumentException`.
2404 LocalIllegalArgument(LocalIllegalArgumentError),
2405 /// Illegal state error — a method was called in an invalid state.
2406 ///
2407 /// Java's `IllegalStateException`.
2408 LocalIllegalState(LocalIllegalStateError),
2409 /// Concurrent modification error — the consumer was accessed from more
2410 /// than one thread.
2411 ///
2412 /// Java's `java.util.ConcurrentModificationException`,
2413 /// thrown by `KafkaConsumer.acquire()` ("KafkaConsumer is not safe for
2414 /// multi-threaded access"). Like `LocalIllegalState`, it is a plain
2415 /// `RuntimeException` — neither an `ApiException` nor a `KafkaException`
2416 /// — so it is never retriable and never fatal.
2417 LocalConcurrentModification(LocalConcurrentModificationError),
2418 /// A wait on a future timed out.
2419 ///
2420 /// Java's `java.util.concurrent.TimeoutException` raised by
2421 /// `Future.get(timeout, unit)`. Distinct from
2422 /// [`Timeout`](Self::Timeout), which is
2423 /// `org.apache.kafka.common.errors.TimeoutException` — a
2424 /// `RetriableException`. This one sits beside `KafkaException`, so it is
2425 /// never retriable, never an api error and carries no wire code.
2426 LocalTimeout(LocalTimeoutError),
2427 /// Unsupported operation error — the requested operation is not supported.
2428 ///
2429 /// Java's `java.lang.UnsupportedOperationException`, thrown
2430 /// where Java leaves an operation unimplemented (`MockAdminClient`'s "Not
2431 /// implemented yet" methods, `MockConsumer.offsetsForTimes`) or rejects it
2432 /// (`Compression.decompressionOutputSize`). Like `LocalIllegalState` it is a
2433 /// plain `RuntimeException` — neither an `ApiException` nor a
2434 /// `KafkaException` — so it is never retriable and never fatal. Distinct
2435 /// from [`UnsupportedVersion`](Self::UnsupportedVersion), the wire-level
2436 /// `ApiException` for a broker lacking an API version.
2437 LocalUnsupportedOperation(LocalUnsupportedOperationError),
2438 /// Null pointer error — a mandatory argument was null.
2439 ///
2440 /// Java's `java.lang.NullPointerException`. Rust has no null, so only the C
2441 /// boundary raises it, for a `NULL` mandatory pointer. Like
2442 /// `LocalIllegalState` it is a plain `RuntimeException` — neither an
2443 /// `ApiException` nor a `KafkaException` — so it is never retriable and
2444 /// never fatal.
2445 LocalNullPointer(LocalNullPointerError),
2446 /// An error raised by a callback written in another language.
2447 ///
2448 /// No Java class: it stands in for the foreign error, which cannot cross
2449 /// the FFI boundary, and carries an opaque pointer the binding uses to find
2450 /// the original again. Outside the Kafka hierarchy, like
2451 /// [`LocalIllegalState`](Self::LocalIllegalState), so the client wraps it
2452 /// as Java wraps a listener's foreign `Throwable`.
2453 LocalCallback(LocalCallbackError),
2454
2455 // One variant per Java exception class, each carrying the struct that
2456 // declares its own `extends` chain. Delegation does the rest.
2457 /// See [`ApiError`](crate::common::errors::ApiError).
2458 Api(ApiError),
2459 /// See [`AuthenticationError`](crate::common::errors::AuthenticationError).
2460 Authentication(AuthenticationError),
2461 /// See [`AuthorizationError`](crate::common::errors::AuthorizationError).
2462 Authorization(AuthorizationError),
2463 /// See [`AuthorizerNotReadyError`](crate::common::errors::AuthorizerNotReadyError).
2464 AuthorizerNotReady(AuthorizerNotReadyError),
2465 /// See [`BootstrapResolutionError`](crate::common::errors::BootstrapResolutionError).
2466 BootstrapResolution(BootstrapResolutionError),
2467 /// See [`BrokerIdNotRegisteredError`](crate::common::errors::BrokerIdNotRegisteredError).
2468 BrokerIdNotRegistered(BrokerIdNotRegisteredError),
2469 /// See [`BrokerNotAvailableError`](crate::common::errors::BrokerNotAvailableError).
2470 BrokerNotAvailable(BrokerNotAvailableError),
2471 /// See [`ProducerBufferExhaustedError`](crate::producer::ProducerBufferExhaustedError).
2472 ProducerBufferExhausted(ProducerBufferExhaustedError),
2473 /// See [`ClusterAuthorizationError`](crate::common::errors::ClusterAuthorizationError).
2474 ClusterAuthorization(ClusterAuthorizationError),
2475 /// See [`ConcurrentTransactionsError`](crate::common::errors::ConcurrentTransactionsError).
2476 ConcurrentTransactions(ConcurrentTransactionsError),
2477 /// See [`ControllerIdNotRegisteredError`](crate::common::errors::ControllerIdNotRegisteredError).
2478 ControllerIdNotRegistered(ControllerIdNotRegisteredError),
2479 /// See [`ControllerMovedError`](crate::common::errors::ControllerMovedError).
2480 ControllerMoved(ControllerMovedError),
2481 /// See [`CoordinatorLoadInProgressError`](crate::common::errors::CoordinatorLoadInProgressError).
2482 CoordinatorLoadInProgress(CoordinatorLoadInProgressError),
2483 /// See [`CoordinatorNotAvailableError`](crate::common::errors::CoordinatorNotAvailableError).
2484 CoordinatorNotAvailable(CoordinatorNotAvailableError),
2485 /// See `CorrelationIdMismatchError`.
2486 ///
2487 /// Lives in `common.requests`, not `common.errors`, and extends
2488 /// `IllegalStateException` rather than `KafkaException` — so like
2489 /// [`LocalIllegalState`](Self::LocalIllegalState) it answers `false` to every
2490 /// predicate.
2491 CorrelationIdMismatch(CorrelationIdMismatchError),
2492 /// See [`CorruptRecordError`](crate::common::errors::CorruptRecordError).
2493 CorruptRecord(CorruptRecordError),
2494 /// See [`DelegationTokenAuthorizationError`](crate::common::errors::DelegationTokenAuthorizationError).
2495 DelegationTokenAuthorization(DelegationTokenAuthorizationError),
2496 /// See [`DelegationTokenDisabledError`](crate::common::errors::DelegationTokenDisabledError).
2497 DelegationTokenDisabled(DelegationTokenDisabledError),
2498 /// See [`DelegationTokenExpiredError`](crate::common::errors::DelegationTokenExpiredError).
2499 DelegationTokenExpired(DelegationTokenExpiredError),
2500 /// See [`DelegationTokenNotFoundError`](crate::common::errors::DelegationTokenNotFoundError).
2501 DelegationTokenNotFound(DelegationTokenNotFoundError),
2502 /// See [`DelegationTokenOwnerMismatchError`](crate::common::errors::DelegationTokenOwnerMismatchError).
2503 DelegationTokenOwnerMismatch(DelegationTokenOwnerMismatchError),
2504 /// See [`DisconnectError`](crate::common::errors::DisconnectError).
2505 Disconnect(DisconnectError),
2506 /// See [`DuplicateBrokerRegistrationError`](crate::common::errors::DuplicateBrokerRegistrationError).
2507 DuplicateBrokerRegistration(DuplicateBrokerRegistrationError),
2508 /// See [`DuplicateResourceError`](crate::common::errors::DuplicateResourceError).
2509 DuplicateResource(DuplicateResourceError),
2510 /// See [`DuplicateSequenceError`](crate::common::errors::DuplicateSequenceError).
2511 DuplicateSequence(DuplicateSequenceError),
2512 /// See [`DuplicateVoterError`](crate::common::errors::DuplicateVoterError).
2513 DuplicateVoter(DuplicateVoterError),
2514 /// See [`ElectionNotNeededError`](crate::common::errors::ElectionNotNeededError).
2515 ElectionNotNeeded(ElectionNotNeededError),
2516 /// See [`EligibleLeadersNotAvailableError`](crate::common::errors::EligibleLeadersNotAvailableError).
2517 EligibleLeadersNotAvailable(EligibleLeadersNotAvailableError),
2518 /// See [`FeatureUpdateFailedError`](crate::common::errors::FeatureUpdateFailedError).
2519 FeatureUpdateFailed(FeatureUpdateFailedError),
2520 /// See [`FencedInstanceIdError`](crate::common::errors::FencedInstanceIdError).
2521 FencedInstanceId(FencedInstanceIdError),
2522 /// See [`FencedLeaderEpochError`](crate::common::errors::FencedLeaderEpochError).
2523 FencedLeaderEpoch(FencedLeaderEpochError),
2524 /// See [`FencedMemberEpochError`](crate::common::errors::FencedMemberEpochError).
2525 FencedMemberEpoch(FencedMemberEpochError),
2526 /// See [`FencedStateEpochError`](crate::common::errors::FencedStateEpochError).
2527 FencedStateEpoch(FencedStateEpochError),
2528 /// See [`FetchSessionIdNotFoundError`](crate::common::errors::FetchSessionIdNotFoundError).
2529 FetchSessionIdNotFound(FetchSessionIdNotFoundError),
2530 /// See [`FetchSessionTopicIdError`](crate::common::errors::FetchSessionTopicIdError).
2531 FetchSessionTopicId(FetchSessionTopicIdError),
2532 /// See [`GroupAuthorizationError`](crate::common::errors::GroupAuthorizationError).
2533 GroupAuthorization(GroupAuthorizationError),
2534 /// See [`GroupDeletionFailedError`](crate::common::errors::GroupDeletionFailedError).
2535 GroupDeletionFailed(GroupDeletionFailedError),
2536 /// See [`GroupIdNotFoundError`](crate::common::errors::GroupIdNotFoundError).
2537 GroupIdNotFound(GroupIdNotFoundError),
2538 /// See [`GroupMaxSizeReachedError`](crate::common::errors::GroupMaxSizeReachedError).
2539 GroupMaxSizeReached(GroupMaxSizeReachedError),
2540 /// See [`GroupNotEmptyError`](crate::common::errors::GroupNotEmptyError).
2541 GroupNotEmpty(GroupNotEmptyError),
2542 /// See [`GroupSubscribedToTopicError`](crate::common::errors::GroupSubscribedToTopicError).
2543 GroupSubscribedToTopic(GroupSubscribedToTopicError),
2544 /// See [`IllegalGenerationError`](crate::common::errors::IllegalGenerationError).
2545 IllegalGeneration(IllegalGenerationError),
2546 /// See [`IllegalSaslStateError`](crate::common::errors::IllegalSaslStateError).
2547 IllegalSaslState(IllegalSaslStateError),
2548 /// See [`InconsistentClusterIdError`](crate::common::errors::InconsistentClusterIdError).
2549 InconsistentClusterId(InconsistentClusterIdError),
2550 /// See [`InconsistentGroupProtocolError`](crate::common::errors::InconsistentGroupProtocolError).
2551 InconsistentGroupProtocol(InconsistentGroupProtocolError),
2552 /// See [`InconsistentTopicIdError`](crate::common::errors::InconsistentTopicIdError).
2553 InconsistentTopicId(InconsistentTopicIdError),
2554 /// See [`InconsistentVoterSetError`](crate::common::errors::InconsistentVoterSetError).
2555 InconsistentVoterSet(InconsistentVoterSetError),
2556 /// See [`IneligibleReplicaError`](crate::common::errors::IneligibleReplicaError).
2557 IneligibleReplica(IneligibleReplicaError),
2558 /// See [`InterruptError`](crate::common::errors::InterruptError).
2559 Interrupt(InterruptError),
2560 /// See [`InvalidCommitOffsetSizeError`](crate::common::errors::InvalidCommitOffsetSizeError).
2561 InvalidCommitOffsetSize(InvalidCommitOffsetSizeError),
2562 /// See [`InvalidConfigurationError`](crate::common::errors::InvalidConfigurationError).
2563 InvalidConfiguration(InvalidConfigurationError),
2564 /// See [`InvalidFetchSessionEpochError`](crate::common::errors::InvalidFetchSessionEpochError).
2565 InvalidFetchSessionEpoch(InvalidFetchSessionEpochError),
2566 /// See [`InvalidFetchSizeError`](crate::common::errors::InvalidFetchSizeError).
2567 InvalidFetchSize(InvalidFetchSizeError),
2568 /// See [`InvalidGroupIdError`](crate::common::errors::InvalidGroupIdError).
2569 InvalidGroupId(InvalidGroupIdError),
2570 /// See [`InvalidOffsetError`](crate::common::errors::InvalidOffsetError).
2571 InvalidOffset(InvalidOffsetError),
2572 /// See [`InvalidPartitionsError`](crate::common::errors::InvalidPartitionsError).
2573 InvalidPartitions(InvalidPartitionsError),
2574 /// See [`InvalidPidMappingError`](crate::common::errors::InvalidPidMappingError).
2575 InvalidPidMapping(InvalidPidMappingError),
2576 /// See [`InvalidPrincipalTypeError`](crate::common::errors::InvalidPrincipalTypeError).
2577 InvalidPrincipalType(InvalidPrincipalTypeError),
2578 /// See [`InvalidProducerEpochError`](crate::common::errors::InvalidProducerEpochError).
2579 InvalidProducerEpoch(InvalidProducerEpochError),
2580 /// See [`InvalidRecordError`](crate::common::InvalidRecordError).
2581 InvalidRecord(InvalidRecordError),
2582 /// See [`InvalidRecordStateError`](crate::common::errors::InvalidRecordStateError).
2583 InvalidRecordState(InvalidRecordStateError),
2584 /// See [`InvalidRegistrationError`](crate::common::errors::InvalidRegistrationError).
2585 InvalidRegistration(InvalidRegistrationError),
2586 /// See [`InvalidRegularExpression`](crate::common::errors::InvalidRegularExpression).
2587 InvalidRegularExpression(InvalidRegularExpression),
2588 /// See [`InvalidReplicaAssignmentError`](crate::common::errors::InvalidReplicaAssignmentError).
2589 InvalidReplicaAssignment(InvalidReplicaAssignmentError),
2590 /// See [`InvalidReplicationFactorError`](crate::common::errors::InvalidReplicationFactorError).
2591 InvalidReplicationFactor(InvalidReplicationFactorError),
2592 /// See [`InvalidRequestError`](crate::common::errors::InvalidRequestError).
2593 InvalidRequest(InvalidRequestError),
2594 /// See [`InvalidRequiredAcksError`](crate::common::errors::InvalidRequiredAcksError).
2595 InvalidRequiredAcks(InvalidRequiredAcksError),
2596 /// See [`InvalidSessionTimeoutError`](crate::common::errors::InvalidSessionTimeoutError).
2597 InvalidSessionTimeout(InvalidSessionTimeoutError),
2598 /// See [`InvalidShareSessionEpochError`](crate::common::errors::InvalidShareSessionEpochError).
2599 InvalidShareSessionEpoch(InvalidShareSessionEpochError),
2600 /// See [`InvalidTimestampError`](crate::common::errors::InvalidTimestampError).
2601 InvalidTimestamp(InvalidTimestampError),
2602 /// See [`InvalidTopicError`](crate::common::errors::InvalidTopicError).
2603 InvalidTopic(InvalidTopicError),
2604 /// See [`InvalidTxnStateError`](crate::common::errors::InvalidTxnStateError).
2605 InvalidTxnState(InvalidTxnStateError),
2606 /// See [`InvalidTxnTimeoutError`](crate::common::errors::InvalidTxnTimeoutError).
2607 InvalidTxnTimeout(InvalidTxnTimeoutError),
2608 /// See [`InvalidUpdateVersionError`](crate::common::errors::InvalidUpdateVersionError).
2609 InvalidUpdateVersion(InvalidUpdateVersionError),
2610 /// See [`InvalidVoterKeyError`](crate::common::errors::InvalidVoterKeyError).
2611 InvalidVoterKey(InvalidVoterKeyError),
2612 /// See [`KafkaStorageError`](crate::common::errors::KafkaStorageError).
2613 KafkaStorage(KafkaStorageError),
2614 /// See [`LeaderNotAvailableError`](crate::common::errors::LeaderNotAvailableError).
2615 LeaderNotAvailable(LeaderNotAvailableError),
2616 /// See [`ListenerNotFoundError`](crate::common::errors::ListenerNotFoundError).
2617 ListenerNotFound(ListenerNotFoundError),
2618 /// See [`LogDirNotFoundError`](crate::common::errors::LogDirNotFoundError).
2619 LogDirNotFound(LogDirNotFoundError),
2620 /// See [`MemberIdRequiredError`](crate::common::errors::MemberIdRequiredError).
2621 MemberIdRequired(MemberIdRequiredError),
2622 /// See [`MismatchedEndpointTypeError`](crate::common::errors::MismatchedEndpointTypeError).
2623 MismatchedEndpointType(MismatchedEndpointTypeError),
2624 /// See [`NetworkError`](crate::common::errors::NetworkError).
2625 Network(NetworkError),
2626 /// See [`NewLeaderElectedError`](crate::common::errors::NewLeaderElectedError).
2627 NewLeaderElected(NewLeaderElectedError),
2628 /// See [`NoReassignmentInProgressError`](crate::common::errors::NoReassignmentInProgressError).
2629 NoReassignmentInProgress(NoReassignmentInProgressError),
2630 /// See [`NotControllerError`](crate::common::errors::NotControllerError).
2631 NotController(NotControllerError),
2632 /// See [`NotCoordinatorError`](crate::common::errors::NotCoordinatorError).
2633 NotCoordinator(NotCoordinatorError),
2634 /// See [`NotEnoughReplicasError`](crate::common::errors::NotEnoughReplicasError).
2635 NotEnoughReplicas(NotEnoughReplicasError),
2636 /// See [`NotEnoughReplicasAfterAppendError`](crate::common::errors::NotEnoughReplicasAfterAppendError).
2637 NotEnoughReplicasAfterAppend(NotEnoughReplicasAfterAppendError),
2638 /// See [`NotLeaderOrFollowerError`](crate::common::errors::NotLeaderOrFollowerError).
2639 NotLeaderOrFollower(NotLeaderOrFollowerError),
2640 /// See [`OffsetMetadataTooLarge`](crate::common::errors::OffsetMetadataTooLarge).
2641 OffsetMetadataTooLarge(OffsetMetadataTooLarge),
2642 /// See [`OffsetMovedToTieredStorageError`](crate::common::errors::OffsetMovedToTieredStorageError).
2643 OffsetMovedToTieredStorage(OffsetMovedToTieredStorageError),
2644 /// See [`OffsetNotAvailableError`](crate::common::errors::OffsetNotAvailableError).
2645 OffsetNotAvailable(OffsetNotAvailableError),
2646 /// See [`OffsetOutOfRangeError`](crate::common::errors::OffsetOutOfRangeError).
2647 OffsetOutOfRange(OffsetOutOfRangeError),
2648 /// See [`OperationNotAttemptedError`](crate::common::errors::OperationNotAttemptedError).
2649 OperationNotAttempted(OperationNotAttemptedError),
2650 /// See [`OutOfOrderSequenceError`](crate::common::errors::OutOfOrderSequenceError).
2651 OutOfOrderSequence(OutOfOrderSequenceError),
2652 /// See [`PolicyViolationError`](crate::common::errors::PolicyViolationError).
2653 PolicyViolation(PolicyViolationError),
2654 /// See [`PositionOutOfRangeError`](crate::common::errors::PositionOutOfRangeError).
2655 PositionOutOfRange(PositionOutOfRangeError),
2656 /// See [`PreferredLeaderNotAvailableError`](crate::common::errors::PreferredLeaderNotAvailableError).
2657 PreferredLeaderNotAvailable(PreferredLeaderNotAvailableError),
2658 /// See [`PrincipalDeserializationError`](crate::common::errors::PrincipalDeserializationError).
2659 PrincipalDeserialization(PrincipalDeserializationError),
2660 /// See [`ProducerFencedError`](crate::common::errors::ProducerFencedError).
2661 ProducerFenced(ProducerFencedError),
2662 /// See [`QuotaViolationError`](crate::common::metrics::QuotaViolationError).
2663 ///
2664 /// Boxed for the same reason as [`RecordDeserialization`](Self::RecordDeserialization):
2665 /// it carries a whole [`MetricName`](crate::common::MetricName) (three
2666 /// `String`s and a `BTreeMap`), which unboxed makes it the largest payload in
2667 /// the enum at 120 bytes and pushes `Error` — and with it every
2668 /// `Result<_, Error>` in the crate — past clippy's 128-byte
2669 /// `result_large_err` threshold.
2670 QuotaViolation(Box<QuotaViolationError>),
2671 /// See [`ReassignmentInProgressError`](crate::common::errors::ReassignmentInProgressError).
2672 ReassignmentInProgress(ReassignmentInProgressError),
2673 /// See [`RebalanceInProgressError`](crate::common::errors::RebalanceInProgressError).
2674 RebalanceInProgress(RebalanceInProgressError),
2675 /// See [`RebootstrapRequiredError`](crate::common::errors::RebootstrapRequiredError).
2676 RebootstrapRequired(RebootstrapRequiredError),
2677 /// See [`RecordBatchTooLargeError`](crate::common::errors::RecordBatchTooLargeError).
2678 RecordBatchTooLarge(RecordBatchTooLargeError),
2679 /// See [`RecordDeserializationError`](crate::common::errors::RecordDeserializationError).
2680 ///
2681 /// Boxed: it carries the full record context (partition, offsets, key/value
2682 /// buffers, headers), which unboxed pushes `Error` — and every
2683 /// `Result<_, Error>` — past clippy's 128-byte `result_large_err` threshold.
2684 RecordDeserialization(Box<RecordDeserializationError>),
2685 /// See [`RecordTooLargeError`](crate::common::errors::RecordTooLargeError).
2686 RecordTooLarge(RecordTooLargeError),
2687 /// See `InvalidReceiveError`.
2688 InvalidReceive(InvalidReceiveError),
2689 /// See [`ConfigError`](crate::common::config::ConfigError).
2690 Config(ConfigError),
2691 /// See [`ConsumerRetriableCommitFailedError`](crate::consumer::ConsumerRetriableCommitFailedError).
2692 ConsumerRetriableCommitFailed(ConsumerRetriableCommitFailedError),
2693 /// See [`ConsumerCommitFailedError`](crate::consumer::ConsumerCommitFailedError).
2694 ConsumerCommitFailed(ConsumerCommitFailedError),
2695 /// See [`ConsumerNoOffsetForPartitionError`](crate::consumer::ConsumerNoOffsetForPartitionError).
2696 ConsumerNoOffsetForPartition(ConsumerNoOffsetForPartitionError),
2697 /// See [`ConsumerOffsetOutOfRangeError`](crate::consumer::ConsumerOffsetOutOfRangeError).
2698 ConsumerOffsetOutOfRange(ConsumerOffsetOutOfRangeError),
2699 /// See [`ConsumerLogTruncationError`](crate::consumer::ConsumerLogTruncationError).
2700 ///
2701 /// Boxed: it carries two maps, and unboxed it made `Error` — and therefore
2702 /// every `Result<_, Error>` in the crate — exceed 128 bytes.
2703 ConsumerLogTruncation(Box<ConsumerLogTruncationError>),
2704 /// See [`ReplicaNotAvailableError`](crate::common::errors::ReplicaNotAvailableError).
2705 ReplicaNotAvailable(ReplicaNotAvailableError),
2706 /// See [`ResourceNotFoundError`](crate::common::errors::ResourceNotFoundError).
2707 ResourceNotFound(ResourceNotFoundError),
2708 /// See [`SaslAuthenticationError`](crate::common::errors::SaslAuthenticationError).
2709 SaslAuthentication(SaslAuthenticationError),
2710 /// See `SchemaError`.
2711 ///
2712 /// Lives in `common.protocol.types`, not `common.errors`.
2713 Schema(SchemaError),
2714 /// See [`SecurityDisabledError`](crate::common::errors::SecurityDisabledError).
2715 SecurityDisabled(SecurityDisabledError),
2716 /// See [`SerializationError`](crate::common::errors::SerializationError).
2717 Serialization(SerializationError),
2718 /// See [`ShareSessionLimitReachedError`](crate::common::errors::ShareSessionLimitReachedError).
2719 ShareSessionLimitReached(ShareSessionLimitReachedError),
2720 /// See [`ShareSessionNotFoundError`](crate::common::errors::ShareSessionNotFoundError).
2721 ShareSessionNotFound(ShareSessionNotFoundError),
2722 /// See [`SnapshotNotFoundError`](crate::common::errors::SnapshotNotFoundError).
2723 SnapshotNotFound(SnapshotNotFoundError),
2724 /// See [`SslAuthenticationError`](crate::common::errors::SslAuthenticationError).
2725 SslAuthentication(SslAuthenticationError),
2726 /// See [`StaleBrokerEpochError`](crate::common::errors::StaleBrokerEpochError).
2727 StaleBrokerEpoch(StaleBrokerEpochError),
2728 /// See [`StaleMemberEpochError`](crate::common::errors::StaleMemberEpochError).
2729 StaleMemberEpoch(StaleMemberEpochError),
2730 /// See [`StreamsInvalidTopologyError`](crate::common::errors::StreamsInvalidTopologyError).
2731 StreamsInvalidTopology(StreamsInvalidTopologyError),
2732 /// See [`StreamsInvalidTopologyEpochError`](crate::common::errors::StreamsInvalidTopologyEpochError).
2733 StreamsInvalidTopologyEpoch(StreamsInvalidTopologyEpochError),
2734 /// See [`StreamsTopologyDescriptionUpdateFailedError`](crate::common::errors::StreamsTopologyDescriptionUpdateFailedError).
2735 StreamsTopologyDescriptionUpdateFailed(StreamsTopologyDescriptionUpdateFailedError),
2736 /// See [`StreamsTopologyFencedError`](crate::common::errors::StreamsTopologyFencedError).
2737 StreamsTopologyFenced(StreamsTopologyFencedError),
2738 /// See [`TelemetryTooLargeError`](crate::common::errors::TelemetryTooLargeError).
2739 TelemetryTooLarge(TelemetryTooLargeError),
2740 /// See [`ThrottlingQuotaExceededError`](crate::common::errors::ThrottlingQuotaExceededError).
2741 ThrottlingQuotaExceeded(ThrottlingQuotaExceededError),
2742 /// See [`TimeoutError`](crate::common::errors::TimeoutError).
2743 Timeout(TimeoutError),
2744 /// See [`TopicAuthorizationError`](crate::common::errors::TopicAuthorizationError).
2745 TopicAuthorization(TopicAuthorizationError),
2746 /// See [`TopicDeletionDisabledError`](crate::common::errors::TopicDeletionDisabledError).
2747 TopicDeletionDisabled(TopicDeletionDisabledError),
2748 /// See [`TopicExistsError`](crate::common::errors::TopicExistsError).
2749 TopicExists(TopicExistsError),
2750 /// See [`TransactionAbortableError`](crate::common::errors::TransactionAbortableError).
2751 TransactionAbortable(TransactionAbortableError),
2752 /// See [`TransactionAbortedError`](crate::common::errors::TransactionAbortedError).
2753 TransactionAborted(TransactionAbortedError),
2754 /// See [`TransactionCoordinatorFencedError`](crate::common::errors::TransactionCoordinatorFencedError).
2755 TransactionCoordinatorFenced(TransactionCoordinatorFencedError),
2756 /// See [`TransactionalIdAuthorizationError`](crate::common::errors::TransactionalIdAuthorizationError).
2757 TransactionalIdAuthorization(TransactionalIdAuthorizationError),
2758 /// See [`TransactionalIdNotFoundError`](crate::common::errors::TransactionalIdNotFoundError).
2759 TransactionalIdNotFound(TransactionalIdNotFoundError),
2760 /// See [`UnacceptableCredentialError`](crate::common::errors::UnacceptableCredentialError).
2761 UnacceptableCredential(UnacceptableCredentialError),
2762 /// See [`UnknownControllerIdError`](crate::common::errors::UnknownControllerIdError).
2763 UnknownControllerId(UnknownControllerIdError),
2764 /// See [`UnknownLeaderEpochError`](crate::common::errors::UnknownLeaderEpochError).
2765 UnknownLeaderEpoch(UnknownLeaderEpochError),
2766 /// See [`UnknownMemberIdError`](crate::common::errors::UnknownMemberIdError).
2767 UnknownMemberId(UnknownMemberIdError),
2768 /// See [`UnknownProducerIdError`](crate::common::errors::UnknownProducerIdError).
2769 UnknownProducerId(UnknownProducerIdError),
2770 /// See [`UnknownServerError`](crate::common::errors::UnknownServerError).
2771 UnknownServer(UnknownServerError),
2772 /// See [`UnknownSubscriptionIdError`](crate::common::errors::UnknownSubscriptionIdError).
2773 UnknownSubscriptionId(UnknownSubscriptionIdError),
2774 /// See [`UnknownTopicIdError`](crate::common::errors::UnknownTopicIdError).
2775 UnknownTopicId(UnknownTopicIdError),
2776 /// See [`UnknownTopicOrPartitionError`](crate::common::errors::UnknownTopicOrPartitionError).
2777 UnknownTopicOrPartition(UnknownTopicOrPartitionError),
2778 /// See [`UnreleasedInstanceIdError`](crate::common::errors::UnreleasedInstanceIdError).
2779 UnreleasedInstanceId(UnreleasedInstanceIdError),
2780 /// See [`UnstableOffsetCommitError`](crate::common::errors::UnstableOffsetCommitError).
2781 UnstableOffsetCommit(UnstableOffsetCommitError),
2782 /// See [`UnsupportedAssignorError`](crate::common::errors::UnsupportedAssignorError).
2783 UnsupportedAssignor(UnsupportedAssignorError),
2784 /// See [`UnsupportedByAuthenticationError`](crate::common::errors::UnsupportedByAuthenticationError).
2785 UnsupportedByAuthentication(UnsupportedByAuthenticationError),
2786 /// See [`UnsupportedCompressionTypeError`](crate::common::errors::UnsupportedCompressionTypeError).
2787 UnsupportedCompressionType(UnsupportedCompressionTypeError),
2788 /// See [`UnsupportedEndpointTypeError`](crate::common::errors::UnsupportedEndpointTypeError).
2789 UnsupportedEndpointType(UnsupportedEndpointTypeError),
2790 /// See [`UnsupportedForMessageFormatError`](crate::common::errors::UnsupportedForMessageFormatError).
2791 UnsupportedForMessageFormat(UnsupportedForMessageFormatError),
2792 /// See [`UnsupportedSaslMechanismError`](crate::common::errors::UnsupportedSaslMechanismError).
2793 UnsupportedSaslMechanism(UnsupportedSaslMechanismError),
2794 /// See [`UnsupportedVersionError`](crate::common::errors::UnsupportedVersionError).
2795 UnsupportedVersion(UnsupportedVersionError),
2796 /// See [`VoterNotFoundError`](crate::common::errors::VoterNotFoundError).
2797 VoterNotFound(VoterNotFoundError),
2798 /// See [`WakeupError`](crate::common::errors::WakeupError).
2799 Wakeup(WakeupError),
2800}
2801
2802impl Error {
2803 // -- Convenience constructors ------------------------------------------
2804
2805 /// Create a bare Kafka error from an error code.
2806 pub(crate) fn new(error: Errors) -> Self {
2807 // Java's `Errors.exception()`: the code names a class, and that class —
2808 // not this enum — knows its ancestry. The fallback covers `Errors::None`,
2809 // which Java maps to a null exception.
2810 error.error().unwrap_or_else(|| Self::KafkaError(KafkaError::new(error)))
2811 }
2812
2813 /// Create a bare Kafka error with a custom message.
2814 pub(crate) fn with_message(error: Errors, message: impl Into<String>) -> Self {
2815 // Java's `Errors.exception(String)`.
2816 let message = message.into();
2817 error
2818 .error_with_message(&message)
2819 .unwrap_or_else(|| Self::KafkaError(KafkaError::with_message(error, message)))
2820 }
2821
2822 /// Creates a bare Kafka error with no message, Java's no-arg `new KafkaException()`.
2823 ///
2824 /// The four `kafka*` constructors translate `KafkaException`'s four constructors.
2825 /// Their parameter-name intersection is empty and the no-arg form matches it, so
2826 /// this one keeps the plain name and the others are suffixed with their parameters.
2827 ///
2828 /// This is deliberately NOT `new` with `Errors::UnknownServerError`: that
2829 /// constructor resolves the code to the class Java associates with it and yields
2830 /// [`UnknownServer`](Self::UnknownServer), an `ApiException`. Java's bare
2831 /// `KafkaException` is a *sibling* of `ApiException`, not a subclass, so it belongs
2832 /// in the [`KafkaError`](Self::KafkaError) variant. The difference is observable:
2833 /// [`is_api_error`](Self::is_api_error) answers `false` here and `true` there, and
2834 /// callers such as `KafkaProducer.doSend` dispatch on exactly that
2835 /// (`catch (ApiException e)` returns a failed future, `catch (KafkaException e)`
2836 /// rethrows).
2837 ///
2838 /// The wire code stays `Errors::UnknownServerError` because a client-constructed
2839 /// `KafkaException` has no protocol code of its own.
2840 ///
2841 /// Java's no-arg form leaves the message null; Rust reports the code's default
2842 /// message instead, since [`KafkaError`] stores the code rather than deriving it
2843 /// from a subclass and always has one to fall back on.
2844 pub fn kafka() -> Self {
2845 Self::KafkaError(KafkaError::new(Errors::UnknownServerError))
2846 }
2847
2848 /// Creates a bare Kafka error, Java's `new KafkaException(String message)`.
2849 ///
2850 /// See [`kafka`](Self::kafka) for why this does not go through `with_message`.
2851 ///
2852 /// # Arguments
2853 ///
2854 /// - `message` - the error message
2855 pub fn kafka_message(message: impl Into<String>) -> Self {
2856 Self::KafkaError(KafkaError::with_message(Errors::UnknownServerError, message))
2857 }
2858
2859 /// Creates a bare Kafka error carrying only the error that caused it, Java's
2860 /// `new KafkaException(Throwable cause)`.
2861 ///
2862 /// See [`kafka`](Self::kafka) for why this does not go through `with_message`.
2863 ///
2864 /// # Arguments
2865 ///
2866 /// - `source` - the error that caused this one, returned by [`source`](Self::source)
2867 pub fn kafka_source(source: Error) -> Self {
2868 Self::KafkaError(KafkaError::with_source(Errors::UnknownServerError, source))
2869 }
2870
2871 /// Creates a bare Kafka error carrying the error that caused it, Java's
2872 /// `new KafkaException(String message, Throwable cause)`.
2873 ///
2874 /// See [`kafka`](Self::kafka) for why this does not go through `with_message`.
2875 ///
2876 /// # Arguments
2877 ///
2878 /// - `message` - the error message
2879 /// - `source` - the error that caused this one, returned by [`source`](Self::source)
2880 pub fn kafka_message_source(message: impl Into<String>, source: Error) -> Self {
2881 Self::KafkaError(KafkaError::with_message_source(Errors::UnknownServerError, message, source))
2882 }
2883
2884 /// Creates a topic authorization error, Java's
2885 /// `new TopicAuthorizationException(unauthorizedTopics)`.
2886 ///
2887 /// The pair intersects on `{unauthorizedTopics}`, which is exactly this overload,
2888 /// so it keeps the plain name.
2889 ///
2890 /// # Arguments
2891 ///
2892 /// - `topics` - the topics the client is not authorized to access
2893 pub fn topic_authorization(topics: HashSet<String>) -> Self {
2894 Self::TopicAuthorization(TopicAuthorizationError::new(topics))
2895 }
2896
2897 /// Creates a topic authorization error carrying a custom message, Java's
2898 /// `new TopicAuthorizationException(message, unauthorizedTopics)`.
2899 ///
2900 /// # Arguments
2901 ///
2902 /// - `topics` - the topics the client is not authorized to access
2903 /// - `message` - the error message
2904 pub fn topic_authorization_message(topics: HashSet<String>, message: impl Into<String>) -> Self {
2905 Self::TopicAuthorization(TopicAuthorizationError::with_message(topics, message))
2906 }
2907
2908 /// Creates an invalid topic error, Java's `new InvalidTopicException(invalidTopics)`.
2909 ///
2910 /// The pair intersects on `{invalidTopics}`, which is exactly this overload, so it
2911 /// keeps the plain name.
2912 ///
2913 /// # Arguments
2914 ///
2915 /// - `topics` - the invalid topic names
2916 pub fn invalid_topics(topics: HashSet<String>) -> Self {
2917 Self::InvalidTopic(InvalidTopicError::new(topics))
2918 }
2919
2920 /// Creates an invalid topic error carrying a custom message, Java's
2921 /// `new InvalidTopicException(message, invalidTopics)`, and the
2922 /// `new InvalidTopicException(String message)` form when `topics` is empty.
2923 ///
2924 /// # Arguments
2925 ///
2926 /// - `topics` - the invalid topic names, possibly empty
2927 /// - `message` - the error message
2928 pub fn invalid_topics_message(topics: HashSet<String>, message: impl Into<String>) -> Self {
2929 Self::InvalidTopic(InvalidTopicError::with_message(topics, message))
2930 }
2931
2932 // The two `group_authorization*` factories below are NOT an overload group:
2933 // the first translates Java's `static forGroupId(String)` and the second the
2934 // `(String message, String groupId)` constructor. Distinct Java members, so
2935 // CLAUDE.md §2's suffixing does not apply and neither name changes.
2936
2937 /// Creates a group authorization error for a group ID, formatting the group into
2938 /// the message, Java's `GroupAuthorizationException.forGroupId(groupId)`.
2939 ///
2940 /// # Arguments
2941 ///
2942 /// - `group_id` - the group the client is not authorized to access
2943 pub fn group_authorization(group_id: impl Into<String>) -> Self {
2944 Self::GroupAuthorization(GroupAuthorizationError::for_group_id(group_id))
2945 }
2946
2947 /// Creates a group authorization error carrying a custom message, Java's
2948 /// `new GroupAuthorizationException(message, groupId)`.
2949 ///
2950 /// # Arguments
2951 ///
2952 /// - `group_id` - the group the client is not authorized to access
2953 /// - `message` - the error message
2954 pub fn group_authorization_with_message(group_id: impl Into<String>, message: impl Into<String>) -> Self {
2955 Self::GroupAuthorization(GroupAuthorizationError::with_group_id(group_id, message))
2956 }
2957
2958 /// Creates an invalid group ID error, Java's `InvalidGroupIdException` (an
2959 /// `ApiException` carrying the code `Errors::InvalidGroupId`).
2960 ///
2961 /// Returned by group-management and offset-commit APIs when the consumer was
2962 /// constructed without a valid `group.id`.
2963 ///
2964 /// # Arguments
2965 ///
2966 /// - `message` - the error message
2967 pub fn invalid_group_id(message: impl Into<String>) -> Self {
2968 Self::InvalidGroupId(InvalidGroupIdError::new(message))
2969 }
2970
2971 /// Creates a throttling quota exceeded error, Java's
2972 /// `ThrottlingQuotaExceededException(int, String)`.
2973 ///
2974 /// # Arguments
2975 ///
2976 /// - `throttle_time_ms` - how long, in milliseconds, the client is throttled
2977 /// - `message` - the error message
2978 pub fn throttling_quota_exceeded(throttle_time_ms: i32, message: impl Into<String>) -> Self {
2979 Self::ThrottlingQuotaExceeded(ThrottlingQuotaExceededError::new(throttle_time_ms, message))
2980 }
2981
2982 /// Returns the throttle time carried by a
2983 /// [`ThrottlingQuotaExceeded`](Self::ThrottlingQuotaExceeded) error, Java's
2984 /// `ThrottlingQuotaExceededException.throttleTimeMs()`, or `None` for any other
2985 /// error.
2986 pub fn throttle_time_ms(&self) -> Option<i32> {
2987 match self {
2988 Self::ThrottlingQuotaExceeded(e) => Some(e.throttle_time_ms),
2989 _ => None,
2990 }
2991 }
2992
2993 /// Creates a buffer exhausted error, Java's `BufferExhaustedException`.
2994 ///
2995 /// # Arguments
2996 ///
2997 /// - `message` - the error message
2998 pub fn buffer_exhausted(message: impl Into<String>) -> Self {
2999 Self::ProducerBufferExhausted(ProducerBufferExhaustedError::new(message))
3000 }
3001
3002 /// Creates an illegal argument error, Java's `IllegalArgumentException`.
3003 ///
3004 /// # Arguments
3005 ///
3006 /// - `message` - the error message
3007 pub fn local_illegal_argument(message: impl Into<String>) -> Self {
3008 Self::LocalIllegalArgument(LocalIllegalArgumentError::new(message))
3009 }
3010
3011 // Java's three `ConfigException` constructors have an empty parameter-name
3012 // intersection and none is no-arg, so no factory below keeps the plain name
3013 // `config` — each takes its full parameter list as the suffix.
3014 // [`ConfigError::new`] is the one exception, and only because it is
3015 // macro-generated; see the note there.
3016
3017 /// Creates a configuration error, Java's `ConfigException(message)`: an invalid
3018 /// config value.
3019 ///
3020 /// Unlike [`local_illegal_argument`](Self::local_illegal_argument) this is inside
3021 /// the `KafkaException` hierarchy, so [`is_kafka_error`](Self::is_kafka_error) is
3022 /// `true` for it.
3023 ///
3024 /// # Arguments
3025 ///
3026 /// - `message` - the error message
3027 pub fn config_message(message: impl Into<String>) -> Self {
3028 Self::Config(ConfigError::new(message))
3029 }
3030
3031 /// Creates a configuration error naming the offending value and key, in Java's
3032 /// `ConfigException(name, value)` format.
3033 ///
3034 /// # Arguments
3035 ///
3036 /// - `name` - the name of the configuration
3037 /// - `value` - the value of the configuration
3038 pub fn config_name_value(name: impl std::fmt::Display, value: impl std::fmt::Display) -> Self {
3039 Self::Config(ConfigError::with_name_value(name, value))
3040 }
3041
3042 /// Creates a configuration error naming the value, key, and a detail message, in
3043 /// Java's `ConfigException(name, value, message)` format.
3044 ///
3045 /// # Arguments
3046 ///
3047 /// - `name` - the name of the configuration
3048 /// - `value` - the value of the configuration
3049 /// - `message` - why the value is invalid
3050 pub fn config_name_value_message(
3051 name: impl std::fmt::Display,
3052 value: impl std::fmt::Display,
3053 message: impl std::fmt::Display,
3054 ) -> Self {
3055 Self::Config(ConfigError::with_name_value_message(name, value, message))
3056 }
3057
3058 /// Creates an illegal state error, Java's `IllegalStateException`.
3059 ///
3060 /// # Arguments
3061 ///
3062 /// - `message` - the error message
3063 pub fn local_illegal_state(message: impl Into<String>) -> Self {
3064 Self::LocalIllegalState(LocalIllegalStateError::new(message))
3065 }
3066
3067 /// Creates an unsupported operation error, Java's
3068 /// `java.lang.UnsupportedOperationException`.
3069 ///
3070 /// Use [`Error::unsupported_version`] instead for
3071 /// `org.apache.kafka.common.errors.UnsupportedVersionException`, the wire-level
3072 /// class for an API version the broker does not support.
3073 ///
3074 /// # Arguments
3075 ///
3076 /// - `message` - the error message
3077 pub fn local_unsupported_operation(message: impl Into<String>) -> Self {
3078 Self::LocalUnsupportedOperation(LocalUnsupportedOperationError::new(message))
3079 }
3080
3081 /// Creates a null pointer error, Java's `java.lang.NullPointerException`.
3082 ///
3083 /// # Arguments
3084 ///
3085 /// - `message` - the error message
3086 pub fn local_null_pointer(message: impl Into<String>) -> Self {
3087 Self::LocalNullPointer(LocalNullPointerError::new(message))
3088 }
3089
3090 /// Creates a timeout error, Java's `org.apache.kafka.common.errors.TimeoutException`.
3091 ///
3092 /// # Arguments
3093 ///
3094 /// - `message` - the error message
3095 pub fn timeout(message: impl Into<String>) -> Self {
3096 Self::Timeout(TimeoutError::new(message))
3097 }
3098
3099 /// Creates a record too large error, Java's `RecordTooLargeException`.
3100 ///
3101 /// # Arguments
3102 ///
3103 /// - `message` - the error message
3104 pub fn record_too_large(message: impl Into<String>) -> Self {
3105 Self::RecordTooLarge(RecordTooLargeError::new(message))
3106 }
3107
3108 /// Creates a correlation-id mismatch error, Java's
3109 /// `CorrelationIdMismatchException(String, int, int)`: an `IllegalStateException`,
3110 /// so outside the `KafkaException` hierarchy.
3111 ///
3112 /// # Arguments
3113 ///
3114 /// - `message` - the error message
3115 /// - `request_correlation_id` - the correlation id of the request sent
3116 /// - `response_correlation_id` - the correlation id the response carried
3117 pub fn correlation_id_mismatch(
3118 message: impl Into<String>,
3119 request_correlation_id: i32,
3120 response_correlation_id: i32,
3121 ) -> Self {
3122 Self::CorrelationIdMismatch(CorrelationIdMismatchError::new(
3123 message,
3124 request_correlation_id,
3125 response_correlation_id,
3126 ))
3127 }
3128
3129 /// Creates an invalid-receive error, Java's `InvalidReceiveException(String)`.
3130 ///
3131 /// The class is not public API (`common.network`), so this constructor is how code
3132 /// outside the crate, such as a test backend decoding an error sent over the wire,
3133 /// builds the variant.
3134 ///
3135 /// # Arguments
3136 ///
3137 /// - `message` - the error message
3138 pub fn invalid_receive(message: impl Into<String>) -> Self {
3139 Self::InvalidReceive(InvalidReceiveError::new(message))
3140 }
3141
3142 /// Creates a protocol-schema error, Java's `SchemaException(String)`.
3143 ///
3144 /// # Arguments
3145 ///
3146 /// - `message` - the error message
3147 pub fn schema(message: impl Into<String>) -> Self {
3148 Self::Schema(SchemaError::new(message))
3149 }
3150
3151 /// Creates a protocol-schema error carrying the failure that caused it, Java's
3152 /// `SchemaException(String, Throwable)`, used by `NetworkClient.parseResponse` to
3153 /// wrap a buffer underflow.
3154 ///
3155 /// The pair intersects on `{message}`, which is exactly [`schema`](Self::schema),
3156 /// so that one keeps the plain name and this is suffixed with the parameter beyond
3157 /// it.
3158 ///
3159 /// # Arguments
3160 ///
3161 /// - `message` - the error message
3162 /// - `source` - the error that caused this one, returned by [`source`](Self::source)
3163 pub fn schema_source(message: impl Into<String>, source: Error) -> Self {
3164 Self::Schema(SchemaError::with_source(message, source))
3165 }
3166
3167 /// Creates a serialization error, Java's `SerializationException`.
3168 ///
3169 /// # Arguments
3170 ///
3171 /// - `message` - the error message
3172 pub fn serialization(message: impl Into<String>) -> Self {
3173 Self::Serialization(SerializationError::new(message))
3174 }
3175
3176 /// Creates an unsupported version error, Java's `UnsupportedVersionException`.
3177 ///
3178 /// # Arguments
3179 ///
3180 /// - `message` - the error message
3181 pub fn unsupported_version(message: impl Into<String>) -> Self {
3182 Self::UnsupportedVersion(UnsupportedVersionError::new(message))
3183 }
3184
3185 /// Creates a wakeup error, Java's `WakeupException`.
3186 ///
3187 /// Returned from blocking `Consumer` operations (`poll`, `commit_sync`, `position`,
3188 /// etc.) when `wakeup()` is invoked from another task.
3189 ///
3190 /// # Arguments
3191 ///
3192 /// - `message` - the error message
3193 pub fn wakeup(message: impl Into<String>) -> Self {
3194 Self::Wakeup(WakeupError::new(message))
3195 }
3196
3197 /// Creates a concurrent modification error, Java's `ConcurrentModificationException`,
3198 /// which `KafkaConsumer.acquire()` throws when the consumer is accessed from more
3199 /// than one thread.
3200 ///
3201 /// # Arguments
3202 ///
3203 /// - `message` - the error message
3204 pub fn local_concurrent_modification(message: impl Into<String>) -> Self {
3205 Self::LocalConcurrentModification(LocalConcurrentModificationError::new(message))
3206 }
3207
3208 /// Creates a timed-out-waiting-on-a-future error, Java's
3209 /// `java.util.concurrent.TimeoutException` from `Future.get(timeout, unit)`.
3210 ///
3211 /// Use [`Error::timeout`] instead for
3212 /// `org.apache.kafka.common.errors.TimeoutException`, the retriable Kafka class the
3213 /// broker reports.
3214 ///
3215 /// # Arguments
3216 ///
3217 /// - `message` - the error message
3218 pub fn local_timeout(message: impl Into<String>) -> Self {
3219 Self::LocalTimeout(LocalTimeoutError::new(message))
3220 }
3221
3222 /// Creates the error a callback written in another language reports when it raised
3223 /// one of that language's errors. See [`LocalCallbackError`].
3224 ///
3225 /// # Arguments
3226 ///
3227 /// - `message` - the foreign error's text, for the client's logs
3228 /// - `opaque` - the binding's pointer to the foreign error, never dereferenced by
3229 /// Rust and not owned by the error
3230 pub fn local_callback(message: impl Into<String>, opaque: *mut c_void) -> Self {
3231 Self::LocalCallback(LocalCallbackError::new(message, opaque))
3232 }
3233
3234 /// As [`local_callback`](Self::local_callback), but the error owns
3235 /// `opaque`: `release(opaque)` runs exactly once, when the last copy of the
3236 /// error drops, on whatever task or thread drops it. The FFI's
3237 /// `kafka_common_Error_local_callback` builds it when given a release
3238 /// function.
3239 ///
3240 /// # Safety
3241 ///
3242 /// `release` must be sound to call once with `opaque`, from any thread, at
3243 /// any time until the process exits.
3244 #[cfg_attr(not(any(feature = "ffi", test)), expect(dead_code))]
3245 pub(crate) unsafe fn local_callback_with_release(
3246 message: impl Into<String>,
3247 opaque: *mut c_void,
3248 release: crate::common::local_callback_error::ReleaseFn,
3249 ) -> Self {
3250 // SAFETY: forwarded: per this function's `# Safety`, `release` is sound to call once
3251 // with `opaque`, from any thread, at any time, as `with_release` requires.
3252 Self::LocalCallback(unsafe { LocalCallbackError::with_release(message, opaque, release) })
3253 }
3254
3255 /// Creates a transaction aborted error with Java's default message, Java's no-arg
3256 /// `TransactionAbortedException()`, whose message is
3257 /// `"Failing batch since transaction was aborted"`.
3258 ///
3259 /// The pair's parameter-name intersection is empty and this overload matches it,
3260 /// so it keeps the plain name.
3261 pub fn transaction_aborted() -> Self {
3262 Self::TransactionAborted(TransactionAbortedError::new("Failing batch since transaction was aborted"))
3263 }
3264
3265 /// Creates a transaction aborted error with a custom message, Java's
3266 /// `TransactionAbortedException(String)`.
3267 ///
3268 /// # Arguments
3269 ///
3270 /// - `message` - the error message
3271 pub fn transaction_aborted_message(message: impl Into<String>) -> Self {
3272 Self::TransactionAborted(TransactionAbortedError::new(message))
3273 }
3274
3275 /// Creates a record batch too large error, Java's `RecordBatchTooLargeException`.
3276 ///
3277 /// # Arguments
3278 ///
3279 /// - `message` - the error message
3280 pub fn record_batch_too_large(message: impl Into<String>) -> Self {
3281 Self::RecordBatchTooLarge(RecordBatchTooLargeError::new(message))
3282 }
3283
3284 // -- Base access -------------------------------------------------------
3285
3286 /// Returns the base [`KafkaError`] common to all variants, or `None` for variants
3287 /// that do not carry one (e.g. [`LocalIllegalArgument`](Self::LocalIllegalArgument),
3288 /// [`LocalIllegalState`](Self::LocalIllegalState)).
3289 pub fn kafka_error(&self) -> Option<&KafkaError> {
3290 match self {
3291 Self::KafkaError(e) => Some(e),
3292 // The only other payloads that embed one: Java gives these three
3293 // subclass state on top of the base, so they compose rather than
3294 // being declared by `kafka_error_type!`.
3295 Self::TopicAuthorization(e) => Some(e.kafka_error()),
3296 Self::InvalidTopic(e) => Some(e.kafka_error()),
3297 Self::GroupAuthorization(e) => Some(e.kafka_error()),
3298 // Every other variant is a `kafka_error_type!` declaration holding
3299 // only its message; it answers its code through [`ErrorCode`] and
3300 // its ancestry through [`ErrorHierarchy`], with no base to expose.
3301 // A catch-all is safe here precisely because there is nothing
3302 // variant-specific left to get wrong — unlike `message()`, which is
3303 // delegated so that a new payload must state its own answer.
3304 _ => None,
3305 }
3306 }
3307
3308 // -- Delegating methods ------------------------------------------------
3309
3310 /// The protocol error code.
3311 ///
3312 /// Returns [`Errors::UnknownServerError`] for variants without a
3313 /// [`KafkaError`].
3314 pub(crate) fn error(&self) -> Errors {
3315 // Delegated to the payload: Java associates a code with an exception
3316 // *class* (`Errors.forException`), not with an instance.
3317 ErrorCode::error(self)
3318 }
3319
3320 /// Returns the error message, Java's `Throwable.getMessage()`.
3321 ///
3322 /// A message-only error returns the text it was constructed with, and a payload
3323 /// wrapping a [`KafkaError`] returns its custom message if set, otherwise the
3324 /// default text for its error code.
3325 ///
3326 /// This is NOT what `to_string()` produces. [`std::fmt::Display`] translates
3327 /// `Throwable.toString()`, which Java renders as
3328 /// `getClass().getName() + ": " + getLocalizedMessage()`, so `Display` carries a
3329 /// class-name prefix and, for some payloads, extra subclass state. Use this method
3330 /// for log fields and equality assertions; use `Display` when rendering the error
3331 /// to a human.
3332 pub fn message(&self) -> &str {
3333 // UFCS: `self.message()` would resolve to this inherent method and recurse.
3334 ErrorMessage::message(self)
3335 }
3336
3337 /// Returns the error that caused this one, Java's `Throwable.getCause()`, or
3338 /// `None` when there is none.
3339 ///
3340 /// `getCause()` lives on `Throwable`, so every error can carry a cause: this
3341 /// answers for all of them. `None` is the common case, as Java's null default.
3342 ///
3343 /// [`std::error::Error::source`] returns the same value, so the standard library's
3344 /// chain-walking works on any [`Error`].
3345 pub fn source(&self) -> Option<&Error> {
3346 // UFCS: `self.source()` would resolve to this inherent method and recurse.
3347 ErrorSource::source(self)
3348 }
3349
3350 // -- Hierarchy predicates ----------------------------------------------
3351 //
3352 // Java's exception hierarchy is flattened into this enum, so each
3353 // intermediate class becomes a predicate. The answers
3354 // come from the variant's payload via `ErrorHierarchy`, which is crate
3355 // -internal; these forwarders are the public surface.
3356 //
3357 // Each MUST call the trait method through UFCS. `self.is_x()` inside
3358 // `Error::is_x` resolves back to this inherent method — inherent beats
3359 // trait — and recurses forever at run time while compiling cleanly.
3360
3361 /// Returns whether this is a Kafka error rather than a generic programming error.
3362 ///
3363 /// This enum flattens two families that Java keeps apart by class
3364 /// hierarchy: Kafka's own `KafkaException` tree, and the generic
3365 /// `java.lang` / `java.util` runtime exceptions that sit beside it as
3366 /// siblings rather than below it (`KafkaException` extends `RuntimeException`). This
3367 /// predicate recovers that distinction, mirroring Java's
3368 /// `t instanceof KafkaException`.
3369 ///
3370 /// Returns `false` for exactly the generic variants — the ones raised by
3371 /// misuse of the client rather than by Kafka itself:
3372 /// [`LocalIllegalArgument`](Self::LocalIllegalArgument),
3373 /// [`LocalIllegalState`](Self::LocalIllegalState),
3374 /// [`LocalConcurrentModification`](Self::LocalConcurrentModification),
3375 /// [`LocalTimeout`](Self::LocalTimeout),
3376 /// [`LocalUnsupportedOperation`](Self::LocalUnsupportedOperation) and
3377 /// [`LocalNullPointer`](Self::LocalNullPointer), plus
3378 /// [`LocalCallback`](Self::LocalCallback), a foreign callback's error, which
3379 /// the client wraps as Java wraps a listener's foreign `Throwable`.
3380 ///
3381 /// Everything else returns `true`: the `ApiException` subtypes,
3382 /// [`Serialization`](Self::Serialization), [`Wakeup`](Self::Wakeup) and the
3383 /// bare [`KafkaError`](Self::KafkaError) all map to `KafkaException`
3384 /// subclasses.
3385 ///
3386 /// **This is not a test for the [`KafkaError`](Self::KafkaError) variant.**
3387 /// That variant means "a bare `KafkaException`, no subclass"; this asks
3388 /// "inside the `KafkaException` hierarchy at all", which is true of
3389 /// `Timeout`, `TopicAuthorization` and most other variants too. Java has no
3390 /// `instanceof` test for "a bare `KafkaException` and no subclass" either.
3391 ///
3392 /// Beware the polarity difference against [`is_api_error`](Self::is_api_error):
3393 /// both return `true` for the in-hierarchy case, but they are not the same
3394 /// test — `Serialization` and `Wakeup` are Kafka errors that are NOT
3395 /// `ApiException`s, so they return `true` here and `false` there.
3396 ///
3397 /// Two call sites depend on this:
3398 /// `org.apache.kafka.clients.consumer.internals.ConsumerUtils#maybeWrapAsKafkaException`
3399 /// — a Kafka error passes through unchanged, a
3400 /// generic one gets wrapped in a new `KafkaException(message, t)` — and
3401 /// `FetchCollector`, whose Java `catch (KafkaException e)` cannot catch a
3402 /// generic error, so those propagate where Kafka errors are swallowed.
3403 pub fn is_kafka_error(&self) -> bool {
3404 ErrorHierarchy::is_kafka_error(self)
3405 }
3406
3407 /// Returns whether this error's Java class is `ApiException` or extends it.
3408 ///
3409 /// In Java, `ApiException` is a subclass of `KafkaException` representing
3410 /// errors from the Kafka API. In `KafkaProducer.doSend()`, `ApiException`s
3411 /// are caught and returned via a failed future (with callback invocation),
3412 /// while other exceptions propagate directly.
3413 ///
3414 /// `true` for every payload whose `extends:` list names `is_api_error` —
3415 /// which is every class carrying a protocol code, since `Errors.java` only
3416 /// names `ApiException` subclasses, plus the code-less concrete bases
3417 /// [`Api`](Self::Api), [`Authentication`](Self::Authentication) and
3418 /// [`Authorization`](Self::Authorization). Examples:
3419 /// [`InvalidTopic`](Self::InvalidTopic),
3420 /// [`RecordTooLarge`](Self::RecordTooLarge), [`Timeout`](Self::Timeout),
3421 /// [`TopicAuthorization`](Self::TopicAuthorization),
3422 /// [`GroupAuthorization`](Self::GroupAuthorization),
3423 /// [`ThrottlingQuotaExceeded`](Self::ThrottlingQuotaExceeded) and
3424 /// [`ProducerBufferExhausted`](Self::ProducerBufferExhausted).
3425 ///
3426 /// `false` for the bare [`KafkaError`](Self::KafkaError) — `KafkaException`
3427 /// is `ApiException`'s *parent*, not an instance of it, and since
3428 /// `Error::new` resolves every code to its own class that variant is now
3429 /// reached only for `Errors::None` and for
3430 /// [`Error::kafka`](Self::kafka). Also `false` for
3431 /// [`LocalIllegalArgument`](Self::LocalIllegalArgument) and
3432 /// [`LocalIllegalState`](Self::LocalIllegalState) (plain `RuntimeException`s),
3433 /// [`LocalConcurrentModification`](Self::LocalConcurrentModification), and for
3434 /// [`Serialization`](Self::Serialization) / [`Wakeup`](Self::Wakeup), which
3435 /// extend `KafkaException` directly without passing through `ApiException`.
3436 ///
3437 /// Not to be confused with [`is_kafka_error`](Self::is_kafka_error), which
3438 /// asks the broader question.
3439 pub fn is_api_error(&self) -> bool {
3440 ErrorHierarchy::is_api_error(self)
3441 }
3442
3443 /// Returns whether this error's Java class extends `RetriableException` — i.e. whether
3444 /// re-sending the failed request can succeed.
3445 ///
3446 /// The answer belongs to the payload, not to the enum: each error class
3447 /// names `is_retriable_error` in its `extends:` list, so the covered set is
3448 /// exactly the classes whose Java ancestry passes through
3449 /// `RetriableException` — directly, or via `RefreshRetriableException`,
3450 /// `InvalidMetadataException` or `TimeoutException`. [`Timeout`](Self::Timeout)
3451 /// is retriable (Java's `TimeoutException` extends `RetriableException`), as
3452 /// are [`ThrottlingQuotaExceeded`](Self::ThrottlingQuotaExceeded) and
3453 /// [`ProducerBufferExhausted`](Self::ProducerBufferExhausted) (through
3454 /// `BufferExhaustedException extends TimeoutException`).
3455 ///
3456 /// Since `Error::new` resolves every code to its own class, the set of
3457 /// *codes* answering `true` is pinned in both directions — against the Java
3458 /// `extends` chain, over every code — by `errors.rs`'s
3459 /// `test_retriable_errors_match_java_hierarchy`.
3460 ///
3461 /// The bare [`KafkaError`](Self::KafkaError) answers `false`
3462 /// (`KafkaException` is not a `RetriableException`), and so do
3463 /// [`LocalIllegalArgument`](Self::LocalIllegalArgument) and
3464 /// [`LocalIllegalState`](Self::LocalIllegalState).
3465 pub fn is_retriable_error(&self) -> bool {
3466 ErrorHierarchy::is_retriable_error(self)
3467 }
3468
3469 /// Returns whether this error's Java class extends `RefreshRetriableException` — retriable, and
3470 /// a metadata / coordinator refresh is what clears it.
3471 ///
3472 /// Fifteen payloads name it in their `extends:` list: the thirteen that also
3473 /// answer [`is_invalid_metadata_error`](Self::is_invalid_metadata_error)
3474 /// (`InvalidMetadataException extends RefreshRetriableException`), plus
3475 /// [`CoordinatorNotAvailable`](Self::CoordinatorNotAvailable) and
3476 /// [`NotCoordinator`](Self::NotCoordinator). All fifteen carry a protocol
3477 /// code, so the set is pinned in both directions over every code by
3478 /// `errors.rs`'s `test_hierarchy_predicates_match_java`.
3479 ///
3480 /// The bare [`KafkaError`](Self::KafkaError) answers `false`, as do the
3481 /// payloads carrying no protocol code.
3482 pub fn is_refresh_retriable_error(&self) -> bool {
3483 ErrorHierarchy::is_refresh_retriable_error(self)
3484 }
3485
3486 /// Returns whether this error's Java class extends `TimeoutException`.
3487 ///
3488 /// Wider than the [`Timeout`](Self::Timeout) variant:
3489 /// `BufferExhaustedException extends TimeoutException`, so
3490 /// [`ProducerBufferExhausted`](Self::ProducerBufferExhausted) answers `true`
3491 /// here too — matching Java, where `catch (TimeoutException e)` catches a
3492 /// buffer-pool exhaustion. To exclude that case, as a Java caller would with
3493 /// a preceding `catch (BufferExhaustedException e)`, also test
3494 /// [`is_producer_buffer_exhausted_error`](Self::is_producer_buffer_exhausted_error).
3495 ///
3496 /// Nested inside [`is_retriable_error`](Self::is_retriable_error).
3497 pub fn is_timeout_error(&self) -> bool {
3498 ErrorHierarchy::is_timeout_error(self)
3499 }
3500
3501 /// Returns whether this error's Java class extends `InvalidMetadataException` — the client's
3502 /// cached metadata may be stale.
3503 ///
3504 /// Nested inside [`is_refresh_retriable_error`](Self::is_refresh_retriable_error),
3505 /// which is nested inside [`is_retriable_error`](Self::is_retriable_error).
3506 /// Thirteen payloads name it, all of them code-carrying; the set is pinned in
3507 /// both directions over every code by `errors.rs`'s
3508 /// `test_hierarchy_predicates_match_java`.
3509 pub fn is_invalid_metadata_error(&self) -> bool {
3510 ErrorHierarchy::is_invalid_metadata_error(self)
3511 }
3512
3513 /// Returns whether this error's Java class extends `InvalidConfigurationException`.
3514 ///
3515 /// Wider than its name suggests: in Kafka 4.2 **both**
3516 /// `AuthenticationException` and `AuthorizationException` extend
3517 /// `InvalidConfigurationException` rather than `ApiException` directly, so
3518 /// every error answering `true` to
3519 /// [`is_authentication_error`](Self::is_authentication_error) or
3520 /// [`is_authorization_error`](Self::is_authorization_error) answers `true`
3521 /// here too. The remaining members are the configuration errors proper —
3522 /// `Errors::InvalidConfig`, `Errors::InvalidReplicationFactor`,
3523 /// `Errors::InvalidRequiredAcks`, `Errors::InvalidTopicError`,
3524 /// `Errors::RecordListTooLarge`, `Errors::UnsupportedForMessageFormat`
3525 /// and `Errors::UnsupportedVersion`.
3526 pub fn is_invalid_configuration_error(&self) -> bool {
3527 ErrorHierarchy::is_invalid_configuration_error(self)
3528 }
3529
3530 /// Returns whether this error's Java class extends `ApplicationRecoverableException` — the
3531 /// application can recover, but only by re-initialising its producer or rejoining its group;
3532 /// the current epoch or session is gone.
3533 ///
3534 /// 6 codes, covering the transaction and group-membership fencing paths:
3535 /// `Errors::FencedInstanceId`, `Errors::IllegalGeneration`,
3536 /// `Errors::InvalidProducerEpoch`, `Errors::InvalidProducerIdMapping`,
3537 /// `Errors::ProducerFenced` and `Errors::UnknownMemberId`.
3538 pub fn is_application_recoverable_error(&self) -> bool {
3539 ErrorHierarchy::is_application_recoverable_error(self)
3540 }
3541
3542 /// Returns whether this error's Java class extends `InvalidOffsetException`.
3543 ///
3544 /// `Errors::OffsetOutOfRange` is the only member carrying a protocol code;
3545 /// the sibling `NoOffsetForPartitionException` is raised client-side.
3546 pub fn is_invalid_offset_error(&self) -> bool {
3547 ErrorHierarchy::is_invalid_offset_error(self)
3548 }
3549
3550 /// Returns whether this error's Java class extends `OutOfOrderSequenceException`.
3551 ///
3552 /// Two codes: `Errors::OutOfOrderSequenceNumber` itself and
3553 /// `Errors::UnknownProducerId`, its only subclass.
3554 pub fn is_out_of_order_sequence_error(&self) -> bool {
3555 ErrorHierarchy::is_out_of_order_sequence_error(self)
3556 }
3557
3558 /// Returns whether this error's Java class extends
3559 /// `org.apache.kafka.clients.consumer.InvalidOffsetException` — no offset is usable for the
3560 /// partition.
3561 ///
3562 /// Covers
3563 /// [`ConsumerNoOffsetForPartition`](Self::ConsumerNoOffsetForPartition),
3564 /// [`ConsumerOffsetOutOfRange`](Self::ConsumerOffsetOutOfRange) and
3565 /// [`ConsumerLogTruncation`](Self::ConsumerLogTruncation) — the `Consumer`
3566 /// prefix marks the `clients.consumer` package's classes, so it is part of
3567 /// the variant name.
3568 ///
3569 /// Distinct from [`is_invalid_offset_error`](Self::is_invalid_offset_error),
3570 /// which tests `common.errors.InvalidOffsetException` — a different Java
3571 /// class with a different parent (`ApiException` rather than
3572 /// `KafkaException`). The wire code `OFFSET_OUT_OF_RANGE` produces that one;
3573 /// `KafkaConsumer::poll` raises these.
3574 pub fn is_consumer_invalid_offset_error(&self) -> bool {
3575 ErrorHierarchy::is_consumer_invalid_offset_error(self)
3576 }
3577
3578 /// Returns whether this error's Java class extends
3579 /// `org.apache.kafka.clients.consumer.OffsetOutOfRangeException`.
3580 ///
3581 /// Wider than the [`ConsumerOffsetOutOfRange`](Self::ConsumerOffsetOutOfRange)
3582 /// variant: `LogTruncationException` extends that class, so
3583 /// [`ConsumerLogTruncation`](Self::ConsumerLogTruncation) answers `true` too
3584 /// — matching Java, where `catch (OffsetOutOfRangeException e)` catches a
3585 /// log truncation.
3586 ///
3587 /// Nested inside
3588 /// [`is_consumer_invalid_offset_error`](Self::is_consumer_invalid_offset_error).
3589 /// Distinct from [`is_invalid_offset_error`](Self::is_invalid_offset_error),
3590 /// which tests the `common.errors` class of the same name.
3591 pub fn is_consumer_offset_out_of_range_error(&self) -> bool {
3592 ErrorHierarchy::is_consumer_offset_out_of_range_error(self)
3593 }
3594
3595 /// Returns whether this error's Java class extends `SerializationException`.
3596 ///
3597 /// No protocol code maps here — `SerializationException` and its subclass
3598 /// `RecordDeserializationException` are raised client-side — so only
3599 /// [`Serialization`](Self::Serialization) answers `true`. Note it is a
3600 /// `KafkaException` but NOT an `ApiException`, so
3601 /// [`is_api_error`](Self::is_api_error) is `false` for it.
3602 pub fn is_serialization_error(&self) -> bool {
3603 ErrorHierarchy::is_serialization_error(self)
3604 }
3605
3606 /// Returns whether this error's Java class extends `AuthenticationException`.
3607 ///
3608 /// Five payloads name it in their `extends:` list:
3609 /// [`Authentication`](Self::Authentication) — the concrete base class, which
3610 /// has no entry in `Errors` of its own but inherits
3611 /// `Errors::InvalidConfig` from `InvalidConfigurationException` — plus
3612 /// [`SaslAuthentication`](Self::SaslAuthentication),
3613 /// [`SslAuthentication`](Self::SslAuthentication),
3614 /// [`IllegalSaslState`](Self::IllegalSaslState) and
3615 /// [`UnsupportedSaslMechanism`](Self::UnsupportedSaslMechanism). Three of
3616 /// them carry a code (`SASL_AUTHENTICATION_FAILED`, `ILLEGAL_SASL_STATE`,
3617 /// `UNSUPPORTED_SASL_MECHANISM`) and that code set is pinned in both
3618 /// directions over every code by `errors.rs`'s
3619 /// `test_hierarchy_predicates_match_java`.
3620 ///
3621 /// A handshake failure detected locally is carried inside an `io::Error`
3622 /// (`common::network::authentication_io_error`) as the class it was raised
3623 /// as — [`SaslAuthentication`](Self::SaslAuthentication) for rejected
3624 /// credentials, [`SslAuthentication`](Self::SslAuthentication) for a rejected
3625 /// certificate — and reaches the application, and the producer's transaction
3626 /// manager, unchanged; each answers `true` here, and so to
3627 /// `request_utils::RequestUtils::is_fatal_error`.
3628 ///
3629 /// Nested inside
3630 /// [`is_invalid_configuration_error`](Self::is_invalid_configuration_error).
3631 pub fn is_authentication_error(&self) -> bool {
3632 ErrorHierarchy::is_authentication_error(self)
3633 }
3634
3635 /// Returns whether this error's Java class extends `AuthorizationException`.
3636 ///
3637 /// Six payloads name it in their `extends:` list:
3638 /// [`Authorization`](Self::Authorization) — the concrete base class, which
3639 /// has no entry in `Errors` of its own but inherits
3640 /// `Errors::InvalidConfig` from `InvalidConfigurationException` — plus the five
3641 /// that do carry one,
3642 /// [`TopicAuthorization`](Self::TopicAuthorization),
3643 /// [`GroupAuthorization`](Self::GroupAuthorization),
3644 /// [`ClusterAuthorization`](Self::ClusterAuthorization),
3645 /// [`TransactionalIdAuthorization`](Self::TransactionalIdAuthorization) and
3646 /// [`DelegationTokenAuthorization`](Self::DelegationTokenAuthorization).
3647 /// Those five codes are pinned in both directions over every code by
3648 /// `errors.rs`'s `test_hierarchy_predicates_match_java`; the bare
3649 /// [`KafkaError`](Self::KafkaError) answers `false`.
3650 ///
3651 /// Nested inside
3652 /// [`is_invalid_configuration_error`](Self::is_invalid_configuration_error).
3653 pub fn is_authorization_error(&self) -> bool {
3654 ErrorHierarchy::is_authorization_error(self)
3655 }
3656
3657 // -- Class predicates ------------------------------------------------
3658 //
3659 // One per variant, mirroring `ErrorHierarchy`'s class predicates: use these
3660 // instead of matching on a variant, so that a subclass a later Java release
3661 // adds — a new variant — still answers `true`.
3662
3663 /// Returns whether this error's Java class is, or extends,
3664 /// `java.lang.IllegalArgumentException`.
3665 ///
3666 /// Prefer this to matching [`Error::LocalIllegalArgument`](Self::LocalIllegalArgument): a
3667 /// variant match misses the subclasses a later Java release may add.
3668 pub fn is_local_illegal_argument_error(&self) -> bool {
3669 ErrorHierarchy::is_local_illegal_argument_error(self)
3670 }
3671
3672 /// Returns whether this error's Java class is, or extends, `java.lang.IllegalStateException`.
3673 ///
3674 /// Prefer this to matching [`Error::LocalIllegalState`](Self::LocalIllegalState): a variant
3675 /// match misses the subclasses a later Java release may add.
3676 pub fn is_local_illegal_state_error(&self) -> bool {
3677 ErrorHierarchy::is_local_illegal_state_error(self)
3678 }
3679
3680 /// Returns whether this error's Java class is, or extends,
3681 /// `java.util.ConcurrentModificationException`.
3682 ///
3683 /// Prefer this to matching
3684 /// [`Error::LocalConcurrentModification`](Self::LocalConcurrentModification): a variant match
3685 /// misses the subclasses a later Java release may add.
3686 pub fn is_local_concurrent_modification_error(&self) -> bool {
3687 ErrorHierarchy::is_local_concurrent_modification_error(self)
3688 }
3689
3690 /// Returns whether this error's Java class is, or extends,
3691 /// `java.util.concurrent.TimeoutException`.
3692 ///
3693 /// Prefer this to matching [`Error::LocalTimeout`](Self::LocalTimeout): a variant match misses
3694 /// the subclasses a later Java release may add.
3695 pub fn is_local_timeout_error(&self) -> bool {
3696 ErrorHierarchy::is_local_timeout_error(self)
3697 }
3698
3699 /// Returns whether this error's Java class is, or extends,
3700 /// `java.lang.UnsupportedOperationException`.
3701 ///
3702 /// Covers exactly [`Error::LocalUnsupportedOperation`](Self::LocalUnsupportedOperation), a
3703 /// plain `RuntimeException` beside `KafkaException`: it answers `false` to
3704 /// [`is_kafka_error`](Self::is_kafka_error), [`is_api_error`](Self::is_api_error) and
3705 /// [`is_retriable_error`](Self::is_retriable_error), and, unlike
3706 /// [`is_unsupported_version_error`](Self::is_unsupported_version_error) (the wire-level
3707 /// `UnsupportedVersionException`), it is not fatal.
3708 ///
3709 /// Prefer this to matching
3710 /// [`Error::LocalUnsupportedOperation`](Self::LocalUnsupportedOperation): a variant match
3711 /// misses the subclasses a later Java release may add.
3712 pub fn is_local_unsupported_operation_error(&self) -> bool {
3713 ErrorHierarchy::is_local_unsupported_operation_error(self)
3714 }
3715
3716 /// Returns whether this error's Java class is, or extends,
3717 /// `java.lang.NullPointerException`.
3718 ///
3719 /// Covers exactly [`Error::LocalNullPointer`](Self::LocalNullPointer), a plain
3720 /// `RuntimeException` beside `KafkaException`: it answers `false` to
3721 /// [`is_kafka_error`](Self::is_kafka_error), [`is_api_error`](Self::is_api_error) and
3722 /// [`is_retriable_error`](Self::is_retriable_error).
3723 ///
3724 /// Prefer this to matching [`Error::LocalNullPointer`](Self::LocalNullPointer): a variant
3725 /// match misses the subclasses a later Java release may add.
3726 pub fn is_local_null_pointer_error(&self) -> bool {
3727 ErrorHierarchy::is_local_null_pointer_error(self)
3728 }
3729
3730 /// Returns whether this is an error raised by a callback written in another language
3731 /// ([`Error::LocalCallback`](Self::LocalCallback); no Java class).
3732 ///
3733 /// Covers exactly that variant. Like the `java.lang` runtime errors it is
3734 /// outside the Kafka hierarchy: [`is_kafka_error`](Self::is_kafka_error) and
3735 /// every other predicate answer `false` for it.
3736 pub fn is_local_callback_error(&self) -> bool {
3737 ErrorHierarchy::is_local_callback_error(self)
3738 }
3739
3740 /// Returns whether this error's Java class is, or extends,
3741 /// `org.apache.kafka.common.errors.AuthorizerNotReadyException`.
3742 ///
3743 /// Prefer this to matching [`Error::AuthorizerNotReady`](Self::AuthorizerNotReady): a variant
3744 /// match misses the subclasses a later Java release may add.
3745 pub fn is_authorizer_not_ready_error(&self) -> bool {
3746 ErrorHierarchy::is_authorizer_not_ready_error(self)
3747 }
3748
3749 /// Returns whether this error's Java class is, or extends,
3750 /// `org.apache.kafka.common.errors.BootstrapResolutionException`.
3751 ///
3752 /// Prefer this to matching [`Error::BootstrapResolution`](Self::BootstrapResolution): a variant
3753 /// match misses the subclasses a later Java release may add.
3754 pub fn is_bootstrap_resolution_error(&self) -> bool {
3755 ErrorHierarchy::is_bootstrap_resolution_error(self)
3756 }
3757
3758 /// Returns whether this error's Java class is, or extends,
3759 /// `org.apache.kafka.common.errors.BrokerIdNotRegisteredException`.
3760 ///
3761 /// Prefer this to matching [`Error::BrokerIdNotRegistered`](Self::BrokerIdNotRegistered): a
3762 /// variant match misses the subclasses a later Java release may add.
3763 pub fn is_broker_id_not_registered_error(&self) -> bool {
3764 ErrorHierarchy::is_broker_id_not_registered_error(self)
3765 }
3766
3767 /// Returns whether this error's Java class is, or extends,
3768 /// `org.apache.kafka.common.errors.BrokerNotAvailableException`.
3769 ///
3770 /// Prefer this to matching [`Error::BrokerNotAvailable`](Self::BrokerNotAvailable): a variant
3771 /// match misses the subclasses a later Java release may add.
3772 pub fn is_broker_not_available_error(&self) -> bool {
3773 ErrorHierarchy::is_broker_not_available_error(self)
3774 }
3775
3776 /// Returns whether this error's Java class is, or extends,
3777 /// `org.apache.kafka.clients.producer.BufferExhaustedException`.
3778 ///
3779 /// Prefer this to matching [`Error::ProducerBufferExhausted`](Self::ProducerBufferExhausted): a
3780 /// variant match misses the subclasses a later Java release may add.
3781 pub fn is_producer_buffer_exhausted_error(&self) -> bool {
3782 ErrorHierarchy::is_producer_buffer_exhausted_error(self)
3783 }
3784
3785 /// Returns whether this error's Java class is, or extends,
3786 /// `org.apache.kafka.common.errors.ClusterAuthorizationException`.
3787 ///
3788 /// Prefer this to matching [`Error::ClusterAuthorization`](Self::ClusterAuthorization): a
3789 /// variant match misses the subclasses a later Java release may add.
3790 pub fn is_cluster_authorization_error(&self) -> bool {
3791 ErrorHierarchy::is_cluster_authorization_error(self)
3792 }
3793
3794 /// Returns whether this error's Java class is, or extends,
3795 /// `org.apache.kafka.common.errors.ConcurrentTransactionsException`.
3796 ///
3797 /// Prefer this to matching [`Error::ConcurrentTransactions`](Self::ConcurrentTransactions): a
3798 /// variant match misses the subclasses a later Java release may add.
3799 pub fn is_concurrent_transactions_error(&self) -> bool {
3800 ErrorHierarchy::is_concurrent_transactions_error(self)
3801 }
3802
3803 /// Returns whether this error's Java class is, or extends,
3804 /// `org.apache.kafka.common.errors.ControllerIdNotRegisteredException`.
3805 ///
3806 /// Prefer this to matching [`Error::ControllerIdNotRegistered`](Self::ControllerIdNotRegistered): a variant
3807 /// match misses the subclasses a later Java release may add.
3808 pub fn is_controller_id_not_registered_error(&self) -> bool {
3809 ErrorHierarchy::is_controller_id_not_registered_error(self)
3810 }
3811
3812 /// Returns whether this error's Java class is, or extends,
3813 /// `org.apache.kafka.common.errors.ControllerMovedException`.
3814 ///
3815 /// Prefer this to matching [`Error::ControllerMoved`](Self::ControllerMoved): a variant match
3816 /// misses the subclasses a later Java release may add.
3817 pub fn is_controller_moved_error(&self) -> bool {
3818 ErrorHierarchy::is_controller_moved_error(self)
3819 }
3820
3821 /// Returns whether this error's Java class is, or extends,
3822 /// `org.apache.kafka.common.errors.CoordinatorLoadInProgressException`.
3823 ///
3824 /// Prefer this to matching
3825 /// [`Error::CoordinatorLoadInProgress`](Self::CoordinatorLoadInProgress): a variant match
3826 /// misses the subclasses a later Java release may add.
3827 pub fn is_coordinator_load_in_progress_error(&self) -> bool {
3828 ErrorHierarchy::is_coordinator_load_in_progress_error(self)
3829 }
3830
3831 /// Returns whether this error's Java class is, or extends,
3832 /// `org.apache.kafka.common.errors.CoordinatorNotAvailableException`.
3833 ///
3834 /// Prefer this to matching [`Error::CoordinatorNotAvailable`](Self::CoordinatorNotAvailable): a
3835 /// variant match misses the subclasses a later Java release may add.
3836 pub fn is_coordinator_not_available_error(&self) -> bool {
3837 ErrorHierarchy::is_coordinator_not_available_error(self)
3838 }
3839
3840 /// Returns whether this error's Java class is, or extends,
3841 /// `org.apache.kafka.common.requests.CorrelationIdMismatchException`.
3842 ///
3843 /// Prefer this to matching [`Error::CorrelationIdMismatch`](Self::CorrelationIdMismatch): a
3844 /// variant match misses the subclasses a later Java release may add.
3845 pub fn is_correlation_id_mismatch_error(&self) -> bool {
3846 ErrorHierarchy::is_correlation_id_mismatch_error(self)
3847 }
3848
3849 /// Returns whether this error's Java class is, or extends,
3850 /// `org.apache.kafka.common.errors.CorruptRecordException`.
3851 ///
3852 /// Prefer this to matching [`Error::CorruptRecord`](Self::CorruptRecord): a variant match
3853 /// misses the subclasses a later Java release may add.
3854 pub fn is_corrupt_record_error(&self) -> bool {
3855 ErrorHierarchy::is_corrupt_record_error(self)
3856 }
3857
3858 /// Returns whether this error's Java class is, or extends,
3859 /// `org.apache.kafka.common.errors.DelegationTokenAuthorizationException`.
3860 ///
3861 /// Prefer this to matching
3862 /// [`Error::DelegationTokenAuthorization`](Self::DelegationTokenAuthorization): a variant match
3863 /// misses the subclasses a later Java release may add.
3864 pub fn is_delegation_token_authorization_error(&self) -> bool {
3865 ErrorHierarchy::is_delegation_token_authorization_error(self)
3866 }
3867
3868 /// Returns whether this error's Java class is, or extends,
3869 /// `org.apache.kafka.common.errors.DelegationTokenDisabledException`.
3870 ///
3871 /// Prefer this to matching [`Error::DelegationTokenDisabled`](Self::DelegationTokenDisabled): a
3872 /// variant match misses the subclasses a later Java release may add.
3873 pub fn is_delegation_token_disabled_error(&self) -> bool {
3874 ErrorHierarchy::is_delegation_token_disabled_error(self)
3875 }
3876
3877 /// Returns whether this error's Java class is, or extends,
3878 /// `org.apache.kafka.common.errors.DelegationTokenExpiredException`.
3879 ///
3880 /// Prefer this to matching [`Error::DelegationTokenExpired`](Self::DelegationTokenExpired): a
3881 /// variant match misses the subclasses a later Java release may add.
3882 pub fn is_delegation_token_expired_error(&self) -> bool {
3883 ErrorHierarchy::is_delegation_token_expired_error(self)
3884 }
3885
3886 /// Returns whether this error's Java class is, or extends,
3887 /// `org.apache.kafka.common.errors.DelegationTokenNotFoundException`.
3888 ///
3889 /// Prefer this to matching [`Error::DelegationTokenNotFound`](Self::DelegationTokenNotFound): a
3890 /// variant match misses the subclasses a later Java release may add.
3891 pub fn is_delegation_token_not_found_error(&self) -> bool {
3892 ErrorHierarchy::is_delegation_token_not_found_error(self)
3893 }
3894
3895 /// Returns whether this error's Java class is, or extends,
3896 /// `org.apache.kafka.common.errors.DelegationTokenOwnerMismatchException`.
3897 ///
3898 /// Prefer this to matching
3899 /// [`Error::DelegationTokenOwnerMismatch`](Self::DelegationTokenOwnerMismatch): a variant match
3900 /// misses the subclasses a later Java release may add.
3901 pub fn is_delegation_token_owner_mismatch_error(&self) -> bool {
3902 ErrorHierarchy::is_delegation_token_owner_mismatch_error(self)
3903 }
3904
3905 /// Returns whether this error's Java class is, or extends,
3906 /// `org.apache.kafka.common.errors.DisconnectException`.
3907 ///
3908 /// Prefer this to matching [`Error::Disconnect`](Self::Disconnect): a variant match misses the
3909 /// subclasses a later Java release may add.
3910 pub fn is_disconnect_error(&self) -> bool {
3911 ErrorHierarchy::is_disconnect_error(self)
3912 }
3913
3914 /// Returns whether this error's Java class is, or extends,
3915 /// `org.apache.kafka.common.errors.DuplicateBrokerRegistrationException`.
3916 ///
3917 /// Prefer this to matching
3918 /// [`Error::DuplicateBrokerRegistration`](Self::DuplicateBrokerRegistration): a variant match
3919 /// misses the subclasses a later Java release may add.
3920 pub fn is_duplicate_broker_registration_error(&self) -> bool {
3921 ErrorHierarchy::is_duplicate_broker_registration_error(self)
3922 }
3923
3924 /// Returns whether this error's Java class is, or extends,
3925 /// `org.apache.kafka.common.errors.DuplicateResourceException`.
3926 ///
3927 /// Prefer this to matching [`Error::DuplicateResource`](Self::DuplicateResource): a variant
3928 /// match misses the subclasses a later Java release may add.
3929 pub fn is_duplicate_resource_error(&self) -> bool {
3930 ErrorHierarchy::is_duplicate_resource_error(self)
3931 }
3932
3933 /// Returns whether this error's Java class is, or extends,
3934 /// `org.apache.kafka.common.errors.DuplicateSequenceException`.
3935 ///
3936 /// Prefer this to matching [`Error::DuplicateSequence`](Self::DuplicateSequence): a variant
3937 /// match misses the subclasses a later Java release may add.
3938 pub fn is_duplicate_sequence_error(&self) -> bool {
3939 ErrorHierarchy::is_duplicate_sequence_error(self)
3940 }
3941
3942 /// Returns whether this error's Java class is, or extends,
3943 /// `org.apache.kafka.common.errors.DuplicateVoterException`.
3944 ///
3945 /// Prefer this to matching [`Error::DuplicateVoter`](Self::DuplicateVoter): a variant match
3946 /// misses the subclasses a later Java release may add.
3947 pub fn is_duplicate_voter_error(&self) -> bool {
3948 ErrorHierarchy::is_duplicate_voter_error(self)
3949 }
3950
3951 /// Returns whether this error's Java class is, or extends,
3952 /// `org.apache.kafka.common.errors.ElectionNotNeededException`.
3953 ///
3954 /// Prefer this to matching [`Error::ElectionNotNeeded`](Self::ElectionNotNeeded): a variant
3955 /// match misses the subclasses a later Java release may add.
3956 pub fn is_election_not_needed_error(&self) -> bool {
3957 ErrorHierarchy::is_election_not_needed_error(self)
3958 }
3959
3960 /// Returns whether this error's Java class is, or extends,
3961 /// `org.apache.kafka.common.errors.EligibleLeadersNotAvailableException`.
3962 ///
3963 /// Prefer this to matching
3964 /// [`Error::EligibleLeadersNotAvailable`](Self::EligibleLeadersNotAvailable): a variant match
3965 /// misses the subclasses a later Java release may add.
3966 pub fn is_eligible_leaders_not_available_error(&self) -> bool {
3967 ErrorHierarchy::is_eligible_leaders_not_available_error(self)
3968 }
3969
3970 /// Returns whether this error's Java class is, or extends,
3971 /// `org.apache.kafka.common.errors.FeatureUpdateFailedException`.
3972 ///
3973 /// Prefer this to matching [`Error::FeatureUpdateFailed`](Self::FeatureUpdateFailed): a variant
3974 /// match misses the subclasses a later Java release may add.
3975 pub fn is_feature_update_failed_error(&self) -> bool {
3976 ErrorHierarchy::is_feature_update_failed_error(self)
3977 }
3978
3979 /// Returns whether this error's Java class is, or extends,
3980 /// `org.apache.kafka.common.errors.FencedInstanceIdException`.
3981 ///
3982 /// Prefer this to matching [`Error::FencedInstanceId`](Self::FencedInstanceId): a variant match
3983 /// misses the subclasses a later Java release may add.
3984 pub fn is_fenced_instance_id_error(&self) -> bool {
3985 ErrorHierarchy::is_fenced_instance_id_error(self)
3986 }
3987
3988 /// Returns whether this error's Java class is, or extends,
3989 /// `org.apache.kafka.common.errors.FencedLeaderEpochException`.
3990 ///
3991 /// Prefer this to matching [`Error::FencedLeaderEpoch`](Self::FencedLeaderEpoch): a variant
3992 /// match misses the subclasses a later Java release may add.
3993 pub fn is_fenced_leader_epoch_error(&self) -> bool {
3994 ErrorHierarchy::is_fenced_leader_epoch_error(self)
3995 }
3996
3997 /// Returns whether this error's Java class is, or extends,
3998 /// `org.apache.kafka.common.errors.FencedMemberEpochException`.
3999 ///
4000 /// Prefer this to matching [`Error::FencedMemberEpoch`](Self::FencedMemberEpoch): a variant
4001 /// match misses the subclasses a later Java release may add.
4002 pub fn is_fenced_member_epoch_error(&self) -> bool {
4003 ErrorHierarchy::is_fenced_member_epoch_error(self)
4004 }
4005
4006 /// Returns whether this error's Java class is, or extends,
4007 /// `org.apache.kafka.common.errors.FencedStateEpochException`.
4008 ///
4009 /// Prefer this to matching [`Error::FencedStateEpoch`](Self::FencedStateEpoch): a variant match
4010 /// misses the subclasses a later Java release may add.
4011 pub fn is_fenced_state_epoch_error(&self) -> bool {
4012 ErrorHierarchy::is_fenced_state_epoch_error(self)
4013 }
4014
4015 /// Returns whether this error's Java class is, or extends,
4016 /// `org.apache.kafka.common.errors.FetchSessionIdNotFoundException`.
4017 ///
4018 /// Prefer this to matching [`Error::FetchSessionIdNotFound`](Self::FetchSessionIdNotFound): a
4019 /// variant match misses the subclasses a later Java release may add.
4020 pub fn is_fetch_session_id_not_found_error(&self) -> bool {
4021 ErrorHierarchy::is_fetch_session_id_not_found_error(self)
4022 }
4023
4024 /// Returns whether this error's Java class is, or extends,
4025 /// `org.apache.kafka.common.errors.FetchSessionTopicIdException`.
4026 ///
4027 /// Prefer this to matching [`Error::FetchSessionTopicId`](Self::FetchSessionTopicId): a variant
4028 /// match misses the subclasses a later Java release may add.
4029 pub fn is_fetch_session_topic_id_error(&self) -> bool {
4030 ErrorHierarchy::is_fetch_session_topic_id_error(self)
4031 }
4032
4033 /// Returns whether this error's Java class is, or extends,
4034 /// `org.apache.kafka.common.errors.GroupAuthorizationException`.
4035 ///
4036 /// Prefer this to matching [`Error::GroupAuthorization`](Self::GroupAuthorization): a variant
4037 /// match misses the subclasses a later Java release may add.
4038 pub fn is_group_authorization_error(&self) -> bool {
4039 ErrorHierarchy::is_group_authorization_error(self)
4040 }
4041
4042 /// Returns whether this error's Java class is, or extends,
4043 /// `org.apache.kafka.common.errors.GroupDeletionFailedException`.
4044 ///
4045 /// Prefer this to matching [`Error::GroupDeletionFailed`](Self::GroupDeletionFailed): a variant
4046 /// match misses the subclasses a later Java release may add.
4047 pub fn is_group_deletion_failed_error(&self) -> bool {
4048 ErrorHierarchy::is_group_deletion_failed_error(self)
4049 }
4050
4051 /// Returns whether this error's Java class is, or extends,
4052 /// `org.apache.kafka.common.errors.GroupIdNotFoundException`.
4053 ///
4054 /// Prefer this to matching [`Error::GroupIdNotFound`](Self::GroupIdNotFound): a variant match
4055 /// misses the subclasses a later Java release may add.
4056 pub fn is_group_id_not_found_error(&self) -> bool {
4057 ErrorHierarchy::is_group_id_not_found_error(self)
4058 }
4059
4060 /// Returns whether this error's Java class is, or extends,
4061 /// `org.apache.kafka.common.errors.GroupMaxSizeReachedException`.
4062 ///
4063 /// Prefer this to matching [`Error::GroupMaxSizeReached`](Self::GroupMaxSizeReached): a variant
4064 /// match misses the subclasses a later Java release may add.
4065 pub fn is_group_max_size_reached_error(&self) -> bool {
4066 ErrorHierarchy::is_group_max_size_reached_error(self)
4067 }
4068
4069 /// Returns whether this error's Java class is, or extends,
4070 /// `org.apache.kafka.common.errors.GroupNotEmptyException`.
4071 ///
4072 /// Prefer this to matching [`Error::GroupNotEmpty`](Self::GroupNotEmpty): a variant match
4073 /// misses the subclasses a later Java release may add.
4074 pub fn is_group_not_empty_error(&self) -> bool {
4075 ErrorHierarchy::is_group_not_empty_error(self)
4076 }
4077
4078 /// Returns whether this error's Java class is, or extends,
4079 /// `org.apache.kafka.common.errors.GroupSubscribedToTopicException`.
4080 ///
4081 /// Prefer this to matching [`Error::GroupSubscribedToTopic`](Self::GroupSubscribedToTopic): a
4082 /// variant match misses the subclasses a later Java release may add.
4083 pub fn is_group_subscribed_to_topic_error(&self) -> bool {
4084 ErrorHierarchy::is_group_subscribed_to_topic_error(self)
4085 }
4086
4087 /// Returns whether this error's Java class is, or extends,
4088 /// `org.apache.kafka.common.errors.IllegalGenerationException`.
4089 ///
4090 /// Prefer this to matching [`Error::IllegalGeneration`](Self::IllegalGeneration): a variant
4091 /// match misses the subclasses a later Java release may add.
4092 pub fn is_illegal_generation_error(&self) -> bool {
4093 ErrorHierarchy::is_illegal_generation_error(self)
4094 }
4095
4096 /// Returns whether this error's Java class is, or extends,
4097 /// `org.apache.kafka.common.errors.IllegalSaslStateException`.
4098 ///
4099 /// Prefer this to matching [`Error::IllegalSaslState`](Self::IllegalSaslState): a variant match
4100 /// misses the subclasses a later Java release may add.
4101 pub fn is_illegal_sasl_state_error(&self) -> bool {
4102 ErrorHierarchy::is_illegal_sasl_state_error(self)
4103 }
4104
4105 /// Returns whether this error's Java class is, or extends,
4106 /// `org.apache.kafka.common.errors.InconsistentClusterIdException`.
4107 ///
4108 /// Prefer this to matching [`Error::InconsistentClusterId`](Self::InconsistentClusterId): a
4109 /// variant match misses the subclasses a later Java release may add.
4110 pub fn is_inconsistent_cluster_id_error(&self) -> bool {
4111 ErrorHierarchy::is_inconsistent_cluster_id_error(self)
4112 }
4113
4114 /// Returns whether this error's Java class is, or extends,
4115 /// `org.apache.kafka.common.errors.InconsistentGroupProtocolException`.
4116 ///
4117 /// Prefer this to matching
4118 /// [`Error::InconsistentGroupProtocol`](Self::InconsistentGroupProtocol): a variant match
4119 /// misses the subclasses a later Java release may add.
4120 pub fn is_inconsistent_group_protocol_error(&self) -> bool {
4121 ErrorHierarchy::is_inconsistent_group_protocol_error(self)
4122 }
4123
4124 /// Returns whether this error's Java class is, or extends,
4125 /// `org.apache.kafka.common.errors.InconsistentTopicIdException`.
4126 ///
4127 /// Prefer this to matching [`Error::InconsistentTopicId`](Self::InconsistentTopicId): a variant
4128 /// match misses the subclasses a later Java release may add.
4129 pub fn is_inconsistent_topic_id_error(&self) -> bool {
4130 ErrorHierarchy::is_inconsistent_topic_id_error(self)
4131 }
4132
4133 /// Returns whether this error's Java class is, or extends,
4134 /// `org.apache.kafka.common.errors.InconsistentVoterSetException`.
4135 ///
4136 /// Prefer this to matching [`Error::InconsistentVoterSet`](Self::InconsistentVoterSet): a
4137 /// variant match misses the subclasses a later Java release may add.
4138 pub fn is_inconsistent_voter_set_error(&self) -> bool {
4139 ErrorHierarchy::is_inconsistent_voter_set_error(self)
4140 }
4141
4142 /// Returns whether this error's Java class is, or extends,
4143 /// `org.apache.kafka.common.errors.IneligibleReplicaException`.
4144 ///
4145 /// Prefer this to matching [`Error::IneligibleReplica`](Self::IneligibleReplica): a variant
4146 /// match misses the subclasses a later Java release may add.
4147 pub fn is_ineligible_replica_error(&self) -> bool {
4148 ErrorHierarchy::is_ineligible_replica_error(self)
4149 }
4150
4151 /// Returns whether this error's Java class is, or extends,
4152 /// `org.apache.kafka.common.errors.InterruptException`.
4153 ///
4154 /// Prefer this to matching [`Error::Interrupt`](Self::Interrupt): a variant match misses the
4155 /// subclasses a later Java release may add.
4156 pub fn is_interrupt_error(&self) -> bool {
4157 ErrorHierarchy::is_interrupt_error(self)
4158 }
4159
4160 /// Returns whether this error's Java class is, or extends,
4161 /// `org.apache.kafka.common.errors.InvalidCommitOffsetSizeException`.
4162 ///
4163 /// Prefer this to matching [`Error::InvalidCommitOffsetSize`](Self::InvalidCommitOffsetSize): a
4164 /// variant match misses the subclasses a later Java release may add.
4165 pub fn is_invalid_commit_offset_size_error(&self) -> bool {
4166 ErrorHierarchy::is_invalid_commit_offset_size_error(self)
4167 }
4168
4169 /// Returns whether this error's Java class is, or extends,
4170 /// `org.apache.kafka.common.errors.InvalidFetchSessionEpochException`.
4171 ///
4172 /// Prefer this to matching [`Error::InvalidFetchSessionEpoch`](Self::InvalidFetchSessionEpoch):
4173 /// a variant match misses the subclasses a later Java release may add.
4174 pub fn is_invalid_fetch_session_epoch_error(&self) -> bool {
4175 ErrorHierarchy::is_invalid_fetch_session_epoch_error(self)
4176 }
4177
4178 /// Returns whether this error's Java class is, or extends,
4179 /// `org.apache.kafka.common.errors.InvalidFetchSizeException`.
4180 ///
4181 /// Prefer this to matching [`Error::InvalidFetchSize`](Self::InvalidFetchSize): a variant match
4182 /// misses the subclasses a later Java release may add.
4183 pub fn is_invalid_fetch_size_error(&self) -> bool {
4184 ErrorHierarchy::is_invalid_fetch_size_error(self)
4185 }
4186
4187 /// Returns whether this error's Java class is, or extends,
4188 /// `org.apache.kafka.common.errors.InvalidGroupIdException`.
4189 ///
4190 /// Prefer this to matching [`Error::InvalidGroupId`](Self::InvalidGroupId): a variant match
4191 /// misses the subclasses a later Java release may add.
4192 pub fn is_invalid_group_id_error(&self) -> bool {
4193 ErrorHierarchy::is_invalid_group_id_error(self)
4194 }
4195
4196 /// Returns whether this error's Java class is, or extends,
4197 /// `org.apache.kafka.common.errors.InvalidPartitionsException`.
4198 ///
4199 /// Prefer this to matching [`Error::InvalidPartitions`](Self::InvalidPartitions): a variant
4200 /// match misses the subclasses a later Java release may add.
4201 pub fn is_invalid_partitions_error(&self) -> bool {
4202 ErrorHierarchy::is_invalid_partitions_error(self)
4203 }
4204
4205 /// Returns whether this error's Java class is, or extends,
4206 /// `org.apache.kafka.common.errors.InvalidPidMappingException`.
4207 ///
4208 /// Prefer this to matching [`Error::InvalidPidMapping`](Self::InvalidPidMapping): a variant
4209 /// match misses the subclasses a later Java release may add.
4210 pub fn is_invalid_pid_mapping_error(&self) -> bool {
4211 ErrorHierarchy::is_invalid_pid_mapping_error(self)
4212 }
4213
4214 /// Returns whether this error's Java class is, or extends,
4215 /// `org.apache.kafka.common.errors.InvalidPrincipalTypeException`.
4216 ///
4217 /// Prefer this to matching [`Error::InvalidPrincipalType`](Self::InvalidPrincipalType): a
4218 /// variant match misses the subclasses a later Java release may add.
4219 pub fn is_invalid_principal_type_error(&self) -> bool {
4220 ErrorHierarchy::is_invalid_principal_type_error(self)
4221 }
4222
4223 /// Returns whether this error's Java class is, or extends,
4224 /// `org.apache.kafka.common.errors.InvalidProducerEpochException`.
4225 ///
4226 /// Prefer this to matching [`Error::InvalidProducerEpoch`](Self::InvalidProducerEpoch): a
4227 /// variant match misses the subclasses a later Java release may add.
4228 pub fn is_invalid_producer_epoch_error(&self) -> bool {
4229 ErrorHierarchy::is_invalid_producer_epoch_error(self)
4230 }
4231
4232 /// Returns whether this error's Java class is, or extends,
4233 /// `org.apache.kafka.common.InvalidRecordException`.
4234 ///
4235 /// Prefer this to matching [`Error::InvalidRecord`](Self::InvalidRecord): a variant match
4236 /// misses the subclasses a later Java release may add.
4237 pub fn is_invalid_record_error(&self) -> bool {
4238 ErrorHierarchy::is_invalid_record_error(self)
4239 }
4240
4241 /// Returns whether this error's Java class is, or extends,
4242 /// `org.apache.kafka.common.errors.InvalidRecordStateException`.
4243 ///
4244 /// Prefer this to matching [`Error::InvalidRecordState`](Self::InvalidRecordState): a variant
4245 /// match misses the subclasses a later Java release may add.
4246 pub fn is_invalid_record_state_error(&self) -> bool {
4247 ErrorHierarchy::is_invalid_record_state_error(self)
4248 }
4249
4250 /// Returns whether this error's Java class is, or extends,
4251 /// `org.apache.kafka.common.errors.InvalidRegistrationException`.
4252 ///
4253 /// Prefer this to matching [`Error::InvalidRegistration`](Self::InvalidRegistration): a variant
4254 /// match misses the subclasses a later Java release may add.
4255 pub fn is_invalid_registration_error(&self) -> bool {
4256 ErrorHierarchy::is_invalid_registration_error(self)
4257 }
4258
4259 /// Returns whether this error's Java class is, or extends,
4260 /// `org.apache.kafka.common.errors.InvalidRegularExpression`.
4261 ///
4262 /// Prefer this to matching [`Error::InvalidRegularExpression`](Self::InvalidRegularExpression):
4263 /// a variant match misses the subclasses a later Java release may add.
4264 pub fn is_invalid_regular_expression_error(&self) -> bool {
4265 ErrorHierarchy::is_invalid_regular_expression_error(self)
4266 }
4267
4268 /// Returns whether this error's Java class is, or extends,
4269 /// `org.apache.kafka.common.errors.InvalidReplicaAssignmentException`.
4270 ///
4271 /// Prefer this to matching [`Error::InvalidReplicaAssignment`](Self::InvalidReplicaAssignment):
4272 /// a variant match misses the subclasses a later Java release may add.
4273 pub fn is_invalid_replica_assignment_error(&self) -> bool {
4274 ErrorHierarchy::is_invalid_replica_assignment_error(self)
4275 }
4276
4277 /// Returns whether this error's Java class is, or extends,
4278 /// `org.apache.kafka.common.errors.InvalidReplicationFactorException`.
4279 ///
4280 /// Prefer this to matching [`Error::InvalidReplicationFactor`](Self::InvalidReplicationFactor):
4281 /// a variant match misses the subclasses a later Java release may add.
4282 pub fn is_invalid_replication_factor_error(&self) -> bool {
4283 ErrorHierarchy::is_invalid_replication_factor_error(self)
4284 }
4285
4286 /// Returns whether this error's Java class is, or extends,
4287 /// `org.apache.kafka.common.errors.InvalidRequestException`.
4288 ///
4289 /// Prefer this to matching [`Error::InvalidRequest`](Self::InvalidRequest): a variant match
4290 /// misses the subclasses a later Java release may add.
4291 pub fn is_invalid_request_error(&self) -> bool {
4292 ErrorHierarchy::is_invalid_request_error(self)
4293 }
4294
4295 /// Returns whether this error's Java class is, or extends,
4296 /// `org.apache.kafka.common.errors.InvalidRequiredAcksException`.
4297 ///
4298 /// Prefer this to matching [`Error::InvalidRequiredAcks`](Self::InvalidRequiredAcks): a variant
4299 /// match misses the subclasses a later Java release may add.
4300 pub fn is_invalid_required_acks_error(&self) -> bool {
4301 ErrorHierarchy::is_invalid_required_acks_error(self)
4302 }
4303
4304 /// Returns whether this error's Java class is, or extends,
4305 /// `org.apache.kafka.common.errors.InvalidSessionTimeoutException`.
4306 ///
4307 /// Prefer this to matching [`Error::InvalidSessionTimeout`](Self::InvalidSessionTimeout): a
4308 /// variant match misses the subclasses a later Java release may add.
4309 pub fn is_invalid_session_timeout_error(&self) -> bool {
4310 ErrorHierarchy::is_invalid_session_timeout_error(self)
4311 }
4312
4313 /// Returns whether this error's Java class is, or extends,
4314 /// `org.apache.kafka.common.errors.InvalidShareSessionEpochException`.
4315 ///
4316 /// Prefer this to matching [`Error::InvalidShareSessionEpoch`](Self::InvalidShareSessionEpoch):
4317 /// a variant match misses the subclasses a later Java release may add.
4318 pub fn is_invalid_share_session_epoch_error(&self) -> bool {
4319 ErrorHierarchy::is_invalid_share_session_epoch_error(self)
4320 }
4321
4322 /// Returns whether this error's Java class is, or extends,
4323 /// `org.apache.kafka.common.errors.InvalidTimestampException`.
4324 ///
4325 /// Prefer this to matching [`Error::InvalidTimestamp`](Self::InvalidTimestamp): a variant match
4326 /// misses the subclasses a later Java release may add.
4327 pub fn is_invalid_timestamp_error(&self) -> bool {
4328 ErrorHierarchy::is_invalid_timestamp_error(self)
4329 }
4330
4331 /// Returns whether this error's Java class is, or extends,
4332 /// `org.apache.kafka.common.errors.InvalidTopicException`.
4333 ///
4334 /// Prefer this to matching [`Error::InvalidTopic`](Self::InvalidTopic): a variant match misses
4335 /// the subclasses a later Java release may add.
4336 pub fn is_invalid_topic_error(&self) -> bool {
4337 ErrorHierarchy::is_invalid_topic_error(self)
4338 }
4339
4340 /// Returns whether this error's Java class is, or extends,
4341 /// `org.apache.kafka.common.errors.InvalidTxnStateException`.
4342 ///
4343 /// Prefer this to matching [`Error::InvalidTxnState`](Self::InvalidTxnState): a variant match
4344 /// misses the subclasses a later Java release may add.
4345 pub fn is_invalid_txn_state_error(&self) -> bool {
4346 ErrorHierarchy::is_invalid_txn_state_error(self)
4347 }
4348
4349 /// Returns whether this error's Java class is, or extends,
4350 /// `org.apache.kafka.common.errors.InvalidTxnTimeoutException`.
4351 ///
4352 /// Prefer this to matching [`Error::InvalidTxnTimeout`](Self::InvalidTxnTimeout): a variant
4353 /// match misses the subclasses a later Java release may add.
4354 pub fn is_invalid_txn_timeout_error(&self) -> bool {
4355 ErrorHierarchy::is_invalid_txn_timeout_error(self)
4356 }
4357
4358 /// Returns whether this error's Java class is, or extends,
4359 /// `org.apache.kafka.common.errors.InvalidUpdateVersionException`.
4360 ///
4361 /// Prefer this to matching [`Error::InvalidUpdateVersion`](Self::InvalidUpdateVersion): a
4362 /// variant match misses the subclasses a later Java release may add.
4363 pub fn is_invalid_update_version_error(&self) -> bool {
4364 ErrorHierarchy::is_invalid_update_version_error(self)
4365 }
4366
4367 /// Returns whether this error's Java class is, or extends,
4368 /// `org.apache.kafka.common.errors.InvalidVoterKeyException`.
4369 ///
4370 /// Prefer this to matching [`Error::InvalidVoterKey`](Self::InvalidVoterKey): a variant match
4371 /// misses the subclasses a later Java release may add.
4372 pub fn is_invalid_voter_key_error(&self) -> bool {
4373 ErrorHierarchy::is_invalid_voter_key_error(self)
4374 }
4375
4376 /// Returns whether this error's Java class is, or extends,
4377 /// `org.apache.kafka.common.errors.KafkaStorageException`.
4378 ///
4379 /// Prefer this to matching [`Error::KafkaStorage`](Self::KafkaStorage): a variant match misses
4380 /// the subclasses a later Java release may add.
4381 pub fn is_kafka_storage_error(&self) -> bool {
4382 ErrorHierarchy::is_kafka_storage_error(self)
4383 }
4384
4385 /// Returns whether this error's Java class is, or extends,
4386 /// `org.apache.kafka.common.errors.LeaderNotAvailableException`.
4387 ///
4388 /// Prefer this to matching [`Error::LeaderNotAvailable`](Self::LeaderNotAvailable): a variant
4389 /// match misses the subclasses a later Java release may add.
4390 pub fn is_leader_not_available_error(&self) -> bool {
4391 ErrorHierarchy::is_leader_not_available_error(self)
4392 }
4393
4394 /// Returns whether this error's Java class is, or extends,
4395 /// `org.apache.kafka.common.errors.ListenerNotFoundException`.
4396 ///
4397 /// Prefer this to matching [`Error::ListenerNotFound`](Self::ListenerNotFound): a variant match
4398 /// misses the subclasses a later Java release may add.
4399 pub fn is_listener_not_found_error(&self) -> bool {
4400 ErrorHierarchy::is_listener_not_found_error(self)
4401 }
4402
4403 /// Returns whether this error's Java class is, or extends,
4404 /// `org.apache.kafka.common.errors.LogDirNotFoundException`.
4405 ///
4406 /// Prefer this to matching [`Error::LogDirNotFound`](Self::LogDirNotFound): a variant match
4407 /// misses the subclasses a later Java release may add.
4408 pub fn is_log_dir_not_found_error(&self) -> bool {
4409 ErrorHierarchy::is_log_dir_not_found_error(self)
4410 }
4411
4412 /// Returns whether this error's Java class is, or extends,
4413 /// `org.apache.kafka.common.errors.MemberIdRequiredException`.
4414 ///
4415 /// Prefer this to matching [`Error::MemberIdRequired`](Self::MemberIdRequired): a variant match
4416 /// misses the subclasses a later Java release may add.
4417 pub fn is_member_id_required_error(&self) -> bool {
4418 ErrorHierarchy::is_member_id_required_error(self)
4419 }
4420
4421 /// Returns whether this error's Java class is, or extends,
4422 /// `org.apache.kafka.common.errors.MismatchedEndpointTypeException`.
4423 ///
4424 /// Prefer this to matching [`Error::MismatchedEndpointType`](Self::MismatchedEndpointType): a
4425 /// variant match misses the subclasses a later Java release may add.
4426 pub fn is_mismatched_endpoint_type_error(&self) -> bool {
4427 ErrorHierarchy::is_mismatched_endpoint_type_error(self)
4428 }
4429
4430 /// Returns whether this error's Java class is, or extends,
4431 /// `org.apache.kafka.common.errors.NetworkException`.
4432 ///
4433 /// Prefer this to matching [`Error::Network`](Self::Network): a variant match misses the
4434 /// subclasses a later Java release may add.
4435 pub fn is_network_error(&self) -> bool {
4436 ErrorHierarchy::is_network_error(self)
4437 }
4438
4439 /// Returns whether this error's Java class is, or extends,
4440 /// `org.apache.kafka.common.errors.NewLeaderElectedException`.
4441 ///
4442 /// Prefer this to matching [`Error::NewLeaderElected`](Self::NewLeaderElected): a variant match
4443 /// misses the subclasses a later Java release may add.
4444 pub fn is_new_leader_elected_error(&self) -> bool {
4445 ErrorHierarchy::is_new_leader_elected_error(self)
4446 }
4447
4448 /// Returns whether this error's Java class is, or extends,
4449 /// `org.apache.kafka.common.errors.NoReassignmentInProgressException`.
4450 ///
4451 /// Prefer this to matching [`Error::NoReassignmentInProgress`](Self::NoReassignmentInProgress):
4452 /// a variant match misses the subclasses a later Java release may add.
4453 pub fn is_no_reassignment_in_progress_error(&self) -> bool {
4454 ErrorHierarchy::is_no_reassignment_in_progress_error(self)
4455 }
4456
4457 /// Returns whether this error's Java class is, or extends,
4458 /// `org.apache.kafka.common.errors.NotControllerException`.
4459 ///
4460 /// Prefer this to matching [`Error::NotController`](Self::NotController): a variant match
4461 /// misses the subclasses a later Java release may add.
4462 pub fn is_not_controller_error(&self) -> bool {
4463 ErrorHierarchy::is_not_controller_error(self)
4464 }
4465
4466 /// Returns whether this error's Java class is, or extends,
4467 /// `org.apache.kafka.common.errors.NotCoordinatorException`.
4468 ///
4469 /// Prefer this to matching [`Error::NotCoordinator`](Self::NotCoordinator): a variant match
4470 /// misses the subclasses a later Java release may add.
4471 pub fn is_not_coordinator_error(&self) -> bool {
4472 ErrorHierarchy::is_not_coordinator_error(self)
4473 }
4474
4475 /// Returns whether this error's Java class is, or extends,
4476 /// `org.apache.kafka.common.errors.NotEnoughReplicasException`.
4477 ///
4478 /// Prefer this to matching [`Error::NotEnoughReplicas`](Self::NotEnoughReplicas): a variant
4479 /// match misses the subclasses a later Java release may add.
4480 pub fn is_not_enough_replicas_error(&self) -> bool {
4481 ErrorHierarchy::is_not_enough_replicas_error(self)
4482 }
4483
4484 /// Returns whether this error's Java class is, or extends,
4485 /// `org.apache.kafka.common.errors.NotEnoughReplicasAfterAppendException`.
4486 ///
4487 /// Prefer this to matching
4488 /// [`Error::NotEnoughReplicasAfterAppend`](Self::NotEnoughReplicasAfterAppend): a variant match
4489 /// misses the subclasses a later Java release may add.
4490 pub fn is_not_enough_replicas_after_append_error(&self) -> bool {
4491 ErrorHierarchy::is_not_enough_replicas_after_append_error(self)
4492 }
4493
4494 /// Returns whether this error's Java class is, or extends,
4495 /// `org.apache.kafka.common.errors.NotLeaderOrFollowerException`.
4496 ///
4497 /// Prefer this to matching [`Error::NotLeaderOrFollower`](Self::NotLeaderOrFollower): a variant
4498 /// match misses the subclasses a later Java release may add.
4499 pub fn is_not_leader_or_follower_error(&self) -> bool {
4500 ErrorHierarchy::is_not_leader_or_follower_error(self)
4501 }
4502
4503 /// Returns whether this error's Java class is, or extends,
4504 /// `org.apache.kafka.common.errors.OffsetMetadataTooLarge`.
4505 ///
4506 /// Prefer this to matching [`Error::OffsetMetadataTooLarge`](Self::OffsetMetadataTooLarge): a
4507 /// variant match misses the subclasses a later Java release may add.
4508 pub fn is_offset_metadata_too_large_error(&self) -> bool {
4509 ErrorHierarchy::is_offset_metadata_too_large_error(self)
4510 }
4511
4512 /// Returns whether this error's Java class is, or extends,
4513 /// `org.apache.kafka.common.errors.OffsetMovedToTieredStorageException`.
4514 ///
4515 /// Prefer this to matching
4516 /// [`Error::OffsetMovedToTieredStorage`](Self::OffsetMovedToTieredStorage): a variant match
4517 /// misses the subclasses a later Java release may add.
4518 pub fn is_offset_moved_to_tiered_storage_error(&self) -> bool {
4519 ErrorHierarchy::is_offset_moved_to_tiered_storage_error(self)
4520 }
4521
4522 /// Returns whether this error's Java class is, or extends,
4523 /// `org.apache.kafka.common.errors.OffsetNotAvailableException`.
4524 ///
4525 /// Prefer this to matching [`Error::OffsetNotAvailable`](Self::OffsetNotAvailable): a variant
4526 /// match misses the subclasses a later Java release may add.
4527 pub fn is_offset_not_available_error(&self) -> bool {
4528 ErrorHierarchy::is_offset_not_available_error(self)
4529 }
4530
4531 /// Returns whether this error's Java class is, or extends,
4532 /// `org.apache.kafka.common.errors.OffsetOutOfRangeException`.
4533 ///
4534 /// Prefer this to matching [`Error::OffsetOutOfRange`](Self::OffsetOutOfRange): a variant match
4535 /// misses the subclasses a later Java release may add.
4536 pub fn is_offset_out_of_range_error(&self) -> bool {
4537 ErrorHierarchy::is_offset_out_of_range_error(self)
4538 }
4539
4540 /// Returns whether this error's Java class is, or extends,
4541 /// `org.apache.kafka.common.errors.OperationNotAttemptedException`.
4542 ///
4543 /// Prefer this to matching [`Error::OperationNotAttempted`](Self::OperationNotAttempted): a
4544 /// variant match misses the subclasses a later Java release may add.
4545 pub fn is_operation_not_attempted_error(&self) -> bool {
4546 ErrorHierarchy::is_operation_not_attempted_error(self)
4547 }
4548
4549 /// Returns whether this error's Java class is, or extends,
4550 /// `org.apache.kafka.common.errors.PolicyViolationException`.
4551 ///
4552 /// Prefer this to matching [`Error::PolicyViolation`](Self::PolicyViolation): a variant match
4553 /// misses the subclasses a later Java release may add.
4554 pub fn is_policy_violation_error(&self) -> bool {
4555 ErrorHierarchy::is_policy_violation_error(self)
4556 }
4557
4558 /// Returns whether this error's Java class is, or extends,
4559 /// `org.apache.kafka.common.errors.PositionOutOfRangeException`.
4560 ///
4561 /// Prefer this to matching [`Error::PositionOutOfRange`](Self::PositionOutOfRange): a variant
4562 /// match misses the subclasses a later Java release may add.
4563 pub fn is_position_out_of_range_error(&self) -> bool {
4564 ErrorHierarchy::is_position_out_of_range_error(self)
4565 }
4566
4567 /// Returns whether this error's Java class is, or extends,
4568 /// `org.apache.kafka.common.errors.PreferredLeaderNotAvailableException`.
4569 ///
4570 /// Prefer this to matching
4571 /// [`Error::PreferredLeaderNotAvailable`](Self::PreferredLeaderNotAvailable): a variant match
4572 /// misses the subclasses a later Java release may add.
4573 pub fn is_preferred_leader_not_available_error(&self) -> bool {
4574 ErrorHierarchy::is_preferred_leader_not_available_error(self)
4575 }
4576
4577 /// Returns whether this error's Java class is, or extends,
4578 /// `org.apache.kafka.common.errors.PrincipalDeserializationException`.
4579 ///
4580 /// Prefer this to matching [`Error::PrincipalDeserialization`](Self::PrincipalDeserialization):
4581 /// a variant match misses the subclasses a later Java release may add.
4582 pub fn is_principal_deserialization_error(&self) -> bool {
4583 ErrorHierarchy::is_principal_deserialization_error(self)
4584 }
4585
4586 /// Returns whether this error's Java class is, or extends,
4587 /// `org.apache.kafka.common.errors.ProducerFencedException`.
4588 ///
4589 /// Prefer this to matching [`Error::ProducerFenced`](Self::ProducerFenced): a variant match
4590 /// misses the subclasses a later Java release may add.
4591 pub fn is_producer_fenced_error(&self) -> bool {
4592 ErrorHierarchy::is_producer_fenced_error(self)
4593 }
4594
4595 /// Returns whether this error's Java class is, or extends,
4596 /// `org.apache.kafka.common.metrics.QuotaViolationException`.
4597 ///
4598 /// Prefer this to matching [`Error::QuotaViolation`](Self::QuotaViolation): a variant match
4599 /// misses the subclasses a later Java release may add.
4600 pub fn is_quota_violation_error(&self) -> bool {
4601 ErrorHierarchy::is_quota_violation_error(self)
4602 }
4603
4604 /// Returns whether this error's Java class is, or extends,
4605 /// `org.apache.kafka.common.errors.ReassignmentInProgressException`.
4606 ///
4607 /// Prefer this to matching [`Error::ReassignmentInProgress`](Self::ReassignmentInProgress): a
4608 /// variant match misses the subclasses a later Java release may add.
4609 pub fn is_reassignment_in_progress_error(&self) -> bool {
4610 ErrorHierarchy::is_reassignment_in_progress_error(self)
4611 }
4612
4613 /// Returns whether this error's Java class is, or extends,
4614 /// `org.apache.kafka.common.errors.RebalanceInProgressException`.
4615 ///
4616 /// Prefer this to matching [`Error::RebalanceInProgress`](Self::RebalanceInProgress): a variant
4617 /// match misses the subclasses a later Java release may add.
4618 pub fn is_rebalance_in_progress_error(&self) -> bool {
4619 ErrorHierarchy::is_rebalance_in_progress_error(self)
4620 }
4621
4622 /// Returns whether this error's Java class is, or extends,
4623 /// `org.apache.kafka.common.errors.RebootstrapRequiredException`.
4624 ///
4625 /// Prefer this to matching [`Error::RebootstrapRequired`](Self::RebootstrapRequired): a variant
4626 /// match misses the subclasses a later Java release may add.
4627 pub fn is_rebootstrap_required_error(&self) -> bool {
4628 ErrorHierarchy::is_rebootstrap_required_error(self)
4629 }
4630
4631 /// Returns whether this error's Java class is, or extends,
4632 /// `org.apache.kafka.common.errors.RecordBatchTooLargeException`.
4633 ///
4634 /// Prefer this to matching [`Error::RecordBatchTooLarge`](Self::RecordBatchTooLarge): a variant
4635 /// match misses the subclasses a later Java release may add.
4636 pub fn is_record_batch_too_large_error(&self) -> bool {
4637 ErrorHierarchy::is_record_batch_too_large_error(self)
4638 }
4639
4640 /// Returns whether this error's Java class is, or extends,
4641 /// `org.apache.kafka.common.errors.RecordDeserializationException`.
4642 ///
4643 /// Prefer this to matching [`Error::RecordDeserialization`](Self::RecordDeserialization): a
4644 /// variant match misses the subclasses a later Java release may add.
4645 pub fn is_record_deserialization_error(&self) -> bool {
4646 ErrorHierarchy::is_record_deserialization_error(self)
4647 }
4648
4649 /// Returns whether this error's Java class is, or extends,
4650 /// `org.apache.kafka.common.errors.RecordTooLargeException`.
4651 ///
4652 /// Prefer this to matching [`Error::RecordTooLarge`](Self::RecordTooLarge): a variant match
4653 /// misses the subclasses a later Java release may add.
4654 pub fn is_record_too_large_error(&self) -> bool {
4655 ErrorHierarchy::is_record_too_large_error(self)
4656 }
4657
4658 /// Returns whether this error's Java class is, or extends,
4659 /// `org.apache.kafka.common.network.InvalidReceiveException`.
4660 ///
4661 /// Prefer this to matching [`Error::InvalidReceive`](Self::InvalidReceive): a variant match
4662 /// misses the subclasses a later Java release may add.
4663 pub fn is_invalid_receive_error(&self) -> bool {
4664 ErrorHierarchy::is_invalid_receive_error(self)
4665 }
4666
4667 /// Returns whether this error's Java class is, or extends,
4668 /// `org.apache.kafka.common.config.ConfigException`.
4669 ///
4670 /// Prefer this to matching [`Error::Config`](Self::Config): a variant match misses the
4671 /// subclasses a later Java release may add.
4672 pub fn is_config_error(&self) -> bool {
4673 ErrorHierarchy::is_config_error(self)
4674 }
4675
4676 /// Returns whether this error's Java class is, or extends,
4677 /// `org.apache.kafka.clients.consumer.RetriableCommitFailedException`.
4678 ///
4679 /// Prefer this to matching
4680 /// [`Error::ConsumerRetriableCommitFailed`](Self::ConsumerRetriableCommitFailed): a variant
4681 /// match misses the subclasses a later Java release may add.
4682 pub fn is_consumer_retriable_commit_failed_error(&self) -> bool {
4683 ErrorHierarchy::is_consumer_retriable_commit_failed_error(self)
4684 }
4685
4686 /// Returns whether this error's Java class is, or extends,
4687 /// `org.apache.kafka.clients.consumer.CommitFailedException`.
4688 ///
4689 /// Prefer this to matching [`Error::ConsumerCommitFailed`](Self::ConsumerCommitFailed): a
4690 /// variant match misses the subclasses a later Java release may add.
4691 pub fn is_consumer_commit_failed_error(&self) -> bool {
4692 ErrorHierarchy::is_consumer_commit_failed_error(self)
4693 }
4694
4695 /// Returns whether this error's Java class is, or extends,
4696 /// `org.apache.kafka.clients.consumer.NoOffsetForPartitionException`.
4697 ///
4698 /// Prefer this to matching
4699 /// [`Error::ConsumerNoOffsetForPartition`](Self::ConsumerNoOffsetForPartition): a variant match
4700 /// misses the subclasses a later Java release may add.
4701 pub fn is_consumer_no_offset_for_partition_error(&self) -> bool {
4702 ErrorHierarchy::is_consumer_no_offset_for_partition_error(self)
4703 }
4704
4705 /// Returns whether this error's Java class is, or extends,
4706 /// `org.apache.kafka.clients.consumer.LogTruncationException`.
4707 ///
4708 /// Prefer this to matching [`Error::ConsumerLogTruncation`](Self::ConsumerLogTruncation): a
4709 /// variant match misses the subclasses a later Java release may add.
4710 pub fn is_consumer_log_truncation_error(&self) -> bool {
4711 ErrorHierarchy::is_consumer_log_truncation_error(self)
4712 }
4713
4714 /// Returns whether this error's Java class is, or extends,
4715 /// `org.apache.kafka.common.errors.ReplicaNotAvailableException`.
4716 ///
4717 /// Prefer this to matching [`Error::ReplicaNotAvailable`](Self::ReplicaNotAvailable): a variant
4718 /// match misses the subclasses a later Java release may add.
4719 pub fn is_replica_not_available_error(&self) -> bool {
4720 ErrorHierarchy::is_replica_not_available_error(self)
4721 }
4722
4723 /// Returns whether this error's Java class is, or extends,
4724 /// `org.apache.kafka.common.errors.ResourceNotFoundException`.
4725 ///
4726 /// Prefer this to matching [`Error::ResourceNotFound`](Self::ResourceNotFound): a variant match
4727 /// misses the subclasses a later Java release may add.
4728 pub fn is_resource_not_found_error(&self) -> bool {
4729 ErrorHierarchy::is_resource_not_found_error(self)
4730 }
4731
4732 /// Returns whether this error's Java class is, or extends,
4733 /// `org.apache.kafka.common.errors.SaslAuthenticationException`.
4734 ///
4735 /// Prefer this to matching [`Error::SaslAuthentication`](Self::SaslAuthentication): a variant
4736 /// match misses the subclasses a later Java release may add.
4737 pub fn is_sasl_authentication_error(&self) -> bool {
4738 ErrorHierarchy::is_sasl_authentication_error(self)
4739 }
4740
4741 /// Returns whether this error's Java class is, or extends,
4742 /// `org.apache.kafka.common.protocol.types.SchemaException`.
4743 ///
4744 /// Prefer this to matching [`Error::Schema`](Self::Schema): a variant match misses the
4745 /// subclasses a later Java release may add.
4746 pub fn is_schema_error(&self) -> bool {
4747 ErrorHierarchy::is_schema_error(self)
4748 }
4749
4750 /// Returns whether this error's Java class is, or extends,
4751 /// `org.apache.kafka.common.errors.SecurityDisabledException`.
4752 ///
4753 /// Prefer this to matching [`Error::SecurityDisabled`](Self::SecurityDisabled): a variant match
4754 /// misses the subclasses a later Java release may add.
4755 pub fn is_security_disabled_error(&self) -> bool {
4756 ErrorHierarchy::is_security_disabled_error(self)
4757 }
4758
4759 /// Returns whether this error's Java class is, or extends,
4760 /// `org.apache.kafka.common.errors.ShareSessionLimitReachedException`.
4761 ///
4762 /// Prefer this to matching [`Error::ShareSessionLimitReached`](Self::ShareSessionLimitReached):
4763 /// a variant match misses the subclasses a later Java release may add.
4764 pub fn is_share_session_limit_reached_error(&self) -> bool {
4765 ErrorHierarchy::is_share_session_limit_reached_error(self)
4766 }
4767
4768 /// Returns whether this error's Java class is, or extends,
4769 /// `org.apache.kafka.common.errors.ShareSessionNotFoundException`.
4770 ///
4771 /// Prefer this to matching [`Error::ShareSessionNotFound`](Self::ShareSessionNotFound): a
4772 /// variant match misses the subclasses a later Java release may add.
4773 pub fn is_share_session_not_found_error(&self) -> bool {
4774 ErrorHierarchy::is_share_session_not_found_error(self)
4775 }
4776
4777 /// Returns whether this error's Java class is, or extends,
4778 /// `org.apache.kafka.common.errors.SnapshotNotFoundException`.
4779 ///
4780 /// Prefer this to matching [`Error::SnapshotNotFound`](Self::SnapshotNotFound): a variant match
4781 /// misses the subclasses a later Java release may add.
4782 pub fn is_snapshot_not_found_error(&self) -> bool {
4783 ErrorHierarchy::is_snapshot_not_found_error(self)
4784 }
4785
4786 /// Returns whether this error's Java class is, or extends,
4787 /// `org.apache.kafka.common.errors.SslAuthenticationException`.
4788 ///
4789 /// Prefer this to matching [`Error::SslAuthentication`](Self::SslAuthentication): a variant
4790 /// match misses the subclasses a later Java release may add.
4791 pub fn is_ssl_authentication_error(&self) -> bool {
4792 ErrorHierarchy::is_ssl_authentication_error(self)
4793 }
4794
4795 /// Returns whether this error's Java class is, or extends,
4796 /// `org.apache.kafka.common.errors.StaleBrokerEpochException`.
4797 ///
4798 /// Prefer this to matching [`Error::StaleBrokerEpoch`](Self::StaleBrokerEpoch): a variant match
4799 /// misses the subclasses a later Java release may add.
4800 pub fn is_stale_broker_epoch_error(&self) -> bool {
4801 ErrorHierarchy::is_stale_broker_epoch_error(self)
4802 }
4803
4804 /// Returns whether this error's Java class is, or extends,
4805 /// `org.apache.kafka.common.errors.StaleMemberEpochException`.
4806 ///
4807 /// Prefer this to matching [`Error::StaleMemberEpoch`](Self::StaleMemberEpoch): a variant match
4808 /// misses the subclasses a later Java release may add.
4809 pub fn is_stale_member_epoch_error(&self) -> bool {
4810 ErrorHierarchy::is_stale_member_epoch_error(self)
4811 }
4812
4813 /// Returns whether this error's Java class is, or extends,
4814 /// `org.apache.kafka.common.errors.StreamsInvalidTopologyException`.
4815 ///
4816 /// Prefer this to matching [`Error::StreamsInvalidTopology`](Self::StreamsInvalidTopology): a
4817 /// variant match misses the subclasses a later Java release may add.
4818 pub fn is_streams_invalid_topology_error(&self) -> bool {
4819 ErrorHierarchy::is_streams_invalid_topology_error(self)
4820 }
4821
4822 /// Returns whether this error's Java class is, or extends,
4823 /// `org.apache.kafka.common.errors.StreamsInvalidTopologyEpochException`.
4824 ///
4825 /// Prefer this to matching
4826 /// [`Error::StreamsInvalidTopologyEpoch`](Self::StreamsInvalidTopologyEpoch): a variant match
4827 /// misses the subclasses a later Java release may add.
4828 pub fn is_streams_invalid_topology_epoch_error(&self) -> bool {
4829 ErrorHierarchy::is_streams_invalid_topology_epoch_error(self)
4830 }
4831
4832 /// Returns whether this error's Java class is, or extends,
4833 /// `org.apache.kafka.common.errors.StreamsTopologyDescriptionUpdateFailedException`.
4834 ///
4835 /// Prefer this to matching [`Error::StreamsTopologyDescriptionUpdateFailed`](Self::StreamsTopologyDescriptionUpdateFailed): a variant
4836 /// match misses the subclasses a later Java release may add.
4837 pub fn is_streams_topology_description_update_failed_error(&self) -> bool {
4838 ErrorHierarchy::is_streams_topology_description_update_failed_error(self)
4839 }
4840
4841 /// Returns whether this error's Java class is, or extends,
4842 /// `org.apache.kafka.common.errors.StreamsTopologyFencedException`.
4843 ///
4844 /// Prefer this to matching [`Error::StreamsTopologyFenced`](Self::StreamsTopologyFenced): a
4845 /// variant match misses the subclasses a later Java release may add.
4846 pub fn is_streams_topology_fenced_error(&self) -> bool {
4847 ErrorHierarchy::is_streams_topology_fenced_error(self)
4848 }
4849
4850 /// Returns whether this error's Java class is, or extends,
4851 /// `org.apache.kafka.common.errors.TelemetryTooLargeException`.
4852 ///
4853 /// Prefer this to matching [`Error::TelemetryTooLarge`](Self::TelemetryTooLarge): a variant
4854 /// match misses the subclasses a later Java release may add.
4855 pub fn is_telemetry_too_large_error(&self) -> bool {
4856 ErrorHierarchy::is_telemetry_too_large_error(self)
4857 }
4858
4859 /// Returns whether this error's Java class is, or extends,
4860 /// `org.apache.kafka.common.errors.ThrottlingQuotaExceededException`.
4861 ///
4862 /// Prefer this to matching [`Error::ThrottlingQuotaExceeded`](Self::ThrottlingQuotaExceeded): a
4863 /// variant match misses the subclasses a later Java release may add.
4864 pub fn is_throttling_quota_exceeded_error(&self) -> bool {
4865 ErrorHierarchy::is_throttling_quota_exceeded_error(self)
4866 }
4867
4868 /// Returns whether this error's Java class is, or extends,
4869 /// `org.apache.kafka.common.errors.TopicAuthorizationException`.
4870 ///
4871 /// Prefer this to matching [`Error::TopicAuthorization`](Self::TopicAuthorization): a variant
4872 /// match misses the subclasses a later Java release may add.
4873 pub fn is_topic_authorization_error(&self) -> bool {
4874 ErrorHierarchy::is_topic_authorization_error(self)
4875 }
4876
4877 /// Returns whether this error's Java class is, or extends,
4878 /// `org.apache.kafka.common.errors.TopicDeletionDisabledException`.
4879 ///
4880 /// Prefer this to matching [`Error::TopicDeletionDisabled`](Self::TopicDeletionDisabled): a
4881 /// variant match misses the subclasses a later Java release may add.
4882 pub fn is_topic_deletion_disabled_error(&self) -> bool {
4883 ErrorHierarchy::is_topic_deletion_disabled_error(self)
4884 }
4885
4886 /// Returns whether this error's Java class is, or extends,
4887 /// `org.apache.kafka.common.errors.TopicExistsException`.
4888 ///
4889 /// Prefer this to matching [`Error::TopicExists`](Self::TopicExists): a variant match misses
4890 /// the subclasses a later Java release may add.
4891 pub fn is_topic_exists_error(&self) -> bool {
4892 ErrorHierarchy::is_topic_exists_error(self)
4893 }
4894
4895 /// Returns whether this error's Java class is, or extends,
4896 /// `org.apache.kafka.common.errors.TransactionAbortableException`.
4897 ///
4898 /// Prefer this to matching [`Error::TransactionAbortable`](Self::TransactionAbortable): a
4899 /// variant match misses the subclasses a later Java release may add.
4900 ///
4901 /// Java tests this class in two ways: by code (`error == Errors.TRANSACTION_ABORTABLE`,
4902 /// four sites in `TransactionManager`) and by class
4903 /// (`error.exception() instanceof TransactionAbortableException`,
4904 /// in `TransactionManager`). This predicate is the class test.
4905 pub fn is_transaction_abortable_error(&self) -> bool {
4906 ErrorHierarchy::is_transaction_abortable_error(self)
4907 }
4908
4909 /// Returns whether this error's Java class is, or extends,
4910 /// `org.apache.kafka.common.errors.TransactionAbortedException`.
4911 ///
4912 /// Prefer this to matching [`Error::TransactionAborted`](Self::TransactionAborted): a variant
4913 /// match misses the subclasses a later Java release may add.
4914 pub fn is_transaction_aborted_error(&self) -> bool {
4915 ErrorHierarchy::is_transaction_aborted_error(self)
4916 }
4917
4918 /// Returns whether this error's Java class is, or extends,
4919 /// `org.apache.kafka.common.errors.TransactionCoordinatorFencedException`.
4920 ///
4921 /// Prefer this to matching
4922 /// [`Error::TransactionCoordinatorFenced`](Self::TransactionCoordinatorFenced): a variant match
4923 /// misses the subclasses a later Java release may add.
4924 pub fn is_transaction_coordinator_fenced_error(&self) -> bool {
4925 ErrorHierarchy::is_transaction_coordinator_fenced_error(self)
4926 }
4927
4928 /// Returns whether this error's Java class is, or extends,
4929 /// `org.apache.kafka.common.errors.TransactionalIdAuthorizationException`.
4930 ///
4931 /// Prefer this to matching
4932 /// [`Error::TransactionalIdAuthorization`](Self::TransactionalIdAuthorization): a variant match
4933 /// misses the subclasses a later Java release may add.
4934 pub fn is_transactional_id_authorization_error(&self) -> bool {
4935 ErrorHierarchy::is_transactional_id_authorization_error(self)
4936 }
4937
4938 /// Returns whether this error's Java class is, or extends,
4939 /// `org.apache.kafka.common.errors.TransactionalIdNotFoundException`.
4940 ///
4941 /// Prefer this to matching [`Error::TransactionalIdNotFound`](Self::TransactionalIdNotFound): a
4942 /// variant match misses the subclasses a later Java release may add.
4943 pub fn is_transactional_id_not_found_error(&self) -> bool {
4944 ErrorHierarchy::is_transactional_id_not_found_error(self)
4945 }
4946
4947 /// Returns whether this error's Java class is, or extends,
4948 /// `org.apache.kafka.common.errors.UnacceptableCredentialException`.
4949 ///
4950 /// Prefer this to matching [`Error::UnacceptableCredential`](Self::UnacceptableCredential): a
4951 /// variant match misses the subclasses a later Java release may add.
4952 pub fn is_unacceptable_credential_error(&self) -> bool {
4953 ErrorHierarchy::is_unacceptable_credential_error(self)
4954 }
4955
4956 /// Returns whether this error's Java class is, or extends,
4957 /// `org.apache.kafka.common.errors.UnknownControllerIdException`.
4958 ///
4959 /// Prefer this to matching [`Error::UnknownControllerId`](Self::UnknownControllerId): a variant
4960 /// match misses the subclasses a later Java release may add.
4961 pub fn is_unknown_controller_id_error(&self) -> bool {
4962 ErrorHierarchy::is_unknown_controller_id_error(self)
4963 }
4964
4965 /// Returns whether this error's Java class is, or extends,
4966 /// `org.apache.kafka.common.errors.UnknownLeaderEpochException`.
4967 ///
4968 /// Prefer this to matching [`Error::UnknownLeaderEpoch`](Self::UnknownLeaderEpoch): a variant
4969 /// match misses the subclasses a later Java release may add.
4970 pub fn is_unknown_leader_epoch_error(&self) -> bool {
4971 ErrorHierarchy::is_unknown_leader_epoch_error(self)
4972 }
4973
4974 /// Returns whether this error's Java class is, or extends,
4975 /// `org.apache.kafka.common.errors.UnknownMemberIdException`.
4976 ///
4977 /// Prefer this to matching [`Error::UnknownMemberId`](Self::UnknownMemberId): a variant match
4978 /// misses the subclasses a later Java release may add.
4979 pub fn is_unknown_member_id_error(&self) -> bool {
4980 ErrorHierarchy::is_unknown_member_id_error(self)
4981 }
4982
4983 /// Returns whether this error's Java class is, or extends,
4984 /// `org.apache.kafka.common.errors.UnknownProducerIdException`.
4985 ///
4986 /// Prefer this to matching [`Error::UnknownProducerId`](Self::UnknownProducerId): a variant
4987 /// match misses the subclasses a later Java release may add.
4988 pub fn is_unknown_producer_id_error(&self) -> bool {
4989 ErrorHierarchy::is_unknown_producer_id_error(self)
4990 }
4991
4992 /// Returns whether this error's Java class is, or extends,
4993 /// `org.apache.kafka.common.errors.UnknownServerException`.
4994 ///
4995 /// Prefer this to matching [`Error::UnknownServer`](Self::UnknownServer): a variant match
4996 /// misses the subclasses a later Java release may add.
4997 pub fn is_unknown_server_error(&self) -> bool {
4998 ErrorHierarchy::is_unknown_server_error(self)
4999 }
5000
5001 /// Returns whether this error's Java class is, or extends,
5002 /// `org.apache.kafka.common.errors.UnknownSubscriptionIdException`.
5003 ///
5004 /// Prefer this to matching [`Error::UnknownSubscriptionId`](Self::UnknownSubscriptionId): a
5005 /// variant match misses the subclasses a later Java release may add.
5006 pub fn is_unknown_subscription_id_error(&self) -> bool {
5007 ErrorHierarchy::is_unknown_subscription_id_error(self)
5008 }
5009
5010 /// Returns whether this error's Java class is, or extends,
5011 /// `org.apache.kafka.common.errors.UnknownTopicIdException`.
5012 ///
5013 /// Prefer this to matching [`Error::UnknownTopicId`](Self::UnknownTopicId): a variant match
5014 /// misses the subclasses a later Java release may add.
5015 pub fn is_unknown_topic_id_error(&self) -> bool {
5016 ErrorHierarchy::is_unknown_topic_id_error(self)
5017 }
5018
5019 /// Returns whether this error's Java class is, or extends,
5020 /// `org.apache.kafka.common.errors.UnknownTopicOrPartitionException`.
5021 ///
5022 /// Prefer this to matching [`Error::UnknownTopicOrPartition`](Self::UnknownTopicOrPartition): a
5023 /// variant match misses the subclasses a later Java release may add.
5024 pub fn is_unknown_topic_or_partition_error(&self) -> bool {
5025 ErrorHierarchy::is_unknown_topic_or_partition_error(self)
5026 }
5027
5028 /// Returns whether this error's Java class is, or extends,
5029 /// `org.apache.kafka.common.errors.UnreleasedInstanceIdException`.
5030 ///
5031 /// Prefer this to matching [`Error::UnreleasedInstanceId`](Self::UnreleasedInstanceId): a
5032 /// variant match misses the subclasses a later Java release may add.
5033 pub fn is_unreleased_instance_id_error(&self) -> bool {
5034 ErrorHierarchy::is_unreleased_instance_id_error(self)
5035 }
5036
5037 /// Returns whether this error's Java class is, or extends,
5038 /// `org.apache.kafka.common.errors.UnstableOffsetCommitException`.
5039 ///
5040 /// Prefer this to matching [`Error::UnstableOffsetCommit`](Self::UnstableOffsetCommit): a
5041 /// variant match misses the subclasses a later Java release may add.
5042 pub fn is_unstable_offset_commit_error(&self) -> bool {
5043 ErrorHierarchy::is_unstable_offset_commit_error(self)
5044 }
5045
5046 /// Returns whether this error's Java class is, or extends,
5047 /// `org.apache.kafka.common.errors.UnsupportedAssignorException`.
5048 ///
5049 /// Prefer this to matching [`Error::UnsupportedAssignor`](Self::UnsupportedAssignor): a variant
5050 /// match misses the subclasses a later Java release may add.
5051 pub fn is_unsupported_assignor_error(&self) -> bool {
5052 ErrorHierarchy::is_unsupported_assignor_error(self)
5053 }
5054
5055 /// Returns whether this error's Java class is, or extends,
5056 /// `org.apache.kafka.common.errors.UnsupportedByAuthenticationException`.
5057 ///
5058 /// Prefer this to matching
5059 /// [`Error::UnsupportedByAuthentication`](Self::UnsupportedByAuthentication): a variant match
5060 /// misses the subclasses a later Java release may add.
5061 pub fn is_unsupported_by_authentication_error(&self) -> bool {
5062 ErrorHierarchy::is_unsupported_by_authentication_error(self)
5063 }
5064
5065 /// Returns whether this error's Java class is, or extends,
5066 /// `org.apache.kafka.common.errors.UnsupportedCompressionTypeException`.
5067 ///
5068 /// Prefer this to matching
5069 /// [`Error::UnsupportedCompressionType`](Self::UnsupportedCompressionType): a variant match
5070 /// misses the subclasses a later Java release may add.
5071 pub fn is_unsupported_compression_type_error(&self) -> bool {
5072 ErrorHierarchy::is_unsupported_compression_type_error(self)
5073 }
5074
5075 /// Returns whether this error's Java class is, or extends,
5076 /// `org.apache.kafka.common.errors.UnsupportedEndpointTypeException`.
5077 ///
5078 /// Prefer this to matching [`Error::UnsupportedEndpointType`](Self::UnsupportedEndpointType): a
5079 /// variant match misses the subclasses a later Java release may add.
5080 pub fn is_unsupported_endpoint_type_error(&self) -> bool {
5081 ErrorHierarchy::is_unsupported_endpoint_type_error(self)
5082 }
5083
5084 /// Returns whether this error's Java class is, or extends,
5085 /// `org.apache.kafka.common.errors.UnsupportedForMessageFormatException`.
5086 ///
5087 /// Prefer this to matching
5088 /// [`Error::UnsupportedForMessageFormat`](Self::UnsupportedForMessageFormat): a variant match
5089 /// misses the subclasses a later Java release may add.
5090 pub fn is_unsupported_for_message_format_error(&self) -> bool {
5091 ErrorHierarchy::is_unsupported_for_message_format_error(self)
5092 }
5093
5094 /// Returns whether this error's Java class is, or extends,
5095 /// `org.apache.kafka.common.errors.UnsupportedSaslMechanismException`.
5096 ///
5097 /// Prefer this to matching [`Error::UnsupportedSaslMechanism`](Self::UnsupportedSaslMechanism):
5098 /// a variant match misses the subclasses a later Java release may add.
5099 pub fn is_unsupported_sasl_mechanism_error(&self) -> bool {
5100 ErrorHierarchy::is_unsupported_sasl_mechanism_error(self)
5101 }
5102
5103 /// Returns whether this error's Java class extends `UnsupportedVersionException`.
5104 ///
5105 /// Exactly the [`UnsupportedVersion`](Self::UnsupportedVersion) variant
5106 /// (`Errors::UnsupportedVersion`). Java's subclasses —
5107 /// `UnsupportedProtocolFieldException` (Kafka 4.4, KAFKA-18157) and the
5108 /// `NoBatchedFindCoordinatorsException` / `NoBatchedOffsetFetchRequestException`
5109 /// nested in `FindCoordinatorRequest` / `OffsetFetchRequest` — are none of
5110 /// them public, so they are carried inside that variant rather than as
5111 /// variants of their own; this predicate therefore answers `true` for them
5112 /// too, as Java's `instanceof UnsupportedVersionException` does.
5113 ///
5114 /// Nested inside [`is_invalid_configuration_error`](Self::is_invalid_configuration_error),
5115 /// because `UnsupportedVersionException extends InvalidConfigurationException`.
5116 /// The set is pinned in both directions over every code by `errors.rs`'s
5117 /// `test_hierarchy_predicates_match_java`.
5118 ///
5119 /// Prefer this to matching [`Error::UnsupportedVersion`](Self::UnsupportedVersion): a variant
5120 /// match misses the subclasses a later Java release may add.
5121 pub fn is_unsupported_version_error(&self) -> bool {
5122 ErrorHierarchy::is_unsupported_version_error(self)
5123 }
5124
5125 /// Returns whether this error's Java class is, or extends,
5126 /// `org.apache.kafka.common.errors.VoterNotFoundException`.
5127 ///
5128 /// Prefer this to matching [`Error::VoterNotFound`](Self::VoterNotFound): a variant match
5129 /// misses the subclasses a later Java release may add.
5130 pub fn is_voter_not_found_error(&self) -> bool {
5131 ErrorHierarchy::is_voter_not_found_error(self)
5132 }
5133
5134 /// Returns whether this error's Java class is, or extends,
5135 /// `org.apache.kafka.common.errors.WakeupException`.
5136 ///
5137 /// Prefer this to matching [`Error::Wakeup`](Self::Wakeup): a variant match misses the
5138 /// subclasses a later Java release may add.
5139 pub fn is_wakeup_error(&self) -> bool {
5140 ErrorHierarchy::is_wakeup_error(self)
5141 }
5142}
5143
5144// `impl Display for Error` is generated by `#[delegate(Display)]` on the enum:
5145// each variant forwards to its payload's own `Display`, which renders the way
5146// that payload's Java class implements `toString()`.
5147
5148impl std::error::Error for Error {
5149 // The standard-library view of Java's `Throwable.getCause()`, so
5150 // `{:#}`-style reporters and `anyhow`-style chains walk the cause chain.
5151 fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
5152 // UFCS: `self.source()` would resolve to the inherent method below.
5153 ErrorSource::source(self).map(|e| e as &(dyn std::error::Error + 'static))
5154 }
5155}
5156
5157#[cfg(test)]
5158mod tests {
5159 use super::*;
5160
5161 /// Java's `getCause()` is declared on `Throwable`, so every error answers it;
5162 /// the Rust-side name follows the std trait (`source`). `None` is the common
5163 /// case (Java's null default); a source set through a constructor is readable
5164 /// back, and `std::error::Error::source()` agrees with the inherent accessor.
5165 ///
5166 /// The inherent `source()` shadows both `ErrorSource::source` and
5167 /// `std::error::Error::source`, so `e.source()` is unambiguous and returns the
5168 /// **typed** `Option<&Error>`; the `dyn` view is reachable through the trait
5169 /// and downcasts back to `Error`.
5170 #[test]
5171 fn source_is_universal_and_readable() {
5172 use std::error::Error as StdError;
5173
5174 // Default: no cause, on both a macro-declared class and the base.
5175 assert!(Error::new(Errors::RequestTimedOut).source().is_none());
5176 assert!(Error::local_illegal_state("misuse").source().is_none());
5177 assert!(StdError::source(&Error::new(Errors::RequestTimedOut)).is_none());
5178
5179 // Set through `KafkaError`'s Java-shaped `(String, Throwable)` constructor.
5180 let root = Error::new(Errors::ClusterAuthorizationFailed);
5181 let wrapped = Error::KafkaError(KafkaError::with_message_source(
5182 Errors::UnknownServerError,
5183 "Cannot execute transactional method because we are in an error state",
5184 root,
5185 ));
5186 let source = wrapped.source().expect("the source is retained");
5187 assert_eq!(source.error(), Errors::ClusterAuthorizationFailed);
5188 // The std view agrees, so `source()` chains resolve.
5189 assert!(StdError::source(&wrapped).is_some());
5190 // The wrapper keeps its own code and message.
5191 assert_eq!(wrapped.error(), Errors::UnknownServerError);
5192
5193 // A macro-declared class carries one too (every class has the slot).
5194 let serialization = Error::Serialization(SerializationError::with_source(
5195 "bad bytes",
5196 Error::local_illegal_argument("not utf-8"),
5197 ));
5198 assert_eq!(serialization.source().expect("retained").message(), "not utf-8");
5199
5200 // The chain is walkable to arbitrary depth.
5201 let outer = Error::KafkaError(KafkaError::with_source(Errors::UnknownServerError, serialization));
5202 let mid = outer.source().expect("first link");
5203 assert_eq!(mid.message(), "bad bytes");
5204 assert_eq!(mid.source().expect("second link").message(), "not utf-8");
5205
5206 // The inherent accessor is typed; the std trait's view is `dyn` but
5207 // downcasts straight back to the enum, so nothing is lost either way.
5208 let typed: Option<&Error> = outer.source();
5209 let via_dyn: Option<&Error> = StdError::source(&outer).and_then(|e| e.downcast_ref::<Error>());
5210 assert_eq!(typed.map(Error::message), via_dyn.map(Error::message));
5211 assert!(
5212 matches!(via_dyn, Some(Error::Serialization(_))),
5213 "the concrete variant survives the round-trip"
5214 );
5215
5216 // A `&dyn Error` chain walks the same two levels.
5217 let mut depth = 0;
5218 let mut cursor: Option<&(dyn StdError + 'static)> = StdError::source(&outer);
5219 while let Some(e) = cursor {
5220 depth += 1;
5221 cursor = e.source();
5222 }
5223 assert_eq!(depth, 2, "walking the dyn chain sees both links");
5224
5225 // Classes whose Java counterpart has no `Throwable cause` constructor
5226 // answer `None` — fidelity, not omission.
5227 assert!(
5228 Error::ConsumerCommitFailed(crate::consumer::ConsumerCommitFailedError::with_default_message())
5229 .source()
5230 .is_none()
5231 );
5232 }
5233
5234 /// [`Error::kafka`] must produce a *bare* `KafkaException`, not the
5235 /// `UnknownServerException` that [`Error::with_message`] resolves
5236 /// [`Errors::UnknownServerError`] to.
5237 ///
5238 /// The difference is observable and load-bearing: `KafkaProducer.doSend`
5239 /// dispatches on `catch (ApiException e)` (fire the callback, return a failed
5240 /// future) versus `catch (KafkaException e)` (rethrow), so translating a bare
5241 /// `new KafkaException(..)` through `with_message` silently moves the error into
5242 /// the wrong arm.
5243 #[test]
5244 fn kafka_builds_a_bare_kafka_error_not_an_api_error() {
5245 let bare = Error::kafka_message("Producer closed while send in progress");
5246 assert!(matches!(bare, Error::KafkaError(_)), "got {bare:?}");
5247 assert!(bare.is_kafka_error());
5248 // Java: a bare `KafkaException` is not an `ApiException`.
5249 assert!(!bare.is_api_error(), "a bare Kafka error is not an API error");
5250 assert_eq!(bare.message(), "Producer closed while send in progress");
5251 assert_eq!(bare.error(), Errors::UnknownServerError, "no protocol code of its own");
5252
5253 // The contrast, and why the helper exists.
5254 let resolved = Error::with_message(Errors::UnknownServerError, "same code, different class");
5255 assert!(matches!(resolved, Error::UnknownServer(_)), "got {resolved:?}");
5256 // Java: `UnknownServerException` IS an `ApiException`.
5257 assert!(resolved.is_api_error(), "an unknown-server error IS an API error");
5258
5259 // The `(String, Throwable)` form carries the cause.
5260 let wrapped =
5261 Error::kafka_message_source("Failed to construct kafka producer", Error::config_message("bad ssl path"));
5262 assert!(!wrapped.is_api_error());
5263 assert_eq!(wrapped.message(), "Failed to construct kafka producer");
5264 assert_eq!(wrapped.source().expect("cause retained").message(), "bad ssl path");
5265 }
5266
5267 /// `RetriableCommitFailedException(Throwable)` keeps its cause in Java; the
5268 /// Rust translation used to accept and discard it.
5269 #[test]
5270 fn retriable_commit_failed_retains_its_source() {
5271 let e = Error::ConsumerRetriableCommitFailed(crate::consumer::ConsumerRetriableCommitFailedError::with_source(
5272 Error::timeout("commit timed out"),
5273 ));
5274 assert_eq!(e.source().expect("retained").message(), "commit timed out");
5275 }
5276
5277 /// `LocalConcurrentModification` mirrors `LocalIllegalState`: a plain Java
5278 /// `RuntimeException`, so it carries no protocol code, is never
5279 /// retriable or fatal, and is neither an `ApiException` nor a
5280 /// `KafkaException`.
5281 #[test]
5282 fn concurrent_modification_parity_with_illegal_state() {
5283 let cme = Error::local_concurrent_modification("KafkaConsumer is not safe for multi-threaded access.");
5284 let ise = Error::local_illegal_state("bad state");
5285
5286 assert_eq!(cme.message(), "KafkaConsumer is not safe for multi-threaded access.");
5287 assert_eq!(cme.error().code(), ise.error().code());
5288 assert_eq!(cme.error(), ise.error());
5289 assert_eq!(cme.is_retriable_error(), ise.is_retriable_error());
5290 assert!(!cme.is_retriable_error());
5291 assert_eq!(
5292 crate::common::requests::RequestUtils::is_fatal_error(&cme),
5293 crate::common::requests::RequestUtils::is_fatal_error(&ise)
5294 );
5295 assert!(!crate::common::requests::RequestUtils::is_fatal_error(&cme));
5296 assert_eq!(cme.is_api_error(), ise.is_api_error());
5297 assert!(!cme.is_api_error());
5298 assert_eq!(cme.is_kafka_error(), ise.is_kafka_error());
5299 assert!(!cme.is_kafka_error());
5300 assert!(cme.kafka_error().is_none());
5301 }
5302
5303 /// `LocalUnsupportedOperation` mirrors `LocalIllegalState` too: Java's
5304 /// `UnsupportedOperationException` is a plain `RuntimeException`. It must
5305 /// not be confused with the wire-level `UnsupportedVersionException`, which
5306 /// is an `ApiException` and fatal (`RequestUtils.isFatalException`).
5307 #[test]
5308 fn unsupported_operation_parity_with_illegal_state() {
5309 let uoe = Error::local_unsupported_operation("Not implemented yet");
5310 let ise = Error::local_illegal_state("bad state");
5311
5312 assert_eq!(uoe.message(), "Not implemented yet");
5313 assert_eq!(uoe.to_string(), "LocalUnsupportedOperationError: Not implemented yet");
5314 assert_eq!(uoe.error(), ise.error());
5315 assert!(uoe.is_local_unsupported_operation_error());
5316 assert!(!ise.is_local_unsupported_operation_error());
5317 assert!(!uoe.is_local_illegal_state_error());
5318 assert_eq!(uoe.is_retriable_error(), ise.is_retriable_error());
5319 assert!(!uoe.is_retriable_error());
5320 assert!(!crate::common::requests::RequestUtils::is_fatal_error(&uoe));
5321 assert!(!uoe.is_api_error());
5322 assert!(!uoe.is_kafka_error());
5323 assert!(uoe.kafka_error().is_none());
5324
5325 // The wire-level class it replaces at the `UnsupportedOperationException`
5326 // sites is a different class in both directions.
5327 let version = Error::unsupported_version("Not implemented yet");
5328 assert!(!uoe.is_unsupported_version_error());
5329 assert!(!version.is_local_unsupported_operation_error());
5330 assert!(version.is_api_error());
5331 assert!(crate::common::requests::RequestUtils::is_fatal_error(&version));
5332
5333 // Java's no-argument `new UnsupportedOperationException()`.
5334 let bare = Error::local_unsupported_operation("");
5335 assert_eq!(bare.message(), "");
5336 assert_eq!(bare.to_string(), "LocalUnsupportedOperationError: ");
5337 }
5338
5339 /// `LocalNullPointer` is Java's `NullPointerException`, a plain
5340 /// `RuntimeException` beside `KafkaException`, distinct from
5341 /// `IllegalArgumentException` in both directions.
5342 #[test]
5343 fn null_pointer_parity_with_illegal_state() {
5344 let npe = Error::local_null_pointer("topic must not be null");
5345 let iae = Error::local_illegal_argument("topic must not be null");
5346 assert_eq!(npe.message(), "topic must not be null");
5347 assert_eq!(npe.to_string(), "LocalNullPointerError: topic must not be null");
5348 assert!(npe.is_local_null_pointer_error());
5349 assert!(!iae.is_local_null_pointer_error());
5350 assert!(!npe.is_local_illegal_argument_error());
5351 assert!(!npe.is_local_illegal_state_error());
5352 assert!(!npe.is_retriable_error());
5353 assert!(!crate::common::requests::RequestUtils::is_fatal_error(&npe));
5354 assert!(!npe.is_api_error());
5355 assert!(!npe.is_kafka_error());
5356 assert!(npe.kafka_error().is_none());
5357 }
5358
5359 #[test]
5360 fn concurrent_modification_display() {
5361 let cme = Error::local_concurrent_modification("oops");
5362 assert_eq!(cme.to_string(), "LocalConcurrentModificationError: oops");
5363 }
5364
5365 /// Every [`Error`] variant against its Java `extends` chain, in both
5366 /// directions.
5367 ///
5368 /// The predicates are no longer computed by matching on the enum — each is
5369 /// delegated to the variant's payload, whose `impl ErrorHierarchy` declares
5370 /// its ancestry. This table is what stops a payload from silently claiming
5371 /// (or dropping) a superclass, which a per-variant `assert!` could not.
5372 ///
5373 /// Order: kafka, api, retriable, refresh_retriable, timeout,
5374 /// invalid_metadata, invalid_configuration, application_recoverable,
5375 /// invalid_offset, consumer_invalid_offset, consumer_offset_out_of_range,
5376 /// out_of_order_sequence, serialization, authentication, authorization,
5377 /// fatal, unsupported_version — the same order the assertion message below
5378 /// spells out, and the order the `actual` array is built in.
5379 #[test]
5380 fn variant_predicates_match_java_hierarchy() {
5381 use std::collections::HashMap;
5382 let cases: &[(&str, Error, [bool; 17])] = &[
5383 // The three concrete intermediate classes the flattened enum has to
5384 // carry as variants of their own: Java lets a caller `throw new
5385 // ApiException(msg)` / `new AuthenticationException(msg)` /
5386 // `new AuthorizationException(msg)` directly, and none of the three
5387 // has an entry in `Errors.java`, so no code reaches them. They are
5388 // the rows `TransactionExceptionHierarchyTest
5389 // .testInvalidConfigurationExceptionHierarchy` asserts for the two
5390 // base classes.
5391 // ApiException -> KafkaException
5392 (
5393 "Api",
5394 Error::Api(ApiError::new("generic")),
5395 [
5396 true, true, false, false, false, false, false, false, false, false, false, false, false, false,
5397 false, false, false,
5398 ],
5399 ),
5400 // AuthenticationException -> InvalidConfigurationException -> ApiException
5401 // -> KafkaException, and fatal per `RequestUtils.isFatalException`.
5402 (
5403 "Authentication",
5404 Error::Authentication(AuthenticationError::new("bad credentials")),
5405 [
5406 true, true, false, false, false, false, true, false, false, false, false, false, false, true,
5407 false, true, false,
5408 ],
5409 ),
5410 // AuthorizationException -> InvalidConfigurationException -> ApiException
5411 // -> KafkaException, and fatal per `RequestUtils.isFatalException`.
5412 (
5413 "Authorization",
5414 Error::Authorization(AuthorizationError::new("not authorized")),
5415 [
5416 true, true, false, false, false, false, true, false, false, false, false, false, false, false,
5417 true, true, false,
5418 ],
5419 ),
5420 // TopicAuthorizationException -> AuthorizationException -> ApiException -> KafkaException
5421 (
5422 "TopicAuthorization",
5423 Error::topic_authorization(HashSet::new()),
5424 [
5425 true, true, false, false, false, false, true, false, false, false, false, false, false, false,
5426 true, true, false,
5427 ],
5428 ),
5429 // GroupAuthorizationException -> AuthorizationException -> ApiException -> KafkaException
5430 (
5431 "GroupAuthorization",
5432 Error::group_authorization("g"),
5433 [
5434 true, true, false, false, false, false, true, false, false, false, false, false, false, false,
5435 true, true, false,
5436 ],
5437 ),
5438 // InvalidTopicException -> ApiException -> KafkaException
5439 (
5440 "InvalidTopic",
5441 Error::invalid_topics(HashSet::new()),
5442 [
5443 true, true, false, false, false, false, true, false, false, false, false, false, false, false,
5444 false, false, false,
5445 ],
5446 ),
5447 // ThrottlingQuotaExceededException -> RetriableException -> ApiException -> KafkaException
5448 (
5449 "ThrottlingQuotaExceeded",
5450 Error::throttling_quota_exceeded(1, "throttled"),
5451 [
5452 true, true, true, false, false, false, false, false, false, false, false, false, false, false,
5453 false, false, false,
5454 ],
5455 ),
5456 // BufferExhaustedException -> TimeoutException -> RetriableException
5457 // -> ApiException -> KafkaException. It extends TimeoutException, so
5458 // it is retriable — and it reports REQUEST_TIMED_OUT, because Java's
5459 // `Errors.forException` walks up the superclass chain to find a code.
5460 (
5461 "BufferExhausted",
5462 Error::buffer_exhausted("full"),
5463 [
5464 true, true, true, false, true, false, false, false, false, false, false, false, false, false,
5465 false, false, false,
5466 ],
5467 ),
5468 // TimeoutException -> RetriableException -> ApiException -> KafkaException
5469 (
5470 "Timeout",
5471 Error::timeout("late"),
5472 [
5473 true, true, true, false, true, false, false, false, false, false, false, false, false, false,
5474 false, false, false,
5475 ],
5476 ),
5477 // RecordTooLargeException -> ApiException -> KafkaException
5478 (
5479 "RecordTooLarge",
5480 Error::record_too_large("big"),
5481 [
5482 true, true, false, false, false, false, false, false, false, false, false, false, false, false,
5483 false, false, false,
5484 ],
5485 ),
5486 // SchemaException -> KafkaException (NOT an ApiException), like
5487 // `SerializationException`.
5488 (
5489 "Schema",
5490 Error::schema("Buffer underflow"),
5491 [
5492 true, false, false, false, false, false, false, false, false, false, false, false, false, false,
5493 false, false, false,
5494 ],
5495 ),
5496 // CorrelationIdMismatchException -> java.lang.IllegalStateException:
5497 // outside the hierarchy entirely, so it reads like the `LocalIllegalState`
5498 // row below rather than like a `KafkaException`.
5499 (
5500 "CorrelationIdMismatch",
5501 Error::correlation_id_mismatch("ids disagree", 7, 9),
5502 [
5503 false, false, false, false, false, false, false, false, false, false, false, false, false, false,
5504 false, false, false,
5505 ],
5506 ),
5507 // SerializationException -> KafkaException (NOT an ApiException)
5508 (
5509 "Serialization",
5510 Error::serialization("bad"),
5511 [
5512 true, false, false, false, false, false, false, false, false, false, false, false, true, false,
5513 false, false, false,
5514 ],
5515 ),
5516 // WakeupException -> KafkaException (NOT an ApiException)
5517 (
5518 "Wakeup",
5519 Error::wakeup("woken"),
5520 [
5521 true, false, false, false, false, false, false, false, false, false, false, false, false, false,
5522 false, false, false,
5523 ],
5524 ),
5525 // BootstrapResolutionException -> KafkaException (NOT an ApiException,
5526 // KIP-909): non-wire, so it answers only `is_kafka_error`.
5527 (
5528 "BootstrapResolution",
5529 Error::BootstrapResolution(BootstrapResolutionError::new("unresolvable")),
5530 [
5531 true, false, false, false, false, false, false, false, false, false, false, false, false, false,
5532 false, false, false,
5533 ],
5534 ),
5535 // The three codes Kafka 4.4 adds are plain ApiExceptions, not fatal.
5536 // GroupDeletionFailedException -> ApiException -> KafkaException
5537 (
5538 "GroupDeletionFailed (from the code)",
5539 Error::new(Errors::GroupDeletionFailed),
5540 [
5541 true, true, false, false, false, false, false, false, false, false, false, false, false, false,
5542 false, false, false,
5543 ],
5544 ),
5545 // StreamsTopologyDescriptionUpdateFailedException -> ApiException -> KafkaException
5546 (
5547 "StreamsTopologyDescriptionUpdateFailed (from the code)",
5548 Error::new(Errors::StreamsTopologyDescriptionUpdateFailed),
5549 [
5550 true, true, false, false, false, false, false, false, false, false, false, false, false, false,
5551 false, false, false,
5552 ],
5553 ),
5554 // ControllerIdNotRegisteredException -> ApiException -> KafkaException
5555 (
5556 "ControllerIdNotRegistered (from the code)",
5557 Error::new(Errors::ControllerIdNotRegistered),
5558 [
5559 true, true, false, false, false, false, false, false, false, false, false, false, false, false,
5560 false, false, false,
5561 ],
5562 ),
5563 // java.lang / java.util runtime exceptions: outside the hierarchy entirely.
5564 (
5565 "LocalIllegalArgument",
5566 Error::local_illegal_argument("bad arg"),
5567 [
5568 false, false, false, false, false, false, false, false, false, false, false, false, false, false,
5569 false, false, false,
5570 ],
5571 ),
5572 (
5573 "LocalIllegalState",
5574 Error::local_illegal_state("bad state"),
5575 [
5576 false, false, false, false, false, false, false, false, false, false, false, false, false, false,
5577 false, false, false,
5578 ],
5579 ),
5580 (
5581 "LocalConcurrentModification",
5582 Error::local_concurrent_modification("racy"),
5583 [
5584 false, false, false, false, false, false, false, false, false, false, false, false, false, false,
5585 false, false, false,
5586 ],
5587 ),
5588 (
5589 "LocalTimeout",
5590 Error::local_timeout("timed out"),
5591 [
5592 false, false, false, false, false, false, false, false, false, false, false, false, false, false,
5593 false, false, false,
5594 ],
5595 ),
5596 // `java.lang.UnsupportedOperationException`: NOT the wire-level
5597 // `UnsupportedVersionException`, so `unsupported_version` (and with
5598 // it `fatal`) is false too.
5599 (
5600 "LocalUnsupportedOperation",
5601 Error::local_unsupported_operation("not implemented"),
5602 [
5603 false, false, false, false, false, false, false, false, false, false, false, false, false, false,
5604 false, false, false,
5605 ],
5606 ),
5607 // `java.lang.NullPointerException`: a plain `RuntimeException`.
5608 (
5609 "LocalNullPointer",
5610 Error::local_null_pointer("self_ must not be null"),
5611 [
5612 false, false, false, false, false, false, false, false, false, false, false, false, false, false,
5613 false, false, false,
5614 ],
5615 ),
5616 // A foreign callback's error: no Java class, outside the hierarchy
5617 // like the runtime exceptions above.
5618 (
5619 "LocalCallback",
5620 Error::local_callback("ValueError: bad", std::ptr::null_mut()),
5621 [
5622 false, false, false, false, false, false, false, false, false, false, false, false, false, false,
5623 false, false, false,
5624 ],
5625 ),
5626 // A bare `KafkaException`: inside the hierarchy, but the parent of
5627 // `ApiException` rather than an instance of it, so it answers `true`
5628 // to `is_kafka_error` and `false` to every other predicate.
5629 (
5630 "KafkaError",
5631 Error::kafka_message("Producer closed while send in progress"),
5632 [
5633 true, false, false, false, false, false, false, false, false, false, false, false, false, false,
5634 false, false, false,
5635 ],
5636 ),
5637 // Consumer-package classes: `LogTruncationException extends
5638 // OffsetOutOfRangeException extends InvalidOffsetException`, so a
5639 // log truncation answers `true` to both consumer predicates — Java's
5640 // `catch (OffsetOutOfRangeException e)` catches it.
5641 (
5642 "ConsumerOffsetOutOfRange",
5643 Error::ConsumerOffsetOutOfRange(ConsumerOffsetOutOfRangeError::new(HashMap::new())),
5644 [
5645 true, false, false, false, false, false, false, false, false, true, true, false, false, false,
5646 false, false, false,
5647 ],
5648 ),
5649 (
5650 "ConsumerLogTruncation",
5651 Error::ConsumerLogTruncation(Box::new(ConsumerLogTruncationError::new(HashMap::new(), HashMap::new()))),
5652 [
5653 true, false, false, false, false, false, false, false, false, true, true, false, false, false,
5654 false, false, false,
5655 ],
5656 ),
5657 // `CommitFailedException extends KafkaException` — not an ApiException.
5658 (
5659 "ConsumerCommitFailed",
5660 Error::ConsumerCommitFailed(ConsumerCommitFailedError::new("m")),
5661 [
5662 true, false, false, false, false, false, false, false, false, false, false, false, false, false,
5663 false, false, false,
5664 ],
5665 ),
5666 // `Error::new(code)` resolves the code to its own class (Java's
5667 // `Errors.exception()`), so these two rows check the classes the
5668 // wire codes name — NOT the bare `KafkaError` variant, which
5669 // `Error::new` now only yields for `Errors::None`.
5670 // NOT_LEADER_OR_FOLLOWER: InvalidMetadataException -> RefreshRetriableException
5671 // -> RetriableException -> ApiException -> KafkaException.
5672 (
5673 "NotLeaderOrFollower (from the code)",
5674 Error::new(Errors::NotLeaderOrFollower),
5675 [
5676 true, true, true, true, false, true, false, false, false, false, false, false, false, false, false,
5677 false, false,
5678 ],
5679 ),
5680 // SASL_AUTHENTICATION_FAILED: AuthenticationException -> ApiException, and fatal.
5681 (
5682 "SaslAuthenticationFailed (from the code)",
5683 Error::new(Errors::SaslAuthenticationFailed),
5684 [
5685 true, true, false, false, false, false, true, false, false, false, false, false, false, true,
5686 false, true, false,
5687 ],
5688 ),
5689 // UNSUPPORTED_VERSION: UnsupportedVersionException -> InvalidConfigurationException
5690 // -> ApiException -> KafkaException, and fatal per `RequestUtils.isFatalException`.
5691 // Intermediate (already in 4.3.1, through the `NoBatched*`
5692 // subclasses); Kafka 4.4 adds the `UnsupportedProtocolFieldException`
5693 // subclass, a crate-private kind of the same variant that answers alike.
5694 (
5695 "UnsupportedVersion (from the code)",
5696 Error::new(Errors::UnsupportedVersion),
5697 [
5698 true, true, false, false, false, false, true, false, false, false, false, false, false, false,
5699 false, true, true,
5700 ],
5701 ),
5702 (
5703 "UnsupportedProtocolField (crate-private subclass)",
5704 crate::common::internals::UnsupportedProtocolFieldError::with_message("m"),
5705 [
5706 true, true, false, false, false, false, true, false, false, false, false, false, false, false,
5707 false, true, true,
5708 ],
5709 ),
5710 ];
5711
5712 for (name, err, expected) in cases {
5713 let actual = [
5714 err.is_kafka_error(),
5715 err.is_api_error(),
5716 err.is_retriable_error(),
5717 err.is_refresh_retriable_error(),
5718 err.is_timeout_error(),
5719 err.is_invalid_metadata_error(),
5720 err.is_invalid_configuration_error(),
5721 err.is_application_recoverable_error(),
5722 err.is_invalid_offset_error(),
5723 err.is_consumer_invalid_offset_error(),
5724 err.is_consumer_offset_out_of_range_error(),
5725 err.is_out_of_order_sequence_error(),
5726 err.is_serialization_error(),
5727 err.is_authentication_error(),
5728 err.is_authorization_error(),
5729 crate::common::requests::RequestUtils::is_fatal_error(err),
5730 err.is_unsupported_version_error(),
5731 ];
5732 assert_eq!(
5733 &actual, expected,
5734 "{name}: predicate vector diverges from the Java extends chain \
5735 (order: kafka, api, retriable, refresh_retriable, timeout, invalid_metadata, invalid_configuration, application_recoverable, invalid_offset, consumer_invalid_offset, consumer_offset_out_of_range, out_of_order_sequence, serialization, authentication, authorization, fatal, unsupported_version)"
5736 );
5737 }
5738 }
5739
5740 /// `message()` and `Display` are two different Java methods and must stay
5741 /// that way: `Throwable.getMessage()` returns the bare text, while
5742 /// `Throwable.toString()` is `getClass().getName() + ": " + message`.
5743 ///
5744 /// Both are delegated to the payload now, so this pins each variant's pair
5745 /// and, for the message-only errors, that `Display` is exactly
5746 /// `"<TypeName>: <message>"`.
5747 #[test]
5748 fn message_is_the_bare_text_and_display_adds_the_class_name() {
5749 let message_only: &[(&str, Error)] = &[
5750 ("LocalIllegalArgumentError", Error::local_illegal_argument("boom")),
5751 ("LocalIllegalStateError", Error::local_illegal_state("boom")),
5752 ("LocalConcurrentModificationError", Error::local_concurrent_modification("boom")),
5753 ("LocalUnsupportedOperationError", Error::local_unsupported_operation("boom")),
5754 ("LocalNullPointerError", Error::local_null_pointer("boom")),
5755 ("TimeoutError", Error::timeout("boom")),
5756 ("RecordTooLargeError", Error::record_too_large("boom")),
5757 ("SerializationError", Error::serialization("boom")),
5758 ("WakeupError", Error::wakeup("boom")),
5759 ];
5760 for (type_name, err) in message_only {
5761 assert_eq!(err.message(), "boom", "{type_name}: message() must be the bare text");
5762 assert_eq!(
5763 err.to_string(),
5764 format!("{type_name}: boom"),
5765 "{type_name}: Display must prefix the class name"
5766 );
5767 }
5768
5769 // Payloads wrapping a `KafkaError` report its message — the custom one
5770 // when set, otherwise the error code's default text. The old `message()`
5771 // reached these through a `_ =>` arm whose "Unknown error" fallback was
5772 // unreachable; delegation makes each payload answer for itself.
5773 assert_eq!(
5774 Error::new(Errors::RequestTimedOut).message(),
5775 Errors::RequestTimedOut.message(),
5776 "bare KafkaError falls back to the code's default text"
5777 );
5778 assert_eq!(
5779 Error::with_message(Errors::RequestTimedOut, "custom").message(),
5780 "custom",
5781 "a custom message wins over the code's default"
5782 );
5783 assert_eq!(Error::buffer_exhausted("pool full").message(), "pool full");
5784 assert_eq!(
5785 Error::group_authorization_with_message("g1", "not authorized").message(),
5786 "not authorized"
5787 );
5788 assert_eq!(Error::throttling_quota_exceeded(42, "throttled").message(), "throttled");
5789
5790 // The three stateful auth/topic classes format their state into the
5791 // message, exactly as Java's single-argument constructors /
5792 // `forGroupId` do — so it appears in BOTH message() and Display.
5793 // (Java: `TopicAuthorizationException(Set)` ->
5794 // `"Not authorized to access topics: " + set`.)
5795 let topic_auth = Error::topic_authorization(HashSet::from(["t1".to_string()]));
5796 assert_eq!(topic_auth.message(), "Not authorized to access topics: [t1]");
5797 assert_eq!(
5798 topic_auth.to_string(),
5799 "TopicAuthorizationError: Not authorized to access topics: [t1]"
5800 );
5801
5802 let group_auth = Error::group_authorization("g1");
5803 assert_eq!(group_auth.message(), "Not authorized to access group: g1");
5804 assert_eq!(
5805 group_auth.to_string(),
5806 "GroupAuthorizationError: Not authorized to access group: g1"
5807 );
5808
5809 let invalid_topics = Error::invalid_topics(HashSet::from(["t1".to_string()]));
5810 assert_eq!(invalid_topics.message(), "Invalid topics: [t1]");
5811 assert_eq!(invalid_topics.to_string(), "InvalidTopicError: Invalid topics: [t1]");
5812
5813 // The `Errors` registry (`exception()` path) still yields the code's
5814 // default message with empty state, matching Java's `::new` builder.
5815 assert_eq!(
5816 Errors::TopicAuthorizationFailed.error().unwrap().message(),
5817 Errors::TopicAuthorizationFailed.message()
5818 );
5819 assert_eq!(
5820 Errors::GroupAuthorizationFailed.error().unwrap().message(),
5821 Errors::GroupAuthorizationFailed.message()
5822 );
5823 assert_eq!(
5824 Errors::InvalidTopicError.error().unwrap().message(),
5825 Errors::InvalidTopicError.message()
5826 );
5827 }
5828
5829 /// The classes translated into `common::errors` answer their own code and
5830 /// ancestry, without an embedded [`KafkaError`].
5831 ///
5832 /// `TimeoutError` moving into that module is a deliberate behaviour change:
5833 /// it used to carry no code, so `code()` was `-1`. Java associates a code
5834 /// with an exception *class* (`Errors.forException`, `CLASS_TO_ERROR`), and
5835 /// `REQUEST_TIMED_OUT` maps to `TimeoutException` — including for
5836 /// client-side timeouts, which is why the code is unconditional.
5837 #[test]
5838 fn translated_classes_answer_their_own_code() {
5839 use crate::common::errors::{NetworkError, NotCoordinatorError, TimeoutError};
5840
5841 let timeout = Error::timeout("late");
5842 assert_eq!(timeout.error(), Errors::RequestTimedOut);
5843 // Java: `TimeoutException` carries `Errors.REQUEST_TIMED_OUT`.
5844 assert_eq!(timeout.error().code(), 7, "a timeout error is Errors.REQUEST_TIMED_OUT");
5845 assert_eq!(timeout.message(), "late");
5846 assert!(timeout.is_retriable_error());
5847
5848 // `with_default_message()` is Java's `Errors.exception()`: the literal
5849 // stays on the `Errors` constant and is handed to the class.
5850 let defaulted = TimeoutError::with_default_message();
5851 assert_eq!(defaulted.message(), Errors::RequestTimedOut.message());
5852
5853 // NetworkException extends InvalidMetadataException extends
5854 // RefreshRetriableException extends RetriableException.
5855 let net = NetworkError::new("disconnected");
5856 assert_eq!(ErrorCode::error(&net), Errors::NetworkError);
5857 assert!(ErrorHierarchy::is_invalid_metadata_error(&net));
5858 assert!(ErrorHierarchy::is_refresh_retriable_error(&net));
5859 assert!(ErrorHierarchy::is_retriable_error(&net));
5860 assert_eq!(net.to_string(), "NetworkError: disconnected");
5861
5862 // NotCoordinatorException is RefreshRetriable but NOT InvalidMetadata.
5863 let nc = NotCoordinatorError::new("wrong coordinator");
5864 assert!(ErrorHierarchy::is_refresh_retriable_error(&nc));
5865 assert!(!ErrorHierarchy::is_invalid_metadata_error(&nc));
5866
5867 // ThrottlingQuotaExceededError keeps its extra field through the move.
5868 let throttled = Error::throttling_quota_exceeded(250, "slow down");
5869 assert_eq!(throttled.throttle_time_ms(), Some(250));
5870 assert_eq!(throttled.error(), Errors::ThrottlingQuotaExceeded);
5871 assert!(throttled.is_retriable_error());
5872 }
5873
5874 /// `Error::KafkaError` now means a *bare* `KafkaException` — every code maps
5875 /// to its own class through [`Errors::error`], so the variant is only reached
5876 /// for [`Errors::None`] or by constructing it directly.
5877 ///
5878 /// It is therefore NOT an `ApiException`: `KafkaException` is that class's
5879 /// parent, not an instance of it. While the variant stood in for every coded
5880 /// error it had to answer `true`, which is the assumption this pins closed.
5881 #[test]
5882 fn bare_kafka_error_is_not_an_api_error() {
5883 let bare = Error::KafkaError(KafkaError::new(Errors::None));
5884 assert!(bare.is_kafka_error());
5885 // Java: `KafkaException` is `ApiException`'s parent, not an instance of it.
5886 assert!(!bare.is_api_error(), "a bare Kafka error is the parent class, not an API error");
5887 assert!(!bare.is_retriable_error());
5888 assert!(!crate::common::requests::RequestUtils::is_fatal_error(&bare));
5889
5890 // A code no longer produces this variant at all.
5891 assert!(matches!(Error::new(Errors::NetworkError), Error::Network(_)));
5892 assert!(matches!(Error::new(Errors::None), Error::KafkaError(_)));
5893 }
5894
5895 /// `is_transaction_abortable_error` is the class predicate for a leaf class.
5896 /// It is still an [`ErrorHierarchy`] method, so that a subclass Java adds
5897 /// later answers `true` too.
5898 ///
5899 /// Note the confusable neighbour: `TransactionAbortableException` (code 120,
5900 /// "you may abort and carry on") is a different Java class from
5901 /// `TransactionAbortedException` (no code, "the transaction was aborted, the
5902 /// record was not written").
5903 #[test]
5904 fn transaction_abortable_is_a_class_predicate() {
5905 let abortable = Error::new(Errors::TransactionAbortable);
5906 assert!(abortable.is_transaction_abortable_error());
5907 assert_eq!(abortable.error().code(), 120);
5908
5909 // Different class, despite the near-identical name.
5910 let aborted = Error::TransactionAborted(TransactionAbortedError::new("aborted"));
5911 assert!(!aborted.is_transaction_abortable_error());
5912
5913 for other in [
5914 Error::timeout("x"),
5915 Error::new(Errors::NetworkError),
5916 Error::local_illegal_state("x"),
5917 ] {
5918 assert!(!other.is_transaction_abortable_error(), "{other:?}");
5919 }
5920 }
5921
5922 /// A `KafkaException` subclass is always a `KafkaException`, and anything
5923 /// retriable through a refresh is retriable. Guards against a payload
5924 /// overriding a narrow predicate while forgetting its ancestors.
5925 #[test]
5926 fn predicate_nesting_holds_for_every_variant() {
5927 let errors = [
5928 Error::topic_authorization(HashSet::new()),
5929 Error::group_authorization("g"),
5930 Error::invalid_topics(HashSet::new()),
5931 Error::throttling_quota_exceeded(1, "throttled"),
5932 Error::buffer_exhausted("full"),
5933 Error::timeout("late"),
5934 Error::record_too_large("big"),
5935 Error::serialization("bad"),
5936 Error::wakeup("woken"),
5937 Error::local_illegal_argument("bad arg"),
5938 Error::local_illegal_state("bad state"),
5939 Error::local_concurrent_modification("racy"),
5940 Error::local_unsupported_operation("not implemented"),
5941 Error::local_null_pointer("self_ must not be null"),
5942 Error::new(Errors::NotLeaderOrFollower),
5943 Error::new(Errors::SaslAuthenticationFailed),
5944 Error::ConsumerOffsetOutOfRange(ConsumerOffsetOutOfRangeError::new(std::collections::HashMap::new())),
5945 Error::ConsumerLogTruncation(Box::new(ConsumerLogTruncationError::new(
5946 std::collections::HashMap::new(),
5947 std::collections::HashMap::new(),
5948 ))),
5949 Error::buffer_exhausted("pool full"),
5950 ];
5951
5952 for err in &errors {
5953 if err.is_api_error() {
5954 // Java: `ApiException extends KafkaException`.
5955 assert!(err.is_kafka_error(), "{err}: an API error must be a Kafka error");
5956 }
5957 if err.is_retriable_error() {
5958 // Java: `RetriableException extends ApiException`.
5959 assert!(err.is_api_error(), "{err}: a retriable error must be an API error");
5960 }
5961 if err.is_refresh_retriable_error() {
5962 assert!(err.is_retriable_error(), "{err}: RefreshRetriable must be Retriable");
5963 }
5964 if err.is_invalid_metadata_error() {
5965 assert!(
5966 err.is_refresh_retriable_error(),
5967 "{err}: InvalidMetadata must be RefreshRetriable"
5968 );
5969 }
5970 if err.is_authentication_error() || err.is_authorization_error() {
5971 // Kafka 4.2: both extend InvalidConfigurationException, NOT
5972 // ApiException directly.
5973 assert!(
5974 err.is_invalid_configuration_error(),
5975 "{err}: auth/authz errors must be invalid-configuration errors"
5976 );
5977 assert!(
5978 crate::common::requests::RequestUtils::is_fatal_error(err),
5979 "{err}: auth/authz errors are fatal"
5980 );
5981 assert!(!err.is_retriable_error(), "{err}: auth/authz errors are not retriable");
5982 }
5983 if err.is_invalid_configuration_error()
5984 || err.is_application_recoverable_error()
5985 || err.is_invalid_offset_error()
5986 || err.is_out_of_order_sequence_error()
5987 {
5988 assert!(
5989 err.is_api_error(),
5990 "{err}: invalid-configuration / application-recoverable / invalid-offset / \
5991 out-of-order-sequence errors are all API errors"
5992 );
5993 }
5994 if err.is_timeout_error() {
5995 // TimeoutException extends RetriableException.
5996 assert!(err.is_retriable_error(), "{err}: a timeout error is retriable");
5997 }
5998 if err.is_unsupported_version_error() {
5999 // UnsupportedVersionException extends InvalidConfigurationException.
6000 assert!(
6001 err.is_invalid_configuration_error(),
6002 "{err}: an unsupported-version error is an invalid-configuration error"
6003 );
6004 }
6005 if err.is_consumer_offset_out_of_range_error() {
6006 // consumer OffsetOutOfRangeException extends consumer
6007 // InvalidOffsetException.
6008 assert!(
6009 err.is_consumer_invalid_offset_error(),
6010 "{err}: a consumer offset-out-of-range error is a consumer invalid-offset error"
6011 );
6012 }
6013 if err.is_consumer_invalid_offset_error() {
6014 // The consumer's InvalidOffsetException extends KafkaException,
6015 // NOT ApiException — unlike the common.errors class of the same
6016 // name.
6017 assert!(err.is_kafka_error(), "{err}: a consumer invalid-offset error is a Kafka error");
6018 assert!(
6019 !err.is_api_error(),
6020 "{err}: a consumer invalid-offset error is NOT an API error"
6021 );
6022 }
6023 if err.is_serialization_error() {
6024 // SerializationException extends KafkaException directly.
6025 assert!(err.is_kafka_error(), "{err}: a serialization error is a Kafka error");
6026 assert!(!err.is_api_error(), "{err}: a serialization error is NOT an API error");
6027 }
6028 }
6029 }
6030 // -----------------------------------------------------------------------
6031 // TransactionExceptionHierarchyTest.java (Apache Kafka 4.2,
6032 // clients/src/test/java/org/apache/kafka/common/errors/
6033 // TransactionExceptionHierarchyTest.java)
6034 //
6035 // Java asserts on `Class.isAssignableFrom`, which it can do because the
6036 // hierarchy is the type system. Rust has no subclassing, so the flattened
6037 // enum answers through the payload's `extends:` list — these four tests are
6038 // that list checked against Java's, class by class, over exactly the Java
6039 // `@ValueSource` sets. Each parameterized method becomes a loop, per DoD #3.
6040 //
6041 // Java names two classes that this crate carries as `Error` variants with no
6042 // protocol code — `AuthenticationException` and `AuthorizationException` —
6043 // and they are the reason this file is translated rather than left to the
6044 // code-level tables in `protocol/errors.rs`, which can only reach classes a
6045 // wire code names.
6046 // -----------------------------------------------------------------------
6047
6048 /// `testRetriableExceptionHierarchy`: these six extend `RetriableException`
6049 /// and must NOT extend `RefreshRetriableException`.
6050 ///
6051 /// Java's javadoc gives the stake: "Using `RefreshRetriableException`
6052 /// changes the exception handling behavior, so only exceptions extending
6053 /// `RetriableException` directly are considered valid here."
6054 #[test]
6055 fn transaction_hierarchy_retriable_classes() {
6056 let classes: &[(&str, Error)] = &[
6057 ("TimeoutError", Error::Timeout(TimeoutError::new("m"))),
6058 (
6059 "NotEnoughReplicasError",
6060 Error::NotEnoughReplicas(NotEnoughReplicasError::new("m")),
6061 ),
6062 (
6063 "CoordinatorLoadInProgressError",
6064 Error::CoordinatorLoadInProgress(CoordinatorLoadInProgressError::new("m")),
6065 ),
6066 ("CorruptRecordError", Error::CorruptRecord(CorruptRecordError::new("m"))),
6067 (
6068 "NotEnoughReplicasAfterAppendError",
6069 Error::NotEnoughReplicasAfterAppend(NotEnoughReplicasAfterAppendError::new("m")),
6070 ),
6071 (
6072 "ConcurrentTransactionsError",
6073 Error::ConcurrentTransactions(ConcurrentTransactionsError::new("m")),
6074 ),
6075 ];
6076 for (name, error) in classes {
6077 assert!(error.is_retriable_error(), "{name} should be a retriable error");
6078 assert!(
6079 !error.is_refresh_retriable_error(),
6080 "{name} should NOT be a refresh-retriable error"
6081 );
6082 }
6083 }
6084
6085 /// `testRefreshRetriableException`: `RefreshRetriableException extends
6086 /// RetriableException`.
6087 ///
6088 /// Java asserts it on the intermediate class itself. The flattened enum has
6089 /// no such class, so the equivalent statement is that the nesting holds for
6090 /// every error: nothing may answer `true` to the child predicate and `false`
6091 /// to the parent's. Asserted over the same class set the next test uses,
6092 /// plus every protocol code — the code-level half is also covered by
6093 /// `errors.rs`'s `test_hierarchy_predicates_nest`.
6094 #[test]
6095 fn transaction_hierarchy_refresh_retriable_is_retriable() {
6096 for code in -1i16..=200 {
6097 let error = Errors::for_code(code);
6098 if let Some(error) = error.error() {
6099 assert!(
6100 !error.is_refresh_retriable_error() || error.is_retriable_error(),
6101 "{error:?}: a refresh-retriable error should also be a retriable error"
6102 );
6103 }
6104 }
6105 }
6106
6107 /// `testRefreshRetriableExceptionHierarchy`: these four extend
6108 /// `RefreshRetriableException` — and therefore `RetriableException`.
6109 #[test]
6110 fn transaction_hierarchy_refresh_retriable_classes() {
6111 let classes: &[(&str, Error)] = &[
6112 (
6113 "UnknownTopicOrPartitionError",
6114 Error::UnknownTopicOrPartition(UnknownTopicOrPartitionError::new("m")),
6115 ),
6116 (
6117 "NotLeaderOrFollowerError",
6118 Error::NotLeaderOrFollower(NotLeaderOrFollowerError::new("m")),
6119 ),
6120 ("NotCoordinatorError", Error::NotCoordinator(NotCoordinatorError::new("m"))),
6121 (
6122 "CoordinatorNotAvailableError",
6123 Error::CoordinatorNotAvailable(CoordinatorNotAvailableError::new("m")),
6124 ),
6125 ];
6126 for (name, error) in classes {
6127 assert!(error.is_refresh_retriable_error(), "{name} should be a refresh-retriable error");
6128 assert!(error.is_retriable_error(), "{name} should be a retriable error");
6129 }
6130 }
6131
6132 /// `testApplicationRecoverableExceptionHierarchy`: these six extend
6133 /// `ApplicationRecoverableException`.
6134 #[test]
6135 fn transaction_hierarchy_application_recoverable_classes() {
6136 let classes: &[(&str, Error)] = &[
6137 (
6138 "FencedInstanceIdError",
6139 Error::FencedInstanceId(FencedInstanceIdError::new("m")),
6140 ),
6141 (
6142 "IllegalGenerationError",
6143 Error::IllegalGeneration(IllegalGenerationError::new("m")),
6144 ),
6145 (
6146 "InvalidPidMappingError",
6147 Error::InvalidPidMapping(InvalidPidMappingError::new("m")),
6148 ),
6149 (
6150 "InvalidProducerEpochError",
6151 Error::InvalidProducerEpoch(InvalidProducerEpochError::new("m")),
6152 ),
6153 ("ProducerFencedError", Error::ProducerFenced(ProducerFencedError::new("m"))),
6154 ("UnknownMemberIdError", Error::UnknownMemberId(UnknownMemberIdError::new("m"))),
6155 ];
6156 for (name, error) in classes {
6157 assert!(
6158 error.is_application_recoverable_error(),
6159 "{name} should be an application-recoverable error"
6160 );
6161 }
6162 }
6163
6164 /// `testInvalidConfigurationExceptionHierarchy`: these twelve extend
6165 /// `InvalidConfigurationException`.
6166 ///
6167 /// Wider than the name suggests: in Kafka 4.2 both `AuthenticationException`
6168 /// and `AuthorizationException` extend it, which is why the two authorization
6169 /// subclasses and the two concrete bases are in Java's `@ValueSource`.
6170 /// [`Error::Authentication`] and [`Error::Authorization`] appear in no other
6171 /// predicate test — a wire code cannot reach them.
6172 #[test]
6173 fn transaction_hierarchy_invalid_configuration_classes() {
6174 let classes: &[(&str, Error)] = &[
6175 ("AuthenticationError", Error::Authentication(AuthenticationError::new("m"))),
6176 ("AuthorizationError", Error::Authorization(AuthorizationError::new("m"))),
6177 (
6178 "ClusterAuthorizationError",
6179 Error::ClusterAuthorization(ClusterAuthorizationError::new("m")),
6180 ),
6181 (
6182 "TransactionalIdAuthorizationError",
6183 Error::TransactionalIdAuthorization(TransactionalIdAuthorizationError::new("m")),
6184 ),
6185 (
6186 "UnsupportedVersionError",
6187 Error::UnsupportedVersion(UnsupportedVersionError::new("m")),
6188 ),
6189 (
6190 "UnsupportedForMessageFormatError",
6191 Error::UnsupportedForMessageFormat(UnsupportedForMessageFormatError::new("m")),
6192 ),
6193 ("InvalidRecordError", Error::InvalidRecord(InvalidRecordError::new("m"))),
6194 (
6195 "InvalidRequiredAcksError",
6196 Error::InvalidRequiredAcks(InvalidRequiredAcksError::new("m")),
6197 ),
6198 (
6199 "RecordBatchTooLargeError",
6200 Error::RecordBatchTooLarge(RecordBatchTooLargeError::new("m")),
6201 ),
6202 ("InvalidTopicError", Error::invalid_topics(HashSet::from(["t".to_string()]))),
6203 (
6204 "TopicAuthorizationError",
6205 Error::topic_authorization(HashSet::from(["t".to_string()])),
6206 ),
6207 ("GroupAuthorizationError", Error::group_authorization("g")),
6208 ];
6209 for (name, error) in classes {
6210 assert!(
6211 error.is_invalid_configuration_error(),
6212 "{name} should be an invalid-configuration error"
6213 );
6214 }
6215 }
6216}