coqui_access_acl/
error.rs1use core::fmt;
4
5use coqui_access::guatiao::library::ProviderError;
6
7#[derive(Debug)]
10#[non_exhaustive]
11pub enum AclError {
12 InvalidName,
14 DuplicateName,
16 UnknownRight {
19 entry: Option<usize>,
21 at: usize,
23 },
24 TooManyRights,
26 TooManyEntries,
28 DenyNotAllowed {
31 entry: usize,
33 },
34 PrincipalNotAllowed {
37 entry: usize,
39 },
40 ModeMismatch,
42 TooDeep,
44 Cycle,
46 Store(ProviderError),
48}
49
50impl fmt::Display for AclError {
51 fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
52 match self {
53 Self::InvalidName => formatter.write_str("a right name is empty or not printable"),
54 Self::DuplicateName => formatter.write_str("a right name is defined twice"),
55 Self::UnknownRight {
56 entry: Some(entry),
57 at,
58 } => {
59 write!(formatter, "entry {entry} names an unknown right at {at}")
60 }
61 Self::UnknownRight { entry: None, at } => {
62 write!(formatter, "unknown right at position {at}")
63 }
64 Self::TooManyRights => formatter.write_str("the schema defines too many rights"),
65 Self::TooManyEntries => formatter.write_str("the acl holds too many entries"),
66 Self::DenyNotAllowed { entry } => {
67 write!(formatter, "entry {entry} denies in a mode without denies")
68 }
69 Self::PrincipalNotAllowed { entry } => {
70 write!(
71 formatter,
72 "entry {entry} names a principal its mode does not take"
73 )
74 }
75 Self::ModeMismatch => formatter.write_str("a walked acl is not in most-specific mode"),
76 Self::TooDeep => formatter.write_str("the item is nested too deep"),
77 Self::Cycle => formatter.write_str("the item is its own ancestor"),
78 Self::Store(_) => formatter.write_str("the acl store could not answer"),
79 }
80 }
81}
82
83impl core::error::Error for AclError {
84 fn source(&self) -> Option<&(dyn core::error::Error + 'static)> {
85 match self {
86 Self::Store(error) => Some(error),
87 _ => None,
88 }
89 }
90}
91
92impl From<ProviderError> for AclError {
93 fn from(error: ProviderError) -> Self {
94 Self::Store(error)
95 }
96}