use thiserror::Error;
use uuid::Uuid;
#[derive(Debug, Error)]
pub enum StorageError {
#[error("agent not found: {0}")]
AgentNotFound(Uuid),
#[error("session not found: {0}")]
SessionNotFound(Uuid),
#[error("delegation link not found: from={from}, to={to}")]
DelegationNotFound { from: Uuid, to: Uuid },
#[error("backend error: {0}")]
Backend(String),
#[error("serialization error: {0}")]
Serialization(String),
#[error("migration error: {0}")]
Migration(String),
#[error("connection error: {0}")]
Connection(String),
#[error("encryption error: {0}")]
Encryption(String),
}
#[cfg(feature = "sqlite")]
impl From<sqlx::Error> for StorageError {
fn from(err: sqlx::Error) -> Self {
StorageError::Backend(err.to_string())
}
}
#[cfg(feature = "sqlite")]
impl From<sqlx::migrate::MigrateError> for StorageError {
fn from(err: sqlx::migrate::MigrateError) -> Self {
StorageError::Migration(err.to_string())
}
}
impl From<serde_json::Error> for StorageError {
fn from(err: serde_json::Error) -> Self {
StorageError::Serialization(err.to_string())
}
}
impl From<crate::encryption::EncryptionError> for StorageError {
fn from(err: crate::encryption::EncryptionError) -> Self {
StorageError::Encryption(err.to_string())
}
}