Globally consistent error reporting formats #10
Description
Problem
Right now there's no easy way to ensure that all errors are printed with a consistent error report format such as via eyre::Report
+ color-eyre
. Errors that have not been converted to an error reporting type prior to panicking in functions like unwrap
cannot then be correctly reported via the panic handler because the error is converted to a string and discarded. Even if it was not such as via panic!(error)
directly you can only downcast to the exact type, so your error reporting hook would need an exhaustive list of all error types that it should try downcasting to, which is infeasible.
Possible Solutions
Carry original type in payloads for panics and add support for casting from &dyn Any
to &dyn Error
One possible approach to this would be to adjust panics to include the data they were created with in the payload along with the formatted message and then add support for somehow extracting error trait objects back out of those &dyn Any
playloads. Ideally the solution for extracting trait objects of other kinds from &dyn Any
would not be specific to &dyn Error
. If we could create a language / library level feature for casting between arbitrary trait objects or even only from &dyn Any
to arbitrary trait objects that the underlying type also implements that would be ideal.
@oli-obk has suggested the possibility of using linker shenanigans to accomplish this:
linker tricks could make that actually feasible to implement
like each type would allocate a named value and each impl block would append to that list
not sure how we'd get the order right
@DianaNites has pointed out that the following libraries may be useful as sources of prior art