1use hehe_core::error::Error as CoreError;
2use thiserror::Error;
3
4#[derive(Error, Debug)]
5pub enum StoreError {
6 #[error("Connection error: {0}")]
7 Connection(String),
8
9 #[error("Query error: {0}")]
10 Query(String),
11
12 #[error("Not found: {0}")]
13 NotFound(String),
14
15 #[error("Already exists: {0}")]
16 AlreadyExists(String),
17
18 #[error("Invalid input: {0}")]
19 InvalidInput(String),
20
21 #[error("Transaction error: {0}")]
22 Transaction(String),
23
24 #[error("Migration error: {0}")]
25 Migration(String),
26
27 #[error("Serialization error: {0}")]
28 Serialization(String),
29
30 #[error("Backend not available: {0}")]
31 BackendNotAvailable(String),
32
33 #[error("Pool exhausted")]
34 PoolExhausted,
35
36 #[error("Timeout")]
37 Timeout,
38
39 #[error("Internal error: {0}")]
40 Internal(String),
41
42 #[error(transparent)]
43 Core(#[from] CoreError),
44
45 #[cfg(feature = "sqlite")]
46 #[error("SQLite error: {0}")]
47 Sqlite(#[from] rusqlite::Error),
48
49 #[cfg(feature = "duckdb")]
50 #[error("DuckDB error: {0}")]
51 DuckDb(#[from] duckdb::Error),
52}
53
54pub type Result<T> = std::result::Result<T, StoreError>;
55
56impl StoreError {
57 pub fn connection(msg: impl Into<String>) -> Self {
58 Self::Connection(msg.into())
59 }
60
61 pub fn query(msg: impl Into<String>) -> Self {
62 Self::Query(msg.into())
63 }
64
65 pub fn not_found(msg: impl Into<String>) -> Self {
66 Self::NotFound(msg.into())
67 }
68
69 pub fn invalid_input(msg: impl Into<String>) -> Self {
70 Self::InvalidInput(msg.into())
71 }
72
73 pub fn transaction(msg: impl Into<String>) -> Self {
74 Self::Transaction(msg.into())
75 }
76
77 pub fn migration(msg: impl Into<String>) -> Self {
78 Self::Migration(msg.into())
79 }
80
81 pub fn internal(msg: impl Into<String>) -> Self {
82 Self::Internal(msg.into())
83 }
84}