Return a Result instead of a vector
This commit is contained in:
parent
fb19114bd9
commit
91eb6c4d08
2 changed files with 21 additions and 13 deletions
|
@ -95,13 +95,17 @@ impl Admin {
|
||||||
|
|
||||||
match event {
|
match event {
|
||||||
AdminCommand::ListLocalUsers => {
|
AdminCommand::ListLocalUsers => {
|
||||||
let users = guard.users.get_local_users();
|
match guard.users.get_local_users() {
|
||||||
|
Ok(users) => {
|
||||||
let mut msg: String = format!("Found {} local user account(s):\n", users.len());
|
let mut msg: String = format!("Found {} local user account(s):\n", users.len());
|
||||||
msg += &users.join("\n");
|
msg += &users.join("\n");
|
||||||
|
|
||||||
send_message(RoomMessageEventContent::text_plain(&msg), guard, &state_lock);
|
send_message(RoomMessageEventContent::text_plain(&msg), guard, &state_lock);
|
||||||
}
|
}
|
||||||
|
Err(e) => {
|
||||||
|
send_message(RoomMessageEventContent::text_plain(e.to_string()), guard, &state_lock);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
AdminCommand::RegisterAppservice(yaml) => {
|
AdminCommand::RegisterAppservice(yaml) => {
|
||||||
guard.appservice.register_appservice(yaml).unwrap(); // TODO handle error
|
guard.appservice.register_appservice(yaml).unwrap(); // TODO handle error
|
||||||
}
|
}
|
||||||
|
|
|
@ -84,7 +84,6 @@ impl Users {
|
||||||
Ok(self.userid_password.iter().count())
|
Ok(self.userid_password.iter().count())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// Find out which user an access token belongs to.
|
/// Find out which user an access token belongs to.
|
||||||
#[tracing::instrument(skip(self, token))]
|
#[tracing::instrument(skip(self, token))]
|
||||||
pub fn find_from_token(&self, token: &str) -> Result<Option<(Box<UserId>, String)>> {
|
pub fn find_from_token(&self, token: &str) -> Result<Option<(Box<UserId>, String)>> {
|
||||||
|
@ -129,16 +128,21 @@ impl Users {
|
||||||
/// If utils::string_from_bytes returns an error that username will be skipped
|
/// If utils::string_from_bytes returns an error that username will be skipped
|
||||||
/// and the function will log the error
|
/// and the function will log the error
|
||||||
#[tracing::instrument(skip(self))]
|
#[tracing::instrument(skip(self))]
|
||||||
pub fn get_local_users(&self) -> Vec<String> {
|
pub fn get_local_users(&self) -> Result<Vec<String>> {
|
||||||
self.userid_password.iter().filter(|(_, pw)| pw.len() > 0).map(|(username, _)| {
|
self.userid_password
|
||||||
match utils::string_from_bytes(&username) {
|
.iter()
|
||||||
|
.filter(|(_, pw)| pw.len() > 0)
|
||||||
|
.map(|(username, _)| match utils::string_from_bytes(&username) {
|
||||||
Ok(s) => s,
|
Ok(s) => s,
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
Error::bad_database(format!("Failed to parse username: {}", e.to_string()));
|
Error::bad_database(format!(
|
||||||
|
"Failed to parse username while calling get_local_users(): {}",
|
||||||
|
e.to_string()
|
||||||
|
));
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
}
|
})
|
||||||
}).collect::<Vec<String>>()
|
.collect::<Result<Vec<String>>>()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the password hash for the given user.
|
/// Returns the password hash for the given user.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue