Re:Go 2 Draft Designs
by lclarkmichalek on Tuesday August 28, 2018 @02:22PM
(#17861388)
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.
[ Parent
| on HN ]
Re:Go 2 Draft Designs
by edflsafoiewq on Tuesday August 28, 2018 @04:17PM
(#17862476)
x? 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.You can use map_err or the failure crate's with_context to add context.