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