actor_sample/user_actor/
error.rs

1//! Error types for the User actor.
2
3use thiserror::Error;
4
5/// Errors that can occur during user operations.
6///
7/// This error type is used both by the client (UserClient) and internally
8/// by the User entity's lifecycle hooks.
9#[derive(Debug, Error)]
10#[allow(dead_code)]
11pub enum UserError {
12    /// The requested user was not found.
13    #[error("User not found: {0}")]
14    NotFound(String),
15
16    /// A user with the same unique identifier (e.g., email) already exists.
17    #[error("User already exists: {0}")]
18    AlreadyExists(String),
19
20    /// The user data provided is invalid.
21    #[error("User validation error: {0}")]
22    ValidationError(String),
23
24    /// Invalid email format (entity-level validation)
25    #[error("Invalid email format: {0}")]
26    InvalidEmail(String),
27
28    /// An underlying database error occurred.
29    #[error("User database error: {0}")]
30    DatabaseError(String),
31
32    /// An error occurred while communicating with the actor system.
33    #[error("Actor communication error: {0}")]
34    ActorCommunicationError(String),
35}
36
37impl From<String> for UserError {
38    fn from(msg: String) -> Self {
39        UserError::ActorCommunicationError(msg)
40    }
41}