Skip to main content

nervusdb_core/
error.rs

1//! Basic error and result types shared across the core crate.
2
3use std::io;
4
5/// Result type used across the core crate.
6pub type Result<T> = std::result::Result<T, Error>;
7
8/// Minimal error enumeration for the prototype storage engine.
9#[derive(Debug)]
10pub enum Error {
11    /// Wrapper around standard I/O errors.
12    Io(io::Error),
13    /// Tried to look up a string that does not exist in the dictionary.
14    UnknownString(String),
15    /// Attempted to use an invalid cursor identifier.
16    InvalidCursor(u64),
17    /// Generic placeholder for unimplemented features.
18    NotImplemented(&'static str),
19    /// Miscellaneous error message.
20    Other(String),
21    /// Entity or Fact not found.
22    NotFound,
23}
24
25impl std::fmt::Display for Error {
26    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
27        match self {
28            Error::Io(err) => write!(f, "I/O error: {err}"),
29            Error::UnknownString(s) => write!(f, "unknown string: {s}"),
30            Error::InvalidCursor(id) => write!(f, "invalid cursor id: {id}"),
31            Error::NotImplemented(msg) => write!(f, "not implemented: {msg}"),
32            Error::Other(msg) => write!(f, "{msg}"),
33            Error::NotFound => write!(f, "not found"),
34        }
35    }
36}
37
38impl std::error::Error for Error {}
39
40impl From<io::Error> for Error {
41    fn from(err: io::Error) -> Self {
42        Error::Io(err)
43    }
44}
45
46#[cfg(all(feature = "temporal", not(target_arch = "wasm32")))]
47impl From<nervusdb_temporal::Error> for Error {
48    fn from(err: nervusdb_temporal::Error) -> Self {
49        Error::Other(err.to_string())
50    }
51}