This repository was archived by the owner on Aug 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 58
Construct a new Handler after already having created one / modify handler #149
Copy link
Copy link
Open
Description
I wanted to switch the style of a specific report, this to circumvent #122 not working and it not being formatted optimally with the env section being repeated.
I have the following code
pub fn add_reports(
origin: eyre::Report,
iter: impl IntoIterator<Item = eyre::Report>,
) -> eyre::Report {
use color_eyre::{Section as _, SectionExt as _};
iter.into_iter().fold(origin, |report, mut e| {
// Create a new Handler
let custom_handler = color_eyre::config::HookBuilder::new()
// disable env section
.display_env_section(false)
.into_hooks() // <---- Panic here!!!
.1
.into_eyre_hook();
let mut custom_handler = custom_handler(e.source().unwrap_or(e.root_cause()));
let custom_handler = custom_handler
.downcast_mut::<color_eyre::Handler>()
.unwrap();
// get the current Handler
let handler = e.handler_mut();
let handler = handler.downcast_mut::<color_eyre::Handler>().unwrap();
std::mem::swap(handler, custom_handler);
report.section(format!("{e:?}").header("Error:"))
})
}but I get a panic:
The application panicked (crashed).
Message: could not set the provided `Theme` via `color_spantrace::set_theme` globally as another was already set: InstallThemeError
Location: .cargo/registry/src/index.crates.io-6f17d22bba15001f/color-eyre-0.6.2/src/config.rs:756
Backtrace omitted. Run with RUST_BACKTRACE=1 environment variable to display it.
Run with RUST_BACKTRACE=full to include source snippets.
The issue is that HookBuilder::into_hooks calls color_spantrace::set_theme
This issue persists on the current master branch as well.
Now, I'm not sure if this is truly the way to go so I have two propositions that would make me happy.
- Provide a way to create a
EyreHookwithoutset_theme(this would also need a way to get the location I discovered, to propagate into the new handler) - Enable a way to change the settings on a specific report, e.g
report.handler_mut().downcast_mut::<color_eyre::Handler>().unwrap().display_env_section = false
I think that nr. 2 is the best option, since it makes it easy to customize a report "in-flight"
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels