use std::{error::Error, fmt};
use kafka_driver::{BootstrapError, CompletionError, DriverBuildError, ReactorError, SubmitError};
#[cfg(test)]
use super::EngineSecurityError;
use super::EndpointError;
#[derive(Debug)]
pub(crate) enum DriverOwnerError {
#[cfg(test)]
Security(EngineSecurityError),
Endpoint {
index: usize,
source: EndpointError,
},
Bootstrap(BootstrapError),
Build(DriverBuildError),
Reactor(ReactorError),
UnrecognizedTurnOutcome,
ShutdownSubmit(SubmitError),
ShutdownCompletion(CompletionError),
ShutdownTurnExhausted,
}
impl fmt::Display for DriverOwnerError {
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
#[cfg(test)]
Self::Security(source) => write!(formatter, "invalid security configuration: {source}"),
Self::Endpoint { index, source } => {
write!(
formatter,
"invalid bootstrap endpoint at index {index}: {source}"
)
}
Self::Bootstrap(source) => write!(formatter, "invalid bootstrap set: {source}"),
Self::Build(source) => write!(formatter, "failed to build embedded driver: {source}"),
Self::Reactor(source) => write!(formatter, "embedded driver turn failed: {source}"),
Self::UnrecognizedTurnOutcome => {
formatter.write_str("embedded driver returned an unrecognized turn outcome")
}
Self::ShutdownSubmit(source) => {
write!(formatter, "driver shutdown request was rejected: {source}")
}
Self::ShutdownCompletion(source) => {
write!(formatter, "driver shutdown barrier failed: {source}")
}
Self::ShutdownTurnExhausted => {
formatter.write_str("driver shutdown exceeded its bounded terminal turns")
}
}
}
}
impl Error for DriverOwnerError {
fn source(&self) -> Option<&(dyn Error + 'static)> {
match self {
#[cfg(test)]
Self::Security(source) => Some(source),
Self::Endpoint { source, .. } => Some(source),
Self::Bootstrap(source) => Some(source),
Self::Build(source) => Some(source),
Self::Reactor(source) => Some(source),
Self::UnrecognizedTurnOutcome => None,
Self::ShutdownSubmit(source) => Some(source),
Self::ShutdownCompletion(source) => Some(source),
Self::ShutdownTurnExhausted => None,
}
}
}