use std::fmt;
use crate::{
config::EngineConfigError, consumer::AssignedConsumerOwnerBuildError, driver::DriverOwnerError,
producer::ProducerHostStartError,
};
mod host;
mod host_display;
#[cfg(test)]
mod host_display_test;
#[cfg(test)]
mod host_test;
pub(crate) use host::EngineHostError;
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum EngineStartErrorKind {
Configuration,
Driver,
Producer,
Admin,
Consumer,
HostThread,
HostHandoff,
}
#[derive(Debug)]
pub struct EngineStartError {
kind: EngineStartErrorKind,
detail: String,
}
impl EngineStartError {
pub const fn kind(&self) -> EngineStartErrorKind {
self.kind
}
pub(crate) fn configuration(error: EngineConfigError) -> Self {
Self::new(
EngineStartErrorKind::Configuration,
format!("invalid engine configuration: {error:?}"),
)
}
pub(super) fn driver(error: &DriverOwnerError) -> Self {
Self::new(EngineStartErrorKind::Driver, error.to_string())
}
pub(super) fn producer(error: &ProducerHostStartError) -> Self {
Self::new(EngineStartErrorKind::Producer, error.to_string())
}
pub(super) fn admin_notifier(error: &std::io::Error) -> Self {
Self::new(
EngineStartErrorKind::Admin,
format!("failed to start shared admin completion notifier: {error}"),
)
}
pub(super) fn assigned_consumer_notifier(error: &std::io::Error) -> Self {
Self::new(
EngineStartErrorKind::Consumer,
format!("failed to start assigned-consumer completion notifier: {error}"),
)
}
pub(super) fn assigned_consumer(error: AssignedConsumerOwnerBuildError) -> Self {
Self::new(
EngineStartErrorKind::Consumer,
format!("failed to start assigned consumer: {error:?}"),
)
}
pub(super) fn group_consumer(error: &std::io::Error) -> Self {
Self::new(
EngineStartErrorKind::Consumer,
format!("failed to start group-consumer registry: {error}"),
)
}
pub(super) fn transaction_notifier(error: &std::io::Error) -> Self {
Self::new(
EngineStartErrorKind::Producer,
format!("failed to start transaction completion notifier: {error}"),
)
}
pub(super) fn host_thread(error: &std::io::Error) -> Self {
Self::new(
EngineStartErrorKind::HostThread,
format!("failed to start engine host thread: {error}"),
)
}
pub(super) fn handoff() -> Self {
Self::new(
EngineStartErrorKind::HostHandoff,
"engine host stopped before accepting startup ownership".to_owned(),
)
}
fn new(kind: EngineStartErrorKind, detail: String) -> Self {
Self { kind, detail }
}
}
impl fmt::Display for EngineStartError {
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
formatter.write_str(&self.detail)
}
}
impl std::error::Error for EngineStartError {}
#[derive(Clone, Debug)]
pub struct EngineShutdownError {
kind: EngineShutdownErrorKind,
detail: String,
}
impl EngineShutdownError {
pub(crate) fn host(error: &EngineHostError) -> Self {
Self {
kind: EngineShutdownErrorKind::Host,
detail: error.to_string(),
}
}
pub(crate) fn notifier_thread() -> Self {
Self {
kind: EngineShutdownErrorKind::NotifierThread,
detail: "shutdown was requested from the completion notifier; terminal cleanup \
continues after the callback returns"
.to_owned(),
}
}
pub const fn kind(&self) -> EngineShutdownErrorKind {
self.kind
}
}
impl fmt::Display for EngineShutdownError {
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
formatter.write_str(&self.detail)
}
}
impl std::error::Error for EngineShutdownError {}
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum EngineShutdownErrorKind {
Host,
NotifierThread,
}