actor_sample/product_actor/
error.rs

1//! Error types for the Product actor.
2
3use thiserror::Error;
4
5/// Errors that can occur during product operations.
6///
7/// This error type is used both by the client (ProductClient) and internally
8/// by the Product entity's lifecycle hooks.
9#[derive(Debug, Error)]
10#[allow(dead_code)]
11pub enum ProductError {
12    /// The requested product was not found.
13    #[error("Product not found: {0}")]
14    NotFound(String),
15
16    /// The requested quantity exceeds the available stock.
17    #[error("Insufficient stock: requested {requested}, available {available}")]
18    InsufficientStock { requested: u32, available: u32 },
19
20    /// The provided quantity is invalid (e.g., zero or negative).
21    #[error("Invalid quantity: {0}")]
22    InvalidQuantity(u32),
23
24    /// Invalid price value (entity-level validation)
25    #[error("Invalid price: {0}")]
26    InvalidPrice(f64),
27
28    /// An underlying database error occurred.
29    #[error("Product 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 ProductError {
38    fn from(msg: String) -> Self {
39        ProductError::ActorCommunicationError(msg)
40    }
41}