1use meerkat_core::{SessionId, SessionStoreError};
4
5#[derive(Debug, thiserror::Error)]
11pub enum StoreError {
12 #[error("IO error: {0}")]
13 Io(#[from] std::io::Error),
14
15 #[error("Serialization error: {0}")]
16 Serialization(#[from] serde_json::Error),
17
18 #[cfg(not(target_arch = "wasm32"))]
19 #[error("SQLite error: {0}")]
20 Sqlite(#[from] rusqlite::Error),
21
22 #[error("Session not found: {0}")]
23 NotFound(SessionId),
24
25 #[error("Session corrupted: {0}")]
26 Corrupted(SessionId),
27
28 #[cfg(not(target_arch = "wasm32"))]
29 #[error("Task join error: {0}")]
30 Join(#[from] tokio::task::JoinError),
31
32 #[error("Internal error: {0}")]
33 Internal(String),
34
35 #[cfg(not(target_arch = "wasm32"))]
36 #[error("timed out acquiring realm manifest lock for '{realm_id}'")]
37 RealmManifestLockTimeout { realm_id: String },
38
39 #[cfg(not(target_arch = "wasm32"))]
40 #[error(
41 "realm backend mismatch for '{realm_id}': requested '{requested}', existing '{existing}'"
42 )]
43 RealmBackendMismatch {
44 realm_id: String,
45 requested: String,
46 existing: String,
47 },
48
49 #[cfg(not(target_arch = "wasm32"))]
50 #[error("unsupported realm backend for '{realm_id}': '{backend}'")]
51 UnsupportedRealmBackend { realm_id: String, backend: String },
52
53 #[cfg(not(target_arch = "wasm32"))]
60 #[error(
61 "realm identity mismatch: requested '{requested}' aliases existing manifest '{existing}'"
62 )]
63 RealmIdentityMismatch { requested: String, existing: String },
64
65 #[cfg(not(target_arch = "wasm32"))]
71 #[error("invalid realm id slug in persisted manifest: '{0}'")]
72 InvalidRealmSlug(String),
73}
74
75impl StoreError {
76 pub fn into_session_store_error(self) -> SessionStoreError {
78 match self {
79 StoreError::Io(e) => SessionStoreError::Io(e),
80 StoreError::Serialization(e) => SessionStoreError::Serialization(e.to_string()),
81 StoreError::NotFound(id) => SessionStoreError::NotFound(id),
82 StoreError::Corrupted(id) => SessionStoreError::Corrupted(id),
83 other => SessionStoreError::Internal(other.to_string()),
84 }
85 }
86}
87
88#[cfg(not(target_arch = "wasm32"))]
93#[cfg(any(feature = "jsonl", feature = "sqlite"))]
94pub(crate) fn into_session_store_error(e: StoreError) -> SessionStoreError {
95 e.into_session_store_error()
96}