Say I have some program that during initialization reads in two different files, Config and Data. The kind of error here could be PermissionDenied, NotFound, etc. Is there some idiomatic way of implementing From such that the ? operator could, for example, return OpenConfigFilePermissionDenied for an error operning the config file or OpenDataFileNotFound for the data file depending on the context of the error, ie where the error occurred.
The implementation of std::io::Error is interesting in this regard. It has Simple and Custom variants, but it still can't use any contextual information when converting to another error.
Hm, sorry i seem to have misunderstood your original question initially. Maybe backtrace could be abused to select the error based on the calling function, but i don't think that's cleaner than doing .map_err at the call site.