1use crate::ids::{RoleId, TenantId};
2#[cfg(feature = "platform")]
3use crate::platform::PlatformRoleId;
4use thiserror::Error;
5
6pub type SourceError = Box<dyn std::error::Error + Send + Sync>;
8
9pub type Result<T> = std::result::Result<T, Error>;
11
12#[derive(Debug, Error)]
14pub enum Error {
15 #[error("source error: {0}")]
17 Source(#[source] SourceError),
18 #[error("invalid id: {0}")]
20 InvalidId(String),
21 #[error("invalid permission: {0}")]
23 InvalidPermission(String),
24 #[error("invalid scope: {0}")]
26 InvalidScope(String),
27 #[error("role cycle detected for tenant {tenant} at role {role}")]
29 RoleCycleDetected { tenant: TenantId, role: RoleId },
30 #[error(
32 "role inheritance depth exceeded for tenant {tenant} at role {role}; max depth {max_depth}"
33 )]
34 RoleDepthExceeded {
35 tenant: TenantId,
36 role: RoleId,
37 max_depth: usize,
38 },
39 #[cfg(feature = "platform")]
41 #[error("platform role cycle detected at role {role}")]
42 PlatformRoleCycleDetected {
43 role: PlatformRoleId,
45 },
46 #[cfg(feature = "platform")]
48 #[error("platform role inheritance depth exceeded at role {role}; max depth {max_depth}")]
49 PlatformRoleDepthExceeded {
50 role: PlatformRoleId,
52 max_depth: usize,
54 },
55}
56
57impl From<SourceError> for Error {
58 fn from(error: SourceError) -> Self {
60 Self::Source(error)
61 }
62}