llldap/src/db/error.rs

46 lines
1.3 KiB
Rust
Raw Normal View History

2026-09-01 19:06:33 +02:00
use std::fmt;
use crate::db::UserRef;
2026-09-01 23:27:02 +02:00
pub type BoxedError = Box<dyn std::error::Error + Send + Sync + 'static>;
2026-09-01 19:06:33 +02:00
#[derive(Debug)]
pub enum UserCreationError {
2026-09-14 21:05:23 +02:00
DomainNotFound(String),
UserAlreadyExists(UserRef),
Permissions,
}
2026-09-01 19:06:33 +02:00
impl fmt::Display for UserCreationError {
2026-09-01 19:06:33 +02:00
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
2026-09-14 21:05:23 +02:00
Self::DomainNotFound(domain) => write!(f, "No domain {domain} to create user in"),
Self::UserAlreadyExists(user) => write!(f, "User already exists: {user}"),
Self::Permissions => write!(f, "You do not have permissions to create this user"),
}
2026-09-01 19:06:33 +02:00
}
}
impl std::error::Error for UserCreationError {}
2026-09-14 21:05:23 +02:00
#[derive(Debug)]
pub enum DomainCreationError {
DomainAlreadyExists(String),
InvalidDomain(String),
}
impl fmt::Display for DomainCreationError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::DomainAlreadyExists(domain) => {
write!(f, "Cannot create domain {domain} because it already exists")
}
Self::InvalidDomain(domain) => write!(
f,
"Cannot create domain `{domain}` because it's not considered a valid domain"
),
}
}
}
impl std::error::Error for DomainCreationError {}