#[non_exhaustive]pub enum Error {
Transport {
context: &'static str,
source: Error,
},
ConnectionClosed {
peer: String,
},
Timeout {
api_key: ApiKey,
elapsed: Duration,
},
Authentication(String),
Authorization(ErrorCode),
Broker {
code: ErrorCode,
message: Option<String>,
},
Decode {
context: &'static str,
source: Box<dyn Error + Sync + Send>,
},
ReadOnly {
api_key: ApiKey,
},
UnsupportedApi {
api_key: ApiKey,
broker: Option<(i16, i16)>,
ours: Option<(i16, i16)>,
},
Unsupported(String),
InvalidRequest(String),
}Expand description
The error taxonomy, re-exported.
One type across the workspace: see the crate docs for why it is defined a layer down. Anything that can go wrong talking to a broker.
Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
Transport
The socket failed, or never opened.
ConnectionClosed
The connection is gone. Every in-flight request resolves to this rather than hanging — a UI backend that leaks a hung future per dead broker stops working long before anyone notices why.
Timeout
The caller’s deadline passed.
Authentication(String)
The credentials were rejected, or the handshake could not agree.
Authorization(ErrorCode)
The principal authenticated but is not permitted to do this.
Broker
The broker answered with an error code.
Fields
Decode
A response did not parse.
Distinct from every other variant because it means we are wrong: a version negotiated badly, or a schema drifted.
Fields
ReadOnly
A read-only client refused a mutating request before touching the
network. See ApiKey::is_mutating.
UnsupportedApi
No version of this API is speakable by both ends.
Usually our side is the binding one: kafka-protocol 0.17 ships
Kafka 4.0 schemas and the broker is newer.
Fields
Unsupported(String)
The caller asked for something the protocol or this build cannot express — an unnamed API key, a sentinel that needs a schema version we cannot encode. An honest blocker, not a workaround.
InvalidRequest(String)
A request was malformed before it went out.
Implementations§
Source§impl Error
impl Error
Sourcepub fn transport(context: &'static str, source: Error) -> Error
pub fn transport(context: &'static str, source: Error) -> Error
Wrap an I/O error with context.
Sourcepub fn decode(
context: &'static str,
source: impl Into<Box<dyn Error + Sync + Send>>,
) -> Error
pub fn decode( context: &'static str, source: impl Into<Box<dyn Error + Sync + Send>>, ) -> Error
Wrap a decode failure with context.
Sourcepub fn from_code(code: ErrorCode, message: Option<String>) -> Error
pub fn from_code(code: ErrorCode, message: Option<String>) -> Error
Build the right variant for a broker error code.
Authentication and authorization codes are lifted out of
Error::Broker here rather than at every call site, because a caller
that forgets renders “not authorized” as a generic failure.
Sourcepub fn retriable(&self) -> bool
pub fn retriable(&self) -> bool
Whether retrying could plausibly succeed.
A dead connection counts: the pool will open a new one. A decode failure does not — retrying a schema mismatch just burns the same bytes again.
Sourcepub fn needs_metadata_refresh(&self) -> bool
pub fn needs_metadata_refresh(&self) -> bool
Whether handling this error should refresh the metadata snapshot.
Sourcepub fn needs_coordinator_refresh(&self) -> bool
pub fn needs_coordinator_refresh(&self) -> bool
Whether handling this error should invalidate a cached coordinator.
Trait Implementations§
Source§impl Clone for Error
One failure often has to be reported to many callers: every record in a
rejected produce batch, every partition in a request whose connection died.
Without Clone each of those sites has to invent a way to fan an error out,
and they invent different ones.
impl Clone for Error
One failure often has to be reported to many callers: every record in a
rejected produce batch, every partition in a request whose connection died.
Without Clone each of those sites has to invent a way to fan an error out,
and they invent different ones.
Two variants cannot be duplicated faithfully and are reconstructed:
Error::Transportkeeps itsstd::io::ErrorKindand its rendering, but a clonedio::Errorloses the raw OS error code.Error::Decodekeeps its source’s rendering rather than its concrete type, so downcasting the clone will not find the original.
Everything Error::retriable, Error::code,
Error::needs_metadata_refresh and Display read is preserved exactly,
which is the whole of what callers branch on. Derived rather than hand-
written is not an option — io::Error and a boxed source are not Clone.
Source§impl Error for Error
impl Error for Error
Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
use the Display impl or to_string()