Skip to main content

arbiter_storage/
error.rs

1//! Storage error types.
2
3use thiserror::Error;
4use uuid::Uuid;
5
6/// Errors from storage operations.
7#[derive(Debug, Error)]
8pub enum StorageError {
9    /// The requested agent was not found.
10    #[error("agent not found: {0}")]
11    AgentNotFound(Uuid),
12
13    /// The requested session was not found.
14    #[error("session not found: {0}")]
15    SessionNotFound(Uuid),
16
17    /// The requested delegation link was not found.
18    #[error("delegation link not found: from={from}, to={to}")]
19    DelegationNotFound { from: Uuid, to: Uuid },
20
21    /// A database or backend error occurred.
22    #[error("backend error: {0}")]
23    Backend(String),
24
25    /// Serialization/deserialization error.
26    #[error("serialization error: {0}")]
27    Serialization(String),
28
29    /// Migration error during schema setup.
30    #[error("migration error: {0}")]
31    Migration(String),
32
33    /// Connection pool error.
34    #[error("connection error: {0}")]
35    Connection(String),
36
37    /// Field-level encryption or decryption error.
38    #[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}