systemprompt_users/
error.rs1use systemprompt_database::IdentifierError;
7use systemprompt_identifiers::UserId;
8use systemprompt_models::domain_error;
9
10domain_error! {
11 pub enum UserError {
12 common: [repository, validation],
13
14 #[error("user not found: {0}")]
15 NotFound(UserId),
16
17 #[error("user already exists with email: {0}")]
18 EmailAlreadyExists(String),
19
20 #[error("invalid status: {0}")]
21 InvalidStatus(String),
22
23 #[error("invalid role: {0}")]
24 InvalidRole(String),
25
26 #[error("invalid roles: {0:?}")]
27 InvalidRoles(Vec<String>),
28
29 #[error("purge {kind} {name} is not a safe SQL identifier")]
30 PurgeIdentifier {
31 kind: &'static str,
32 name: String,
33 #[source]
34 source: IdentifierError,
35 },
36
37 #[error("user {0} is under legal hold and cannot be purged")]
38 LegalHold(UserId),
39
40 #[error("user {0} is not archived; archive before purging")]
41 NotArchived(UserId),
42
43 #[error("user {id} cannot be restored: not archived, or archived more than {window_days} days ago")]
44 RestoreRefused { id: UserId, window_days: u32 },
45
46 #[error("account merge is unavailable: no owner reassignments are configured")]
47 MergeUnavailable,
48
49 #[error("owner reassignment failed in the {domain} domain: {source}")]
50 OwnerReassignment {
51 domain: &'static str,
52 #[source]
53 source: systemprompt_traits::RepositoryError,
54 },
55 }
56}
57
58impl From<sqlx::Error> for UserError {
59 fn from(err: sqlx::Error) -> Self {
60 Self::Repository(systemprompt_traits::RepositoryError::from(err))
61 }
62}
63
64pub type Result<T> = std::result::Result<T, UserError>;
65
66pub type UserResult<T> = Result<T>;