use crate::storage::StorageError; use thiserror::Error; #[derive(Debug, Error)] pub enum Error { #[error("database: {0}")] Storage(#[from] StorageError), #[error("I/O: {0}")] Io(#[from] std::io::Error), #[error("task panicked: {0}")] TaskPanic(#[from] tokio::task::JoinError), #[error(transparent)] Resync(#[from] crate::sync::resync::ResyncError), #[error("collection mortality: {0}")] MstMortality(#[from] crate::mst::mortality::MstMortalityError), #[error("{0}")] Other(String), } impl Error { /// True if this error indicates the database is in an unrecoverable state. /// /// `fjall::Error::Poisoned` is fjall's signal that a prior flush/commit /// failed and subsequent writes can't be trusted — fjall's own docs say /// to crash the application. `Unrecoverable` is a similar terminal state. /// Callers should force-exit the process rather than attempt graceful /// shutdown, since the blocking thread pool may be stuck on the same /// underlying failure. pub fn is_db_fatal(&self) -> bool { matches!( self, Error::Storage(StorageError::Fjall( fjall::Error::Poisoned | fjall::Error::Unrecoverable )) ) } } pub type Result = std::result::Result;