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: "<our-string>"
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.
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);