Skip to main content

systemprompt_users/
error.rs

1//! Typed error surface for the users crate.
2
3use systemprompt_identifiers::UserId;
4use systemprompt_models::domain_error;
5
6domain_error! {
7    pub enum UserError {
8        common: [repository, validation],
9
10        #[error("user not found: {0}")]
11        NotFound(UserId),
12
13        #[error("user already exists with email: {0}")]
14        EmailAlreadyExists(String),
15
16        #[error("invalid status: {0}")]
17        InvalidStatus(String),
18
19        #[error("invalid role: {0}")]
20        InvalidRole(String),
21
22        #[error("invalid roles: {0:?}")]
23        InvalidRoles(Vec<String>),
24
25        #[error("pool error: {0}")]
26        Pool(String),
27    }
28}
29
30impl From<sqlx::Error> for UserError {
31    fn from(err: sqlx::Error) -> Self {
32        Self::Repository(systemprompt_database::RepositoryError::from(err))
33    }
34}
35
36pub type Result<T> = std::result::Result<T, UserError>;
37
38pub type UserResult<T> = Result<T>;