regulus_db/types/
error.rs1use crate::types::schema::SchemaError;
2use std::fmt;
3use std::io;
4
5#[derive(Debug)]
7pub enum DbError {
8 TableNotFound(String),
10 TableAlreadyExists(String),
12 RowNotFound,
14 SchemaError(SchemaError),
16 TransactionError(String),
18 IndexError(String),
20 IoError(io::Error),
22 InternalError(String),
24 Other(String),
26}
27
28impl fmt::Display for DbError {
29 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
30 match self {
31 DbError::TableNotFound(name) => write!(f, "Table not found: {}", name),
32 DbError::TableAlreadyExists(name) => write!(f, "Table already exists: {}", name),
33 DbError::RowNotFound => write!(f, "Row not found"),
34 DbError::SchemaError(err) => write!(f, "Schema error: {}", err),
35 DbError::TransactionError(msg) => write!(f, "Transaction error: {}", msg),
36 DbError::IndexError(msg) => write!(f, "Index error: {}", msg),
37 DbError::IoError(err) => write!(f, "IO error: {}", err),
38 DbError::InternalError(msg) => write!(f, "Internal error: {}", msg),
39 DbError::Other(msg) => write!(f, "{}", msg),
40 }
41 }
42}
43
44impl std::error::Error for DbError {}
45
46impl From<SchemaError> for DbError {
47 fn from(err: SchemaError) -> Self {
48 DbError::SchemaError(err)
49 }
50}
51
52impl From<std::io::Error> for DbError {
53 fn from(err: std::io::Error) -> Self {
54 DbError::IoError(err)
55 }
56}
57
58pub type DbResult<T> = Result<T, DbError>;