1use thiserror::Error;
4use uuid::Uuid;
5
6#[derive(Debug, Error)]
8pub enum StorageError {
9 #[error("agent not found: {0}")]
11 AgentNotFound(Uuid),
12
13 #[error("session not found: {0}")]
15 SessionNotFound(Uuid),
16
17 #[error("delegation link not found: from={from}, to={to}")]
19 DelegationNotFound { from: Uuid, to: Uuid },
20
21 #[error("backend error: {0}")]
23 Backend(String),
24
25 #[error("serialization error: {0}")]
27 Serialization(String),
28
29 #[error("migration error: {0}")]
31 Migration(String),
32
33 #[error("connection error: {0}")]
35 Connection(String),
36
37 #[error("encryption error: {0}")]
39 Encryption(String),
40}
41
42#[cfg(feature = "sqlite")]
43impl From<sqlx::Error> for StorageError {
44 fn from(err: sqlx::Error) -> Self {
45 StorageError::Backend(err.to_string())
46 }
47}
48
49#[cfg(feature = "sqlite")]
50impl From<sqlx::migrate::MigrateError> for StorageError {
51 fn from(err: sqlx::migrate::MigrateError) -> Self {
52 StorageError::Migration(err.to_string())
53 }
54}
55
56impl From<serde_json::Error> for StorageError {
57 fn from(err: serde_json::Error) -> Self {
58 StorageError::Serialization(err.to_string())
59 }
60}
61
62impl From<crate::encryption::EncryptionError> for StorageError {
63 fn from(err: crate::encryption::EncryptionError) -> Self {
64 StorageError::Encryption(err.to_string())
65 }
66}