Skip to main content

zlayer_store/
error.rs

1//! Shared storage error type.
2//!
3//! `StorageError` is the error returned by every `ZLayer` storage operation.
4//! It was moved here verbatim from `zlayer-api::storage::deployments` so that
5//! the generic adapter ([`crate::JsonStore`]) and every domain store can
6//! share a single error type without depending on `zlayer-api`.
7
8use thiserror::Error;
9
10/// Storage errors
11#[derive(Debug, Error)]
12pub enum StorageError {
13    /// Database error
14    #[error("Database error: {0}")]
15    Database(String),
16
17    /// Serialization error
18    #[error("Serialization error: {0}")]
19    Serialization(String),
20
21    /// Deployment not found
22    #[error("Deployment not found: {0}")]
23    NotFound(String),
24
25    /// Row already exists (unique constraint violation)
26    #[error("Already exists: {0}")]
27    AlreadyExists(String),
28
29    /// Other / miscellaneous error (e.g. unknown column, invalid argument)
30    #[error("Storage error: {0}")]
31    Other(String),
32
33    /// IO error
34    #[error("IO error: {0}")]
35    Io(#[from] std::io::Error),
36}
37
38impl From<sqlx::Error> for StorageError {
39    fn from(err: sqlx::Error) -> Self {
40        StorageError::Database(err.to_string())
41    }
42}
43
44impl From<serde_json::Error> for StorageError {
45    fn from(err: serde_json::Error) -> Self {
46        StorageError::Serialization(err.to_string())
47    }
48}