shepmaster / snafu

Easily assign underlying errors into domain-specific errors while adding context
https://docs.rs/snafu/
Apache License 2.0
1.4k stars 60 forks source link

Consider adding `ResultExt::unwrap_report` #375

Open shepmaster opened 1 year ago

shepmaster commented 1 year ago
r.unwrap_report();

This would basically boil down to

match r {
    Ok(v) => v,
    Err(e) => panic!("{}", snafu::Report::from_error(e)),
}
Stargateur commented 1 year ago

unwrap_or_report() ? or just report() ?

Enet4 commented 1 year ago

I'd favor unwrap_report, which is a pattern already seen in wasm bindgen with unwrap_throw. report would work too, although this one does not convey so well the idea that it may panic. unwrap_or_report would falsely suggest that it creates a report instead of panicking.

8573 commented 1 year ago

unwrap_report sounds like the report is returned in the success (non-divergent) case, as the error is in unwrap_err. Maybe unwrap_reporting, with "reporting" modifying, rather than being an argument to, "unwrap"?

shepmaster commented 1 year ago

And riffing on that could be reporting_unwrap