-
Notifications
You must be signed in to change notification settings - Fork 966
Errors should return source instead of displaying it #831
Description
Not displaying the source and returning it from the source method is better for consumers as they may want to display error sources differently (line-by-line is a popular example, even Cargo does it). We're currently displaying sources together with messages. We should change it to use source.
There's one issue though: no_std would lose sources which may be annoying. I was previously ignoring this issue in my projects but I came up with a hopefully reasonable solution: continue displaying the source in no_std builds. This looks a bit backwards ("cargo features are supposed to be additive") but shouldn't break things unless people are foolishly matching against strings.
Another issue is adding cfgs could be annoying but I believe it can be easily solved with a macro. Something like this:
match error {
Error::Foo(source) => write_err!(f, source, "some message"),
Error::Bar(details, source) => write_err!(f, source, "the thing {} went wrong", details),
}Perhaps it'd be even easier with something like amplify that could generate it together with std Error impl. Cc @dr-orlovsky