From: Carl Worth Date: Tue, 10 Mar 2026 15:08:01 +0000 (-0700) Subject: Switch from expect to map_err. X-Git-Url: https://git.cworth.org/git?a=commitdiff_plain;h=556edb7edc52dac4280361ccbd7da3f178338350;p=rust-learning Switch from expect to map_err. This lets us make a clean exit rather than triggering a panic, (which has some extra noise and suggests something more exceptional than we really want here). Note our message is reworded slightly since map_err doesn't give us full control of the string. It emits: Error: "" so we don't want to start our string with "Error" as that would look redundant. I don't love not having full control of the error message, but still, I think it is a reasonable compromise given how clean the code is with .map_err. --- diff --git a/src/main.rs b/src/main.rs index 657e481..7123ed3 100644 --- a/src/main.rs +++ b/src/main.rs @@ -15,7 +15,7 @@ async fn main() -> Result<(), Box> { let config_path = std::path::Path::new(&args[1]); let config = config::load_config(config_path) - .expect(format!("Error loading config file {}", args[1]).as_str()); + .map_err(|e| format!("Failed to open config file {}: {}", args[1], e))?; eprintln!("Race: {}", config.name);