Skip to main content

hematite/
error.rs

1//! Error handling for Hematite database
2
3use std::fmt;
4
5#[derive(Debug)]
6pub enum HematiteError {
7    IoError(std::io::Error),
8    CorruptedData(String),
9    InvalidPage(u32),
10    PageNotFound(u32),
11    InvalidSchema(String),
12    ParseError(String),
13    StorageError(String),
14    InternalError(String),
15}
16
17impl fmt::Display for HematiteError {
18    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
19        match self {
20            HematiteError::IoError(e) => write!(f, "IO Error: {}", e),
21            HematiteError::CorruptedData(msg) => write!(f, "Corrupted data: {}", msg),
22            HematiteError::InvalidPage(page) => write!(f, "Invalid page: {}", page),
23            HematiteError::PageNotFound(page) => write!(f, "Page not found: {}", page),
24            HematiteError::InvalidSchema(msg) => write!(f, "Invalid schema: {}", msg),
25            HematiteError::ParseError(msg) => write!(f, "Parse error: {}", msg),
26            HematiteError::StorageError(msg) => write!(f, "Storage error: {}", msg),
27            HematiteError::InternalError(msg) => write!(f, "Internal error: {}", msg),
28        }
29    }
30}
31
32impl std::error::Error for HematiteError {}
33
34impl From<std::io::Error> for HematiteError {
35    fn from(error: std::io::Error) -> Self {
36        HematiteError::IoError(error)
37    }
38}
39
40pub type Result<T> = std::result::Result<T, HematiteError>;