4 ms·
I've not used Rust. Do you get to add context at the point of bailing?
by kitd 3y ago
I've not used Rust. Do you get to add context at the point of bailing?
- dthul 3y agoThat depends on the type you use to represent errors. A more "fancy" error type will allow you to add context / backtraces / whatever you want, while a simpler error type, for example just an error code, does not. (The error type is the E in Result<T, E>).
- oneshtein 3y agoNo, context is not added by default. With third party libraries like anyhow, it's possible to add context[0] before `?` operator in human-readable or machine-readable form: a_method().context("Failed to complete the work")?; a_method().context(FailedToCompleteTheWork)?; [0]: https://docs.rs/anyhow/latest/anyhow/trait.Context.html https://docs.rs/anyhow/latest/anyhow/trait.Context.html