Skip to main content

journal_engine/
error.rs

1//! Error types for journal engine operations
2
3use std::path::PathBuf;
4use thiserror::Error;
5
6/// Errors that can occur during engine operations
7#[derive(Debug, Error)]
8pub enum EngineError {
9    /// I/O error when reading files
10    #[error("I/O error: {0}")]
11    Io(#[from] std::io::Error),
12
13    /// Error from journal core operations
14    #[error("Journal error: {0}")]
15    Journal(#[from] journal_core::JournalError),
16
17    /// Error from journal indexing operations
18    #[error("Index error: {0}")]
19    Index(#[from] journal_index::IndexError),
20
21    /// Error from repository operations
22    #[error("Repository error: {0}")]
23    Repository(#[from] journal_registry::repository::RepositoryError),
24
25    /// Error from registry operations
26    #[error("Registry error: {0}")]
27    Registry(#[from] journal_registry::RegistryError),
28
29    /// Error when parsing a journal file path
30    #[error("Failed to parse journal file path: {path}")]
31    InvalidPath { path: String },
32
33    /// Error when a path contains invalid UTF-8
34    #[error("Path contains invalid UTF-8: {}", .path.display())]
35    InvalidUtf8 { path: PathBuf },
36
37    /// Channel closed error
38    #[error("Channel closed")]
39    ChannelClosed,
40
41    /// Foyer cache error
42    #[error("Cache error: {0}")]
43    Foyer(#[source] Box<foyer::Error>),
44
45    /// Operation was cancelled
46    #[error("Operation cancelled")]
47    Cancelled,
48
49    /// Invalid time range (start >= end)
50    #[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
62/// A specialized Result type for engine operations
63pub 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}