1use core::fmt::Display;
7
8pub type Result<T> = core::result::Result<T, Error>;
13
14#[derive(Debug, Clone)]
23pub enum Error {
24 FailedToGetCurrentTaskIdentifier(task::Error),
26 FailedToReadUsersDirectory(file_system::Error),
28 FailedToGetUserFilePath,
30 FailedToOpenUserFile(file_system::Error),
32 FailedToReadUserFile(file_system::Error),
34 FailedToParseUserFile(miniserde::Error),
36 FailedToAddUser(users::Error),
38 FailedToGetNewUserIdentifier(users::Error),
40 FailedToCreateUser(users::Error),
42 FailedToWriteUserFile(file_system::Error),
44 FailedToCreateUsersDirectory(file_system::Error),
46 FailedToReadGroupDirectory(file_system::Error),
48 FailedToGetGroupFilePath,
50 FailedToOpenGroupFile(file_system::Error),
52 FailedToReadGroupFile(file_system::Error),
54 FailedToParseGroupFile(miniserde::Error),
56 FailedToAddGroup(users::Error),
58 FailedToGetNewGroupIdentifier(users::Error),
60 FailedToCreateGroup(users::Error),
62 FailedToWriteGroupFile(file_system::Error),
64 FailedToCreateGroupsDirectory(file_system::Error),
66 InvalidPassword,
68 FailedToOpenRandomDevice(file_system::Error),
70 FailedToReadRandomDevice(file_system::Error),
72 FailedToGetUserIdentifier(users::Error),
74}
75
76impl Display for Error {
77 fn fmt(&self, formatter: &mut core::fmt::Formatter) -> core::fmt::Result {
78 match self {
79 Self::FailedToGetCurrentTaskIdentifier(error) => {
80 write!(formatter, "Failed to get current task identifier: {error}")
81 }
82 Self::FailedToReadUsersDirectory(error) => {
83 write!(formatter, "Failed to read users directory: {error}")
84 }
85 Self::FailedToGetUserFilePath => {
86 write!(formatter, "Failed to get user file path")
87 }
88 Self::FailedToReadUserFile(error) => {
89 write!(formatter, "Failed to read user file: {error}")
90 }
91 Self::FailedToOpenUserFile(error) => {
92 write!(formatter, "Failed to open user file: {error}")
93 }
94 Self::FailedToParseUserFile(error) => {
95 write!(formatter, "Failed to parse user file: {error}")
96 }
97 Self::FailedToAddUser(error) => {
98 write!(formatter, "Failed to add user: {error}")
99 }
100 Self::FailedToCreateUsersDirectory(error) => {
101 write!(formatter, "Failed to create users directory: {error}")
102 }
103 Self::FailedToReadGroupDirectory(error) => {
104 write!(formatter, "Failed to read group directory: {error}")
105 }
106 Self::FailedToGetGroupFilePath => {
107 write!(formatter, "Failed to get group file path")
108 }
109 Self::FailedToOpenGroupFile(error) => {
110 write!(formatter, "Failed to open group file: {error}")
111 }
112 Self::FailedToReadGroupFile(error) => {
113 write!(formatter, "Failed to read group file: {error}")
114 }
115 Self::FailedToParseGroupFile(error) => {
116 write!(formatter, "Failed to parse group file: {error}")
117 }
118 Self::FailedToAddGroup(error) => {
119 write!(formatter, "Failed to add group: {error}")
120 }
121 Self::FailedToCreateGroupsDirectory(error) => {
122 write!(formatter, "Failed to create group directory: {error}")
123 }
124 Self::InvalidPassword => {
125 write!(formatter, "Invalid password")
126 }
127 Self::FailedToOpenRandomDevice(error) => {
128 write!(formatter, "Failed to open random device: {error}")
129 }
130 Self::FailedToReadRandomDevice(error) => {
131 write!(formatter, "Failed to read random device: {error}")
132 }
133 Self::FailedToCreateUser(error) => {
134 write!(formatter, "Failed to create user: {error}")
135 }
136 Self::FailedToGetNewUserIdentifier(error) => {
137 write!(formatter, "Failed to get new user identifier: {error}")
138 }
139 Self::FailedToWriteUserFile(error) => {
140 write!(formatter, "Failed to write user file: {error}")
141 }
142 Self::FailedToGetNewGroupIdentifier(error) => {
143 write!(formatter, "Failed to get new groupe identifier: {error}")
144 }
145 Self::FailedToCreateGroup(error) => {
146 write!(formatter, "Failed to create group: {error}")
147 }
148 Self::FailedToWriteGroupFile(error) => {
149 write!(
150 formatter,
151 "Failed to writeerror
152 group file: {error}"
153 )
154 }
155 Self::FailedToGetUserIdentifier(error) => {
156 write!(formatter, "Failed to get user identifier: {error}")
157 }
158 }
159 }
160}
161
162impl From<task::Error> for Error {
163 fn from(error: task::Error) -> Self {
164 Self::FailedToGetCurrentTaskIdentifier(error)
165 }
166}