From 00996dd83441abac357e27b4bd325c8ccef62e75 Mon Sep 17 00:00:00 2001 From: Nyaaori <+@nyaaori.cat> Date: Mon, 31 Oct 2022 09:31:17 +0100 Subject: [PATCH 1/2] Cargo Clippy --- src/api/client_server/search.rs | 2 +- src/database/key_value/rooms/edus/typing.rs | 3 +-- src/main.rs | 5 ++++- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/api/client_server/search.rs b/src/api/client_server/search.rs index 1ba9cdfe..5b634a44 100644 --- a/src/api/client_server/search.rs +++ b/src/api/client_server/search.rs @@ -103,7 +103,7 @@ pub async fn search_events_route( .take(limit) .collect(); - let next_batch = if results.len() < limit as usize { + let next_batch = if results.len() < limit { None } else { Some((skip + limit).to_string()) diff --git a/src/database/key_value/rooms/edus/typing.rs b/src/database/key_value/rooms/edus/typing.rs index d2d43062..5709192c 100644 --- a/src/database/key_value/rooms/edus/typing.rs +++ b/src/database/key_value/rooms/edus/typing.rs @@ -1,5 +1,4 @@ -use std::collections::HashSet; -use std::mem; +use std::{collections::HashSet, mem}; use ruma::{OwnedUserId, RoomId, UserId}; diff --git a/src/main.rs b/src/main.rs index 695f0be6..72c6d516 100644 --- a/src/main.rs +++ b/src/main.rs @@ -28,7 +28,10 @@ use http::{ }; use opentelemetry::trace::{FutureExt, Tracer}; use ruma::api::{ - client::{error::Error as RumaError, error::ErrorKind, uiaa::UiaaResponse}, + client::{ + error::{Error as RumaError, ErrorKind}, + uiaa::UiaaResponse, + }, IncomingRequest, }; use tokio::signal; From 23cf39c525790122a97090b041e16b68e94644de Mon Sep 17 00:00:00 2001 From: Nyaaori <+@nyaaori.cat> Date: Mon, 31 Oct 2022 12:08:01 +0100 Subject: [PATCH 2/2] Cleanly handle invalid response from trusted server instead of panicking --- src/service/rooms/event_handler/mod.rs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/service/rooms/event_handler/mod.rs b/src/service/rooms/event_handler/mod.rs index 477a9719..3b41e86f 100644 --- a/src/service/rooms/event_handler/mod.rs +++ b/src/service/rooms/event_handler/mod.rs @@ -1464,7 +1464,17 @@ impl Service { .write() .map_err(|_| Error::bad_database("RwLock is poisoned."))?; for k in keys.server_keys { - let k = k.deserialize().unwrap(); + let k = match k.deserialize() { + Ok(key) => key, + Err(e) => { + warn!( + "Received error {} while fetching keys from trusted server {}", + e, server + ); + warn!("{}", k.into_json()); + continue; + } + }; // TODO: Check signature from trusted server? servers.remove(&k.server_name);