webgates_core/permissions/
errors.rs1use crate::errors_core::{ErrorSeverity, UserFriendlyError};
19use thiserror::Error;
20
21#[derive(Debug, Error)]
26#[non_exhaustive]
27pub enum PermissionsError {
28 #[error("Permission collision: {collision_count} permissions map to hash {hash_id}")]
30 Collision {
31 collision_count: usize,
33 hash_id: u64,
35 permissions: Vec<String>,
37 },
38}
39
40impl PermissionsError {
41 pub fn collision(hash_id: u64, permissions: Vec<String>) -> Self {
45 PermissionsError::Collision {
46 collision_count: permissions.len(),
47 hash_id,
48 permissions,
49 }
50 }
51
52 fn support_code_inner(&self) -> String {
54 match self {
55 PermissionsError::Collision { hash_id, .. } => {
56 format!("PERM-COLLISION-{}", hash_id)
57 }
58 }
59 }
60}
61
62impl UserFriendlyError for PermissionsError {
63 fn user_message(&self) -> String {
64 match self {
65 PermissionsError::Collision { .. } => {
66 "There's a technical issue with your account permissions. Our support team has been notified and will resolve this shortly. Please contact support if you need immediate assistance.".to_string()
67 }
68 }
69 }
70
71 fn developer_message(&self) -> String {
72 match self {
73 PermissionsError::Collision {
74 collision_count,
75 hash_id,
76 permissions,
77 } => {
78 format!(
79 "Permission collision detected: {} permissions [{}] map to hash ID {}. This indicates a critical hash collision in the permission system requiring immediate administrator attention.",
80 collision_count,
81 permissions.join(", "),
82 hash_id
83 )
84 }
85 }
86 }
87
88 fn support_code(&self) -> String {
89 self.support_code_inner()
90 }
91
92 fn severity(&self) -> ErrorSeverity {
93 match self {
94 PermissionsError::Collision { .. } => ErrorSeverity::Critical,
95 }
96 }
97
98 fn suggested_actions(&self) -> Vec<String> {
99 match self {
100 PermissionsError::Collision { .. } => vec![
101 "Contact our support team immediately with the reference code below".to_string(),
102 "Do not attempt to retry this operation".to_string(),
103 "This is a critical system issue requiring immediate administrator attention"
104 .to_string(),
105 ],
106 }
107 }
108
109 fn is_retryable(&self) -> bool {
110 match self {
111 PermissionsError::Collision { .. } => false, }
113 }
114}