diff --git a/Cargo.toml b/Cargo.toml index 1265c35a..c7c7922e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -750,6 +750,7 @@ manual_let_else = "warn" trivially_copy_pass_by_ref = "warn" wildcard_imports = "warn" checked_conversions = "warn" +let_underscore_must_use = "warn" #integer_arithmetic = "warn" #as_conversions = "warn" @@ -767,7 +768,6 @@ mod_module_files = "allow" unwrap_used = "allow" expect_used = "allow" if_then_some_else_none = "allow" -let_underscore_must_use = "allow" let_underscore_future = "allow" map_err_ignore = "allow" missing_docs_in_private_items = "allow" diff --git a/src/admin/federation/federation_commands.rs b/src/admin/federation/federation_commands.rs index f461c237..3405b6fa 100644 --- a/src/admin/federation/federation_commands.rs +++ b/src/admin/federation/federation_commands.rs @@ -1,4 +1,4 @@ -use std::fmt::Write as _; +use std::fmt::Write; use ruma::{events::room::message::RoomMessageEventContent, OwnedRoomId, RoomId, ServerName, UserId}; @@ -20,7 +20,8 @@ pub(crate) async fn incoming_federeation(_body: Vec<&str>) -> Result, user_id: Box) members, escape_html(name) ) - .unwrap(); + .expect("should be able to write to string buffer"); output }) ); diff --git a/src/admin/room/room_alias_commands.rs b/src/admin/room/room_alias_commands.rs index f2b5c7eb..b767251a 100644 --- a/src/admin/room/room_alias_commands.rs +++ b/src/admin/room/room_alias_commands.rs @@ -1,4 +1,4 @@ -use std::fmt::Write as _; +use std::fmt::Write; use ruma::{events::room::message::RoomMessageEventContent, RoomAliasId}; @@ -79,12 +79,13 @@ pub(crate) async fn process(command: RoomAliasCommand, _body: Vec<&str>) -> Resu match aliases { Ok(aliases) => { let plain_list = aliases.iter().fold(String::new(), |mut output, alias| { - writeln!(output, "- {alias}").unwrap(); + writeln!(output, "- {alias}").expect("should be able to write to string buffer"); output }); let html_list = aliases.iter().fold(String::new(), |mut output, alias| { - writeln!(output, "
  • {}
  • ", escape_html(alias.as_ref())).unwrap(); + writeln!(output, "
  • {}
  • ", escape_html(alias.as_ref())) + .expect("should be able to write to string buffer"); output }); @@ -106,7 +107,8 @@ pub(crate) async fn process(command: RoomAliasCommand, _body: Vec<&str>) -> Resu let plain_list = aliases .iter() .fold(String::new(), |mut output, (alias, id)| { - writeln!(output, "- `{alias}` -> #{id}:{server_name}").unwrap(); + writeln!(output, "- `{alias}` -> #{id}:{server_name}") + .expect("should be able to write to string buffer"); output }); @@ -120,7 +122,7 @@ pub(crate) async fn process(command: RoomAliasCommand, _body: Vec<&str>) -> Resu escape_html(id.as_ref()), server_name ) - .unwrap(); + .expect("should be able to write to string buffer"); output }); diff --git a/src/admin/room/room_commands.rs b/src/admin/room/room_commands.rs index 701cfb54..50372e32 100644 --- a/src/admin/room/room_commands.rs +++ b/src/admin/room/room_commands.rs @@ -1,4 +1,4 @@ -use std::fmt::Write as _; +use std::fmt::Write; use ruma::{events::room::message::RoomMessageEventContent, OwnedRoomId}; @@ -48,7 +48,7 @@ pub(crate) async fn list(_body: Vec<&str>, page: Option) -> Result) -> members, escape_html(name.as_ref()) ) - .unwrap(); + .expect("should be able to write to string buffer"); output }) ); diff --git a/src/admin/room/room_moderation_commands.rs b/src/admin/room/room_moderation_commands.rs index 03de4cde..6a146454 100644 --- a/src/admin/room/room_moderation_commands.rs +++ b/src/admin/room/room_moderation_commands.rs @@ -122,7 +122,9 @@ pub(crate) async fn process(command: RoomModerationCommand, body: Vec<&str>) -> &local_user, &room_id ); - _ = leave_room(&local_user, &room_id, None).await; + if let Err(e) = leave_room(&local_user, &room_id, None).await { + warn!(%e, "Failed to leave room"); + } } } else { for local_user in services() @@ -329,7 +331,9 @@ pub(crate) async fn process(command: RoomModerationCommand, body: Vec<&str>) -> admins too)", &local_user, room_id ); - _ = leave_room(&local_user, &room_id, None).await; + if let Err(e) = leave_room(&local_user, &room_id, None).await { + warn!(%e, "Failed to leave room"); + } } } else { for local_user in services() diff --git a/src/admin/user/user_commands.rs b/src/admin/user/user_commands.rs index 2ec23f0d..7422a758 100644 --- a/src/admin/user/user_commands.rs +++ b/src/admin/user/user_commands.rs @@ -65,7 +65,8 @@ pub(crate) async fn create( .new_user_displayname_suffix .is_empty() { - _ = write!(displayname, " {}", services().globals.config.new_user_displayname_suffix); + write!(displayname, " {}", services().globals.config.new_user_displayname_suffix) + .expect("should be able to write to string buffer"); } services() diff --git a/src/api/client_server/account.rs b/src/api/client_server/account.rs index a786a836..8c945c74 100644 --- a/src/api/client_server/account.rs +++ b/src/api/client_server/account.rs @@ -1,4 +1,4 @@ -use std::fmt::Write as _; +use std::fmt::Write; use register::RegistrationKind; use ruma::{ @@ -241,7 +241,8 @@ pub(crate) async fn register_route(body: Ruma) -> Result< // If `new_user_displayname_suffix` is set, registration will push whatever // content is set to the user's display name with a space before it if !services().globals.new_user_displayname_suffix().is_empty() { - _ = write!(displayname, " {}", services().globals.config.new_user_displayname_suffix); + write!(displayname, " {}", services().globals.config.new_user_displayname_suffix) + .expect("should be able to write to string buffer"); } services() diff --git a/src/api/client_server/membership.rs b/src/api/client_server/membership.rs index 1cee7720..7ccea350 100644 --- a/src/api/client_server/membership.rs +++ b/src/api/client_server/membership.rs @@ -80,7 +80,9 @@ async fn banned_room_check(user_id: &UserId, room_id: Option<&RoomId>, server_na // ignore errors leave_all_rooms(user_id).await; - _ = services().users.deactivate_account(user_id); + if let Err(e) = services().users.deactivate_account(user_id) { + warn!(%e, "Failed to deactivate account"); + } } return Err(Error::BadRequest( @@ -115,7 +117,9 @@ async fn banned_room_check(user_id: &UserId, room_id: Option<&RoomId>, server_na // ignore errors leave_all_rooms(user_id).await; - _ = services().users.deactivate_account(user_id); + if let Err(e) = services().users.deactivate_account(user_id) { + warn!(%e, "Failed to deactivate account"); + } } return Err(Error::BadRequest( @@ -1548,8 +1552,12 @@ pub async fn leave_all_rooms(user_id: &UserId) { }; // ignore errors - _ = services().rooms.state_cache.forget(&room_id, user_id); - _ = leave_room(user_id, &room_id, None).await; + if let Err(e) = services().rooms.state_cache.forget(&room_id, user_id) { + warn!(%e, "Failed to forget room"); + } + if let Err(e) = leave_room(user_id, &room_id, None).await { + warn!(%e, "Failed to leave room"); + } } } diff --git a/src/api/client_server/profile.rs b/src/api/client_server/profile.rs index b6e4598d..96cbe7fd 100644 --- a/src/api/client_server/profile.rs +++ b/src/api/client_server/profile.rs @@ -12,6 +12,7 @@ use ruma::{ presence::PresenceState, }; use serde_json::value::to_raw_value; +use tracing::warn; use crate::{ service::{pdu::PduBuilder, user_is_local}, @@ -82,11 +83,14 @@ pub(crate) async fn set_displayname_route( ); let state_lock = mutex_state.lock().await; - _ = services() + if let Err(e) = services() .rooms .timeline .build_and_append_pdu(pdu_builder, sender_user, &room_id, &state_lock) - .await; + .await + { + warn!(%e, "Failed to update/send new display name in room"); + } } if services().globals.allow_local_presence() { @@ -224,11 +228,14 @@ pub(crate) async fn set_avatar_url_route( ); let state_lock = mutex_state.lock().await; - _ = services() + if let Err(e) = services() .rooms .timeline .build_and_append_pdu(pdu_builder, sender_user, &room_id, &state_lock) - .await; + .await + { + warn!(%e, "Failed to set/update room with new avatar URL / pfp"); + } } if services().globals.allow_local_presence() { diff --git a/src/api/client_server/room.rs b/src/api/client_server/room.rs index db0d4e4a..4593b2e4 100644 --- a/src/api/client_server/room.rs +++ b/src/api/client_server/room.rs @@ -388,7 +388,7 @@ pub(crate) async fn create_room_route(body: Ruma) -> R Error::BadRequest(ErrorKind::InvalidParam, "Invalid initial state event.") })?; - debug_warn!("initial state event: {event:?}"); + debug_info!("Room creation initial state event: {event:?}"); // client/appservice workaround: if a user sends an initial_state event with a // state event in there with the content of literally `{}` (not null or empty @@ -460,7 +460,9 @@ pub(crate) async fn create_room_route(body: Ruma) -> R // 8. Events implied by invite (and TODO: invite_3pid) drop(state_lock); for user_id in &body.invite { - _ = invite_helper(sender_user, user_id, &room_id, None, body.is_direct).await; + if let Err(e) = invite_helper(sender_user, user_id, &room_id, None, body.is_direct).await { + warn!(%e, "Failed to send invite"); + } } // Homeserver specific stuff @@ -815,7 +817,7 @@ pub(crate) async fn upgrade_room_route(body: Ruma) -> // Modify the power levels in the old room to prevent sending of events and // inviting new users - _ = services() + services() .rooms .timeline .build_and_append_pdu( diff --git a/src/core/config/mod.rs b/src/core/config/mod.rs index 4b85fb53..4a58f7d7 100644 --- a/src/core/config/mod.rs +++ b/src/core/config/mod.rs @@ -866,7 +866,7 @@ impl fmt::Display for Config { let mut msg: String = "Active config values:\n\n".to_owned(); for line in lines.into_iter().enumerate() { - let _ = writeln!(msg, "{}: {}", line.1 .0, line.1 .1); + writeln!(msg, "{}: {}", line.1 .0, line.1 .1).expect("should be able to write to string buffer"); } write!(f, "{msg}") diff --git a/src/database/rocksdb/mod.rs b/src/database/rocksdb/mod.rs index 3f39c292..1b7077fc 100644 --- a/src/database/rocksdb/mod.rs +++ b/src/database/rocksdb/mod.rs @@ -5,6 +5,7 @@ extern crate rust_rocksdb; use std::{ collections::HashMap, + fmt::Write, sync::{atomic::AtomicU32, Arc}, }; @@ -99,6 +100,7 @@ impl KeyValueDatabaseEngine for Arc { if !self.old_cfs.contains(&name.to_owned()) { // Create if it didn't exist debug!("Creating new column family in database: {}", name); + _ = self.rocks.create_cf(name, &self.opts); } @@ -141,22 +143,19 @@ impl KeyValueDatabaseEngine for Arc { fn memory_usage(&self) -> Result { let mut res = String::new(); let stats = get_memory_usage_stats(Some(&[&self.rocks]), Some(&[&self.row_cache]))?; - _ = std::fmt::write( - &mut res, - format_args!( - "Memory buffers: {:.2} MiB\nPending write: {:.2} MiB\nTable readers: {:.2} MiB\nRow cache: {:.2} MiB\n", - stats.mem_table_total as f64 / 1024.0 / 1024.0, - stats.mem_table_unflushed as f64 / 1024.0 / 1024.0, - stats.mem_table_readers_total as f64 / 1024.0 / 1024.0, - self.row_cache.get_usage() as f64 / 1024.0 / 1024.0, - ), - ); + writeln!( + res, + "Memory buffers: {:.2} MiB\nPending write: {:.2} MiB\nTable readers: {:.2} MiB\nRow cache: {:.2} MiB", + stats.mem_table_total as f64 / 1024.0 / 1024.0, + stats.mem_table_unflushed as f64 / 1024.0 / 1024.0, + stats.mem_table_readers_total as f64 / 1024.0 / 1024.0, + self.row_cache.get_usage() as f64 / 1024.0 / 1024.0, + ) + .expect("should be able to write to string buffer"); for (name, cache) in &self.col_cache { - _ = std::fmt::write( - &mut res, - format_args!("{} cache: {:.2} MiB\n", name, cache.get_usage() as f64 / 1024.0 / 1024.0,), - ); + writeln!(res, "{} cache: {:.2} MiB", name, cache.get_usage() as f64 / 1024.0 / 1024.0,) + .expect("should be able to write to string buffer"); } Ok(res) @@ -217,19 +216,17 @@ impl KeyValueDatabaseEngine for Arc { let options = BackupEngineOptions::new(path.unwrap())?; let engine = BackupEngine::open(&options, &self.env)?; for info in engine.get_backup_info() { - std::fmt::write( - &mut res, - format_args!( - "#{} {}: {} bytes, {} files\n", - info.backup_id, - DateTime::::from_timestamp(info.timestamp, 0) - .unwrap_or_default() - .to_rfc2822(), - info.size, - info.num_files, - ), + writeln!( + res, + "#{} {}: {} bytes, {} files", + info.backup_id, + DateTime::::from_timestamp(info.timestamp, 0) + .unwrap_or_default() + .to_rfc2822(), + info.size, + info.num_files, ) - .unwrap(); + .expect("should be able to write to string buffer"); } Ok(res) @@ -241,18 +238,12 @@ impl KeyValueDatabaseEngine for Arc { Ok(files) => { let mut res = String::new(); for file in files { - let _ = std::fmt::write( - &mut res, - format_args!( - "L{} {:<13} {:7}+ {:4}- {:9} {}
    ", - file.level, - file.name, - file.num_entries, - file.num_deletions, - file.size, - file.column_family_name, - ), - ); + writeln!( + res, + "L{} {:<13} {:7}+ {:4}- {:9} {}
    ", + file.level, file.name, file.num_entries, file.num_deletions, file.size, file.column_family_name, + ) + .expect("should be able to writeln to string buffer"); } Ok(res) }, diff --git a/src/router/run.rs b/src/router/run.rs index ee75ffec..27987145 100644 --- a/src/router/run.rs +++ b/src/router/run.rs @@ -81,8 +81,7 @@ pub(crate) async fn start(server: Arc) -> Result<(), Error> { services().start().await?; #[cfg(feature = "systemd")] - #[allow(clippy::let_underscore_untyped)] // error[E0658]: attributes on expressions are experimental - let _ = sd_notify::notify(true, &[sd_notify::NotifyState::Ready]); + sd_notify::notify(true, &[sd_notify::NotifyState::Ready]).expect("failed to notify systemd of ready state"); debug!("Started"); Ok(()) @@ -115,8 +114,7 @@ pub(crate) async fn stop(_server: Arc) -> Result<(), Error> { drop(s); #[cfg(feature = "systemd")] - #[allow(clippy::let_underscore_untyped)] // error[E0658]: attributes on expressions are experimental - let _ = sd_notify::notify(true, &[sd_notify::NotifyState::Stopping]); + sd_notify::notify(true, &[sd_notify::NotifyState::Stopping]).expect("failed to notify systemd of stopping state"); info!("Shutdown complete."); Ok(()) diff --git a/src/service/globals/updates.rs b/src/service/globals/updates.rs index 5f530736..9413c54a 100644 --- a/src/service/globals/updates.rs +++ b/src/service/globals/updates.rs @@ -3,7 +3,7 @@ use std::time::Duration; use ruma::events::room::message::RoomMessageEventContent; use serde::Deserialize; use tokio::{task::JoinHandle, time::interval}; -use tracing::{debug, error}; +use tracing::{debug, error, warn}; use crate::{ conduit::{Error, Result}, @@ -35,7 +35,9 @@ pub async fn start_check_for_updates_task() -> Result> { }, } - _ = try_handle_updates().await; + if let Err(e) = try_handle_updates().await { + warn!(%e, "Failed to check for updates"); + } } })) }