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.
This commit is contained in:
@@ -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.
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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).
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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(())
|
||||
|
||||
Reference in New Issue
Block a user