2 ms·
We opted for a more manual approach, we have a ctx!() macro[1] we use for wrapping errors we want to enrich that we then use like this[2]: ctx!(some_fallible_fu
by tasn 3y ago
We opted for a more manual approach, we have a ctx!() macro[1] we use for wrapping errors we want to enrich that we then use like this[2]: ctx!(some_fallible_fund(foo))?
I wodner if anyone is doing anything better? The nice thing about our approach is that we store the data on each error, so we get a full backtrace, even when using async.
1: https://github.com/svix/svix-webhooks/blob/main/server/svix-server/src/error.rs#L168 https://github.com/svix/svix-webhooks/blob/main/server/svix-...
2: https://github.com/svix/svix-webhooks/blob/main/server/svix-server/src/v1/endpoints/application.rs#L258 https://github.com/svix/svix-webhooks/blob/main/server/svix-...
- shepmaster 3y agoIn SNAFU, you can add a Location [0] type to your error which will automatically capture that information when you add context to your error [0] https://docs.rs/snafu/latest/snafu/struct.Location.html https://docs.rs/snafu/latest/snafu/struct.Location.html
- tasn 3y agoWe have a similar structure in our code. How does snafu get filename and line number when adding context? Context usually added like this: `some_error.context("bloop")`, no? Which can't get the line info, that's why we used a macro.
- shepmaster 3y agoYou will want to use `Location::caller` [0] instead of the `line` macro (and friends). You will need to annotate enough places with `#[track_caller]` so the location is correct. [0]: https://doc.rust-lang.org/std/panic/struct.Location.html#method.caller https://doc.rust-lang.org/std/panic/struct.Location.html#met...
- tasn 3y agoAh, gotcha! We are actually going to try what the sibling comment recommended. https://news.ycombinator.com/item?id=37235165 https://news.ycombinator.com/item?id=37235165