use printobserver_printer_api::PrinterError;
use printobserver_store_api::StoreError;
use printobserver_supervisor_api::SupervisorError;
use printobserver_types::PrintId;
use printobserver_vision_api::VisionError;
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum CoreError {
Store(StoreError),
Printer(PrinterError),
Vision(VisionError),
Supervisor(SupervisorError),
NoSuchPrint {
print_id: PrintId,
},
Unrepresentable {
detail: String,
},
}
impl core::fmt::Display for CoreError {
fn fmt(&self, formatter: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
match self {
Self::Store(error) => write!(formatter, "the store failed: {error}"),
Self::Printer(error) => write!(formatter, "the printer failed: {error}"),
Self::Vision(error) => write!(formatter, "the vision port failed: {error}"),
Self::Supervisor(error) => write!(formatter, "the supervisor failed: {error}"),
Self::NoSuchPrint { print_id } => write!(formatter, "there is no print {print_id}"),
Self::Unrepresentable { detail } => {
write!(formatter, "an instant is not representable: {detail}")
}
}
}
}
impl core::error::Error for CoreError {}
impl From<StoreError> for CoreError {
fn from(error: StoreError) -> Self {
Self::Store(error)
}
}