1use core::fmt::Display;
7use embedded_i18n::t;
8
9pub type Result<T> = core::result::Result<T, Error>;
14
15#[derive(Debug, Clone)]
24pub enum Error {
25 FailedToGetCurrentTaskIdentifier(task::Error),
27 FailedToReadUsersDirectory(virtual_file_system::IoErrorKind),
29 FailedToGetUserFilePath,
31 FailedToOpenUserFile(virtual_file_system::IoErrorKind),
33 FailedToReadUserFile(virtual_file_system::IoErrorKind),
35 FailedToParseUserFile(miniserde::Error),
37 FailedToAddUser(users::Error),
39 FailedToGetNewUserIdentifier(users::Error),
41 FailedToCreateUser(users::Error),
43 FailedToWriteUserFile(virtual_file_system::IoErrorKind),
45 FailedToCreateUsersDirectory(virtual_file_system::IoErrorKind),
47 FailedToReadGroupDirectory(virtual_file_system::IoErrorKind),
49 FailedToGetGroupFilePath,
51 FailedToOpenGroupFile(virtual_file_system::IoErrorKind),
53 FailedToReadGroupFile(virtual_file_system::IoErrorKind),
55 FailedToParseGroupFile(miniserde::Error),
57 FailedToAddGroup(users::Error),
59 FailedToGetNewGroupIdentifier(users::Error),
61 FailedToCreateGroup(users::Error),
63 FailedToWriteGroupFile(virtual_file_system::IoErrorKind),
65 FailedToCreateGroupsDirectory(virtual_file_system::IoErrorKind),
67 InvalidPassword,
69 FailedToOpenRandomDevice(virtual_file_system::IoErrorKind),
71 FailedToReadRandomDevice(virtual_file_system::IoErrorKind),
73 FailedToGetUserIdentifier(users::Error),
75 FailedToCloseFile(virtual_file_system::IoErrorKind),
77 FailedToHashPassword(virtual_file_system::IoErrorKind),
79 InvalidUserName,
81 InvalidUserHome,
83 InvalidUserRecord,
85 UnsupportedUserRecordVersion,
87 UserHomeAlreadyUsed,
89 FailedToRenameUser(users::Error),
91}
92
93impl Display for Error {
94 fn fmt(&self, formatter: &mut core::fmt::Formatter) -> core::fmt::Result {
95 match self {
96 Self::FailedToGetCurrentTaskIdentifier(error) => {
97 write!(
98 formatter,
99 "{}",
100 t!("errors.failed_to_get_current_task_identifier", arg0 = error)
101 )
102 }
103 Self::FailedToReadUsersDirectory(error) => {
104 write!(
105 formatter,
106 "{}",
107 t!("errors.failed_to_read_users_directory", arg0 = error)
108 )
109 }
110 Self::FailedToGetUserFilePath => {
111 write!(formatter, "{}", t!("errors.failed_to_get_user_file_path"))
112 }
113 Self::FailedToReadUserFile(error) => {
114 write!(
115 formatter,
116 "{}",
117 t!("errors.failed_to_read_user_file", arg0 = error)
118 )
119 }
120 Self::FailedToOpenUserFile(error) => {
121 write!(
122 formatter,
123 "{}",
124 t!("errors.failed_to_open_user_file", arg0 = error)
125 )
126 }
127 Self::FailedToParseUserFile(error) => {
128 write!(
129 formatter,
130 "{}",
131 t!("errors.failed_to_parse_user_file", arg0 = error)
132 )
133 }
134 Self::FailedToAddUser(error) => {
135 write!(
136 formatter,
137 "{}",
138 t!("errors.failed_to_add_user", arg0 = error)
139 )
140 }
141 Self::FailedToCreateUsersDirectory(error) => {
142 write!(
143 formatter,
144 "{}",
145 t!("errors.failed_to_create_users_directory", arg0 = error)
146 )
147 }
148 Self::FailedToReadGroupDirectory(error) => {
149 write!(
150 formatter,
151 "{}",
152 t!("errors.failed_to_read_group_directory", arg0 = error)
153 )
154 }
155 Self::FailedToGetGroupFilePath => {
156 write!(formatter, "{}", t!("errors.failed_to_get_group_file_path"))
157 }
158 Self::FailedToOpenGroupFile(error) => {
159 write!(
160 formatter,
161 "{}",
162 t!("errors.failed_to_open_group_file", arg0 = error)
163 )
164 }
165 Self::FailedToReadGroupFile(error) => {
166 write!(
167 formatter,
168 "{}",
169 t!("errors.failed_to_read_group_file", arg0 = error)
170 )
171 }
172 Self::FailedToParseGroupFile(error) => {
173 write!(
174 formatter,
175 "{}",
176 t!("errors.failed_to_parse_group_file", arg0 = error)
177 )
178 }
179 Self::FailedToAddGroup(error) => {
180 write!(
181 formatter,
182 "{}",
183 t!("errors.failed_to_add_group", arg0 = error)
184 )
185 }
186 Self::FailedToCreateGroupsDirectory(error) => {
187 write!(
188 formatter,
189 "{}",
190 t!("errors.failed_to_create_group_directory", arg0 = error)
191 )
192 }
193 Self::InvalidPassword => {
194 write!(formatter, "{}", t!("errors.invalid_password"))
195 }
196 Self::FailedToOpenRandomDevice(error) => {
197 write!(
198 formatter,
199 "{}",
200 t!("errors.failed_to_open_random_device", arg0 = error)
201 )
202 }
203 Self::FailedToReadRandomDevice(error) => {
204 write!(
205 formatter,
206 "{}",
207 t!("errors.failed_to_read_random_device", arg0 = error)
208 )
209 }
210 Self::FailedToCreateUser(error) => {
211 write!(
212 formatter,
213 "{}",
214 t!("errors.failed_to_create_user", arg0 = error)
215 )
216 }
217 Self::FailedToGetNewUserIdentifier(error) => {
218 write!(
219 formatter,
220 "{}",
221 t!("errors.failed_to_get_new_user_identifier", arg0 = error)
222 )
223 }
224 Self::FailedToWriteUserFile(error) => {
225 write!(
226 formatter,
227 "{}",
228 t!("errors.failed_to_write_user_file", arg0 = error)
229 )
230 }
231 Self::FailedToGetNewGroupIdentifier(error) => {
232 write!(
233 formatter,
234 "{}",
235 t!("errors.failed_to_get_new_groupe_identifier", arg0 = error)
236 )
237 }
238 Self::FailedToCreateGroup(error) => {
239 write!(
240 formatter,
241 "{}",
242 t!("errors.failed_to_create_group", arg0 = error)
243 )
244 }
245 Self::FailedToWriteGroupFile(error) => {
246 write!(
247 formatter,
248 "{}",
249 t!("errors.failed_to_write_group_file", arg0 = error)
250 )
251 }
252 Self::FailedToGetUserIdentifier(error) => {
253 write!(
254 formatter,
255 "{}",
256 t!("errors.failed_to_get_user_identifier", arg0 = error)
257 )
258 }
259 Self::FailedToCloseFile(error) => {
260 write!(
261 formatter,
262 "{}",
263 t!("errors.failed_to_close_file", arg0 = error)
264 )
265 }
266 Self::FailedToHashPassword(error) => {
267 write!(
268 formatter,
269 "{}",
270 t!("errors.failed_to_hash_password", arg0 = error)
271 )
272 }
273 Self::InvalidUserName => {
274 write!(formatter, "{}", t!("errors.invalid_user_name"))
275 }
276 Self::InvalidUserHome => {
277 write!(formatter, "{}", t!("errors.invalid_user_home"))
278 }
279 Self::InvalidUserRecord => {
280 write!(formatter, "{}", t!("errors.invalid_user_record"))
281 }
282 Self::UnsupportedUserRecordVersion => {
283 write!(
284 formatter,
285 "{}",
286 t!("errors.unsupported_user_record_version")
287 )
288 }
289 Self::UserHomeAlreadyUsed => {
290 write!(formatter, "{}", t!("errors.user_home_already_used"))
291 }
292 Self::FailedToRenameUser(error) => {
293 write!(
294 formatter,
295 "{}",
296 t!("errors.failed_to_rename_user", arg0 = error)
297 )
298 }
299 }
300 }
301}
302
303impl From<task::Error> for Error {
304 fn from(error: task::Error) -> Self {
305 Self::FailedToGetCurrentTaskIdentifier(error)
306 }
307}