diff options
| author | Matt Strapp <matt@mattstrapp.net> | 2025-11-19 10:36:26 -0600 |
|---|---|---|
| committer | Matt Strapp <matt@mattstrapp.net> | 2025-11-19 10:36:26 -0600 |
| commit | 9cc7dfc37f1db3b46f40158e9bc9f41fec2e6c06 (patch) | |
| tree | 769eb9745e40f8852ba2be15f8bfc642a7ba8b77 | |
| parent | Fix a missing pretty string (diff) | |
| download | wwb-9cc7dfc37f1db3b46f40158e9bc9f41fec2e6c06.tar wwb-9cc7dfc37f1db3b46f40158e9bc9f41fec2e6c06.tar.gz wwb-9cc7dfc37f1db3b46f40158e9bc9f41fec2e6c06.tar.bz2 wwb-9cc7dfc37f1db3b46f40158e9bc9f41fec2e6c06.tar.lz wwb-9cc7dfc37f1db3b46f40158e9bc9f41fec2e6c06.tar.xz wwb-9cc7dfc37f1db3b46f40158e9bc9f41fec2e6c06.tar.zst wwb-9cc7dfc37f1db3b46f40158e9bc9f41fec2e6c06.zip | |
only panic when the error is unrecoverable
Signed-off-by: Matt Strapp <matt@mattstrapp.net>
| -rw-r--r-- | wwb/src/main.rs | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/wwb/src/main.rs b/wwb/src/main.rs index 5ca78b4..3cea3ae 100644 --- a/wwb/src/main.rs +++ b/wwb/src/main.rs @@ -42,8 +42,14 @@ fn save_game(game: &Game, path: &str) { if path.is_empty() { return; } - let serialized_game = bincode::encode_to_vec(game, BINCODE_CONFIG).unwrap(); - fs::write(path, serialized_game).unwrap(); + let serialized_game = bincode::encode_to_vec(game, BINCODE_CONFIG).expect("Cannot encode to binary. Panicking!"); + match fs::write(path, serialized_game) { + Ok(_) => {}, + Err(err) => { + log::error!("Cannot write to file. Full error: {}", err); + log::error!("Game State: {:#?}", game); + } + } } /// This unholy abomination is used to turn a number like 10000 to "10,000". @@ -56,7 +62,7 @@ fn number_to_pretty_string(number: u128) -> String { .rev() .map(std::str::from_utf8) .collect::<Result<Vec<&str>, _>>() - .unwrap() + .unwrap_or([].to_vec()) .join(",") } @@ -91,6 +97,7 @@ fn main() { ctrlc::set_handler(move || { save_clone.store(true, Ordering::SeqCst); }) + // If the handler cannot be set, panicking is intended. .expect("Error setting Ctrl-C handler"); game_loop(&mut game, &path, &save); |
