Skip to main content

systemprompt_traits/
repository.rs

1//! Generic repository error type used by domain crates.
2//!
3//! Copyright (c) systemprompt.io — Business Source License 1.1.
4//! See <https://systemprompt.io> for licensing details.
5
6#[derive(Debug, thiserror::Error)]
7#[non_exhaustive]
8pub enum RepositoryError {
9    #[error("database error: {message}")]
10    Database { message: String },
11
12    #[error("entity not found: {0}")]
13    NotFound(String),
14
15    #[error("serialization error: {0}")]
16    Serialization(#[from] serde_json::Error),
17
18    #[error("invalid data: {0}")]
19    InvalidData(String),
20
21    #[error("constraint violation: {0}")]
22    ConstraintViolation(String),
23
24    #[error("{0}")]
25    Internal(String),
26}
27
28impl RepositoryError {
29    pub fn database(err: impl std::fmt::Display) -> Self {
30        Self::Database {
31            message: err.to_string(),
32        }
33    }
34}