use crate::ids::{RoleId, TenantId};
#[cfg(feature = "platform")]
use crate::platform::PlatformRoleId;
use thiserror::Error;
pub type SourceError = Box<dyn std::error::Error + Send + Sync>;
pub type Result<T> = std::result::Result<T, Error>;
#[derive(Debug, Error)]
pub enum Error {
#[error("source error: {0}")]
Source(#[source] SourceError),
#[error("invalid id: {0}")]
InvalidId(String),
#[error("invalid permission: {0}")]
InvalidPermission(String),
#[error("invalid scope: {0}")]
InvalidScope(String),
#[error("role cycle detected for tenant {tenant} at role {role}")]
RoleCycleDetected { tenant: TenantId, role: RoleId },
#[error(
"role inheritance depth exceeded for tenant {tenant} at role {role}; max depth {max_depth}"
)]
RoleDepthExceeded {
tenant: TenantId,
role: RoleId,
max_depth: usize,
},
#[cfg(feature = "platform")]
#[error("platform role cycle detected at role {role}")]
PlatformRoleCycleDetected {
role: PlatformRoleId,
},
#[cfg(feature = "platform")]
#[error("platform role inheritance depth exceeded at role {role}; max depth {max_depth}")]
PlatformRoleDepthExceeded {
role: PlatformRoleId,
max_depth: usize,
},
}
impl From<SourceError> for Error {
fn from(error: SourceError) -> Self {
Self::Source(error)
}
}