mirror of
https://gitlab.com/famedly/conduit.git
synced 2024-11-04 16:28:53 +01:00
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,12 +95,16 @@ impl Admin {
|
|||
|
||||
match event {
|
||||
AdminCommand::ListLocalUsers => {
|
||||
let users = guard.users.get_local_users();
|
||||
|
||||
let mut msg: String = format!("Found {} local user account(s):\n", users.len());
|
||||
msg += &users.join("\n");
|
||||
|
||||
send_message(RoomMessageEventContent::text_plain(&msg), guard, &state_lock);
|
||||
match guard.users.get_local_users() {
|
||||
Ok(users) => {
|
||||
let mut msg: String = format!("Found {} local user account(s):\n", users.len());
|
||||
msg += &users.join("\n");
|
||||
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) => {
|
||||
guard.appservice.register_appservice(yaml).unwrap(); // TODO handle error
|
||||
|
|
|
@ -84,7 +84,6 @@ impl Users {
|
|||
Ok(self.userid_password.iter().count())
|
||||
}
|
||||
|
||||
|
||||
/// Find out which user an access token belongs to.
|
||||
#[tracing::instrument(skip(self, token))]
|
||||
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
|
||||
/// and the function will log the error
|
||||
#[tracing::instrument(skip(self))]
|
||||
pub fn get_local_users(&self) -> Vec<String> {
|
||||
self.userid_password.iter().filter(|(_, pw)| pw.len() > 0).map(|(username, _)| {
|
||||
match utils::string_from_bytes(&username) {
|
||||
pub fn get_local_users(&self) -> Result<Vec<String>> {
|
||||
self.userid_password
|
||||
.iter()
|
||||
.filter(|(_, pw)| pw.len() > 0)
|
||||
.map(|(username, _)| match utils::string_from_bytes(&username) {
|
||||
Ok(s) => s,
|
||||
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
|
||||
}
|
||||
}
|
||||
}).collect::<Vec<String>>()
|
||||
})
|
||||
.collect::<Result<Vec<String>>>()
|
||||
}
|
||||
|
||||
/// Returns the password hash for the given user.
|
||||
|
|
Loading…
Reference in a new issue