eyre-rs / color-eyre

Custom hooks for colorful human oriented error reports via panics and the eyre crate
Other
958 stars 57 forks source link

How to access fields of a Report #121

Open ghost opened 1 year ago

ghost commented 1 year ago

I'm trying to display Reports in an app of mine (using ImGUI), and I'm having trouble accessing the data hidden inside the Report. For example, I'd like to access the backtrace and spantrace (preferably as raw structs not strings), and then do things to make them appear in the UI.

I can't access these on the Report object because it doesn't provide access to any.

One solution is to downcast to a concrete type:

report
    .handler()
    .downcast_ref::<color_eyre::Handler>()
    .map(|h| h.spantrace())

This only lets me access the SpanTrace and BackTrace though, but not the location (file) or any Sections. I think I might be able to get the location form the BackTrace, but I'm not sure since I haven't used that crate directly before. Also, downcasting like this isn't good, because what if the handler isn't the default eyre handler but something else, then my code completely breaks.

Any help would be much appreciated (especially if I'm barking up the wrong tree and looking in the wrong spot)