use std::path::PathBuf;
use thiserror::Error;
#[derive(Debug, Error)]
pub enum EngineError {
#[error("I/O error: {0}")]
Io(#[from] std::io::Error),
#[error("Journal error: {0}")]
Journal(#[from] journal_core::JournalError),
#[error("Index error: {0}")]
Index(#[from] journal_index::IndexError),
#[error("Repository error: {0}")]
Repository(#[from] journal_registry::repository::RepositoryError),
#[error("Registry error: {0}")]
Registry(#[from] journal_registry::RegistryError),
#[error("Failed to parse journal file path: {path}")]
InvalidPath { path: String },
#[error("Path contains invalid UTF-8: {}", .path.display())]
InvalidUtf8 { path: PathBuf },
#[error("Channel closed")]
ChannelClosed,
#[error("Cache error: {0}")]
Foyer(#[source] Box<foyer::Error>),
#[error("Operation cancelled")]
Cancelled,
#[error("Invalid time range: start={start} >= end={end}")]
InvalidTimeRange { start: u32, end: u32 },
}
impl From<foyer::Error> for EngineError {
fn from(error: foyer::Error) -> Self {
Self::Foyer(Box::new(error))
}
}
static_assertions::const_assert!(std::mem::size_of::<EngineError>() <= 64);
pub type Result<T> = std::result::Result<T, EngineError>;
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn foyer_errors_are_boxed_within_the_engine_error_size_bound() {
let error = foyer::Error::new(foyer::ErrorKind::Config, "test error");
let error = EngineError::from(error);
assert!(matches!(error, EngineError::Foyer(_)));
assert!(std::mem::size_of::<EngineError>() <= 64);
}
}