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

Mechanism to add sections in hook callback #137

Open ColonelThirtyTwo opened 11 months ago

ColonelThirtyTwo commented 11 months ago

It'd be convenient if a callback could be registered with color_eyre::config::HookBuilder that gets called with the error passed to the EyreHandler and can add sections to the returned Report.

My use case is annotating 3rd party errors with additional info by downcasting them from the std::error::Error reference. For example, I could create a section with the url, status, and body from a reqwest::Error without having to annotate every single place where the conversion happens.

I could potentially do this by wrapping the color_eyre::config::EyreHook returned by the HookBuilder but it's limited to writing some text before and/or after the call to Handler.debug/display, which isn't pretty.