|
|
|
|
|
by JoelJacobson
1038 days ago
|
|
Author of `wherr` here. I can totally relate to the situation you describe. That's exactly what happened to me, and why I created wherr. At first, I couldn't understand why I couldn't find the `?` line in the backtrace. `anyhow`'s `with_context` is great, but seems to require you to modify each line of code where errors are created, to find the error. With `wherr`, you only need to add one line of code, `#[wherr]`, per function. |
|
Really we’d need rustc to support some kind of AOP technique that lets you inject code at every call site somehow. That way you write the extra context info in a single macro that gets applied transparently for you.
That being said, SNAFU’s approach seems better in the interim. Just add a Location (and presumably there’s a backtrace option too) to your error type and it’s captured automatically without any macros.