1use std::path::PathBuf;
4use thiserror::Error;
5
6#[derive(Debug, Error)]
8pub enum EngineError {
9 #[error("I/O error: {0}")]
11 Io(#[from] std::io::Error),
12
13 #[error("Journal error: {0}")]
15 Journal(#[from] journal_core::JournalError),
16
17 #[error("Index error: {0}")]
19 Index(#[from] journal_index::IndexError),
20
21 #[error("Repository error: {0}")]
23 Repository(#[from] journal_registry::repository::RepositoryError),
24
25 #[error("Registry error: {0}")]
27 Registry(#[from] journal_registry::RegistryError),
28
29 #[error("Failed to parse journal file path: {path}")]
31 InvalidPath { path: String },
32
33 #[error("Path contains invalid UTF-8: {}", .path.display())]
35 InvalidUtf8 { path: PathBuf },
36
37 #[error("Channel closed")]
39 ChannelClosed,
40
41 #[error("Cache error: {0}")]
43 Foyer(#[source] Box<foyer::Error>),
44
45 #[error("Operation cancelled")]
47 Cancelled,
48
49 #[error("Invalid time range: start={start} >= end={end}")]
51 InvalidTimeRange { start: u32, end: u32 },
52}
53
54impl From<foyer::Error> for EngineError {
55 fn from(error: foyer::Error) -> Self {
56 Self::Foyer(Box::new(error))
57 }
58}
59
60static_assertions::const_assert!(std::mem::size_of::<EngineError>() <= 64);
61
62pub type Result<T> = std::result::Result<T, EngineError>;
64
65#[cfg(test)]
66mod tests {
67 use super::*;
68
69 #[test]
70 fn foyer_errors_are_boxed_within_the_engine_error_size_bound() {
71 let error = foyer::Error::new(foyer::ErrorKind::Config, "test error");
72 let error = EngineError::from(error);
73
74 assert!(matches!(error, EngineError::Foyer(_)));
75 assert!(std::mem::size_of::<EngineError>() <= 64);
76 }
77}