kacrab_protocol/version/error.rs
1//! Error types for [`crate::version`].
2//!
3//! Two distinct failure modes, each a plain struct rather than an enum variant:
4//! [`UnsupportedVersion`] (the negotiated range was empty / a decoder rejected an
5//! unknown version) and [`UnsupportedFieldVersion`] (a field was set while
6//! encoding a version that does not carry it). Context fields are always
7//! populated.
8
9/// API version negotiation produced no mutually-supported version, or a
10/// generated decoder rejected an unknown version.
11#[derive(Debug, Clone, Copy, PartialEq, Eq, thiserror::Error)]
12#[error("unsupported version: api_key={api_key}, version={version}")]
13#[non_exhaustive]
14pub struct UnsupportedVersion {
15 /// Kafka API key (numeric form).
16 pub api_key: i16,
17 /// The version that was rejected.
18 pub version: i16,
19}
20
21impl UnsupportedVersion {
22 /// Construct a new `UnsupportedVersion`.
23 #[must_use]
24 pub const fn new(api_key: i16, version: i16) -> Self {
25 Self { api_key, version }
26 }
27}
28
29/// A field was set while encoding a protocol version where that field does not
30/// exist.
31#[derive(Debug, Clone, Copy, PartialEq, Eq, thiserror::Error)]
32#[error("unsupported field version: api_key={api_key}, field={field}, version={version}")]
33#[non_exhaustive]
34pub struct UnsupportedFieldVersion {
35 /// Kafka API key (numeric form).
36 pub api_key: i16,
37 /// Generated Rust field name.
38 pub field: &'static str,
39 /// The version that does not carry this field.
40 pub version: i16,
41}
42
43impl UnsupportedFieldVersion {
44 /// Construct a new `UnsupportedFieldVersion`.
45 #[must_use]
46 pub const fn new(api_key: i16, field: &'static str, version: i16) -> Self {
47 Self {
48 api_key,
49 field,
50 version,
51 }
52 }
53}