Skip to main content

nrc_mls_storage/groups/
error.rs

1//! Error types for the groups module
2
3use std::fmt;
4
5/// Invalid group state
6#[derive(Debug, PartialEq, Eq)]
7pub enum InvalidGroupState {
8    /// Group has no admins
9    NoAdmins,
10    /// Group has no relays
11    NoRelays,
12}
13
14impl fmt::Display for InvalidGroupState {
15    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
16        match self {
17            Self::NoAdmins => write!(f, "group has no admins"),
18            Self::NoRelays => write!(f, "group has no relays"),
19        }
20    }
21}
22
23/// Error types for the groups module
24#[derive(Debug)]
25pub enum GroupError {
26    /// Invalid parameters
27    InvalidParameters(String),
28    /// Database error
29    DatabaseError(String),
30    /// Invalid state
31    InvalidState(InvalidGroupState),
32}
33
34impl std::error::Error for GroupError {}
35
36impl fmt::Display for GroupError {
37    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
38        match self {
39            Self::InvalidParameters(message) => write!(f, "Invalid parameters: {}", message),
40            Self::DatabaseError(message) => write!(f, "Database error: {}", message),
41            Self::InvalidState(state) => write!(f, "Invalid state: {state}"),
42        }
43    }
44}