4 ms·
I would recommend the `anyhow` crate and use of anyhow::Context to annotate errors on the return path within applications, like: falliable_func().context("fa
by jgraettinger1 1y ago
I would recommend the `anyhow` crate and use of anyhow::Context to annotate errors on the return path within applications, like:
falliable_func().context("failed to frob the peanut")?
Combine that with the `thiserror` crate for implementing errors within a library context. `thiserror` makes it easy to implement structured errors which embed other errors, and plays well with `anyhow`.
- kaathewise 1y agoYeah, I found `anyhow`'s `Contex` to be a great way of annotating bubbled up errors. The only problem is that using the lazy `with_context` can get somewhat unwieldy. For all the grief people give to Go's `if err != nil` Rust's method chaining can get out of hand too. One particular offender I wrote: match operator.propose(py).with_context(|| { anyhow!( "Operator {} failed while generating a proposal", operator.repr(py).unwrap() ) })? { Which is a combination of `rustfmt` giving up on long lines and also not formatting macros as well as functions
- deleted 1y ago[deleted]