role_system/
error.rs

1//! Error types for the role system.
2
3use thiserror::Error;
4
5/// The main error type for role system operations.
6#[derive(Error, Debug)]
7pub enum Error {
8    /// Role with the given name already exists.
9    #[error("Role '{0}' already exists")]
10    RoleAlreadyExists(String),
11
12    /// Role with the given name was not found.
13    #[error("Role '{0}' not found")]
14    RoleNotFound(String),
15
16    /// Subject with the given ID was not found.
17    #[error("Subject '{0}' not found")]
18    SubjectNotFound(String),
19
20    /// Permission was denied for the requested operation.
21    #[error("Permission denied: {0}")]
22    PermissionDenied(String),
23
24    /// Circular dependency detected in role hierarchy.
25    #[error("Circular dependency detected in role hierarchy involving '{0}'")]
26    CircularDependency(String),
27
28    /// Invalid permission format.
29    #[error("Invalid permission format: {0}")]
30    InvalidPermission(String),
31
32    /// Invalid resource format.
33    #[error("Invalid resource format: {0}")]
34    InvalidResource(String),
35
36    /// Role elevation has expired.
37    #[error("Role elevation for subject '{0}' has expired")]
38    ElevationExpired(String),
39
40    /// Maximum role hierarchy depth exceeded.
41    #[error("Maximum role hierarchy depth exceeded (max: {0})")]
42    MaxDepthExceeded(usize),
43
44    /// Serialization error.
45    #[cfg(feature = "persistence")]
46    #[error("Serialization error: {0}")]
47    Serialization(#[from] serde_json::Error),
48
49    /// Storage operation failed.
50    #[error("Storage operation failed: {0}")]
51    Storage(String),
52
53    /// Invalid configuration.
54    #[error("Invalid configuration: {0}")]
55    InvalidConfiguration(String),
56}
57
58/// Result type alias for role system operations.
59pub type Result<T> = std::result::Result<T, Error>;