4 ms·
This is something I don't enjoy about Rust's error handling. The context is added on a package level (or at least, the level at which the Error type is defined,
by lclarkmichalek 8y ago
This is something I don't enjoy about Rust's error handling. The context is added on a package level (or at least, the level at which the Error type is defined, which seems to be usually package level), and often quite far away from where the error was emitted. For all its ills, `errors.Wrap(err, "...")` puts the adding of context incredibly close to the place where the error is relevant.
- cpuguy83 8y agoWhat do you think are the ills of errors.Wrap?
- edflsafoiewq 8y agox? will convert the error type for x, E1, to the error type for the calling function, E2, only when a conversion from E1 to E2 is defined. If its not possible to do this conversion without some contextual information, then this bare conversion can't be defined and x? will not compile. In that case, callers will have to do something like x.context(...)? x.map_err(|e| ...)? ...etc... so they have to provide contextual information.
- IshKebab 8y agoYou can use map_err or the failure crate's with_context to add context.