From a96dccf6918aa18b509b42a217dc0388a7fb5ec6 Mon Sep 17 00:00:00 2001 From: Alexander Krylov Date: Sun, 25 Oct 2026 03:57:31 +0300 Subject: [PATCH] Save: the write paths report a failure instead of dropping it The moderation lists on a dedicated server, command storage, boss bars, the world clocks, the difficulty and the emergency save before a crash all used let _ = and lost the error. write_dat also swallowed the rename that moves the current file aside, which made the following rename fail on the existing path with nothing reporting it. --- crates/horizon-client/src/command_storage.rs | 6 ++++-- crates/horizon-client/src/game/bossbars.rs | 6 ++++-- crates/horizon-client/src/game/chat.rs | 8 ++++++-- crates/horizon-client/src/game/debug_keys.rs | 4 +++- crates/horizon-client/src/game/dedicated.rs | 17 +++++++++++++---- crates/horizon-client/src/save.rs | 5 ++++- 6 files changed, 34 insertions(+), 12 deletions(-) diff --git a/crates/horizon-client/src/command_storage.rs b/crates/horizon-client/src/command_storage.rs index ce6e88f5c..560423e90 100644 --- a/crates/horizon-client/src/command_storage.rs +++ b/crates/horizon-client/src/command_storage.rs @@ -55,7 +55,7 @@ impl CommandStorage { .iter() .map(|(k, v)| (k.as_str().into(), v.clone())) .collect(); - let _ = save::write_dat( + if let Err(e) = save::write_dat( &file(root, namespace), Tag::compound([ ( @@ -64,7 +64,9 @@ impl CommandStorage { ), ("DataVersion", Tag::Int(horizon_world::DATA_VERSION)), ]), - ); + ) { + log::warn!("command storage {namespace} was not written: {e}"); + } } } /// `get`: an empty compound when unset. diff --git a/crates/horizon-client/src/game/bossbars.rs b/crates/horizon-client/src/game/bossbars.rs index ec7b72632..f03257f18 100644 --- a/crates/horizon-client/src/game/bossbars.rs +++ b/crates/horizon-client/src/game/bossbars.rs @@ -47,13 +47,15 @@ impl Game<'_> { if self.bosses.bars.bars.is_empty() && !self.bossbar_path().exists() { return; } - let _ = save::write_dat( + if let Err(e) = save::write_dat( &self.bossbar_path(), Tag::compound([ ("data", self.bosses.bars.pack(self.level.player_uuid)), ("DataVersion", Tag::Int(horizon_world::DATA_VERSION)), ]), - ); + ) { + log::warn!("boss bars were not written: {e}"); + } } pub(in crate::game) fn bossbar_exists(&self, id: &str) -> bool { self.bosses.bars.get(id).is_some() diff --git a/crates/horizon-client/src/game/chat.rs b/crates/horizon-client/src/game/chat.rs index f760bd82f..d06d303ae 100644 --- a/crates/horizon-client/src/game/chat.rs +++ b/crates/horizon-client/src/game/chat.rs @@ -816,8 +816,12 @@ impl Game<'_> { ("data", data), ("DataVersion", Tag::Int(horizon_world::DATA_VERSION)), ]); - let _ = horizon_client::save::write_dat(&path, root); - let _ = write_difficulty(&self.world_root, self.ui.difficulty); + if let Err(e) = horizon_client::save::write_dat(&path, root) { + log::warn!("the world clocks were not written: {e}"); + } + if let Err(e) = write_difficulty(&self.world_root, self.ui.difficulty) { + log::warn!("the difficulty was not written: {e}"); + } } /// Death message in chat (CombatTracker.getDeathMessage, as far as the /// cause is known to the client). diff --git a/crates/horizon-client/src/game/debug_keys.rs b/crates/horizon-client/src/game/debug_keys.rs index e0ad706de..61e2b2f05 100644 --- a/crates/horizon-client/src/game/debug_keys.rs +++ b/crates/horizon-client/src/game/debug_keys.rs @@ -185,7 +185,9 @@ impl Game<'_> { // Minecraft.emergencySaveAndCrash: the world is saved, then the // game stops; main writes the crash report. let crash = horizon_client::crash::DebugCrash::new(); - let _ = self.save_game(); + if let Err(e) = self.save_game() { + log::error!("the emergency save before the crash failed: {e}"); + } return Err(crash.into()); } } diff --git a/crates/horizon-client/src/game/dedicated.rs b/crates/horizon-client/src/game/dedicated.rs index eee12fe3f..4e91b9704 100644 --- a/crates/horizon-client/src/game/dedicated.rs +++ b/crates/horizon-client/src/game/dedicated.rs @@ -225,14 +225,23 @@ impl Lists { }; // DedicatedPlayerList's constructor order. warn("user banlist", l.bans.load()); - let _ = l.bans.save(); + warn( + "user banlist write", + l.bans.save().map_err(|e| e.to_string()), + ); warn("ip banlist", l.ip_bans.load()); - let _ = l.ip_bans.save(); + warn( + "ip banlist write", + l.ip_bans.save().map_err(|e| e.to_string()), + ); warn("operators list", l.ops.load()); warn("white-list", l.white.load()); - let _ = l.ops.save(); + warn("operators write", l.ops.save().map_err(|e| e.to_string())); if !l.white.file.exists() { - let _ = l.white.save(); + warn( + "white-list write", + l.white.save().map_err(|e| e.to_string()), + ); } l } diff --git a/crates/horizon-client/src/save.rs b/crates/horizon-client/src/save.rs index 7819a9b0b..9dc7f62fd 100644 --- a/crates/horizon-client/src/save.rs +++ b/crates/horizon-client/src/save.rs @@ -1913,7 +1913,10 @@ pub fn write_dat(path: &Path, tag: Tag) -> Result<()> { Some(stem) => path.with_file_name(format!("{stem}.dat_old")), None => path.with_file_name(format!("{file}_old")), }; - let _ = fs::rename(path, old); + // Vanilla's safeReplaceFile moves the current file aside first. This used to be + // swallowed, and the rename below then failed on the existing path with nothing + // reporting it: a save that could not happen looked like one that did. + fs::rename(path, old).map_err(|e| format!("{}: {e}", path.display()))?; } fs::rename(temporary, path)?; Ok(())