From 0e42d8b6c1cd331cf5f0c6fed6d1fa193566fd5d Mon Sep 17 00:00:00 2001 From: teor Date: Wed, 2 Dec 2020 15:45:16 +1000 Subject: [PATCH] Always enable color_eyre, even when color is disabled We want to automatically disable colors upstream in color_eyre, and add a config that allows users to always turn off color. --- zebrad/src/application.rs | 40 ++++++++++++++++++--------------------- 1 file changed, 18 insertions(+), 22 deletions(-) diff --git a/zebrad/src/application.rs b/zebrad/src/application.rs index e73f6a56..e1aa79bc 100644 --- a/zebrad/src/application.rs +++ b/zebrad/src/application.rs @@ -110,6 +110,24 @@ impl Application for ZebradApp { } let terminal = Terminal::new(term_colors); + // This MUST happen after `Terminal::new` to ensure our preferred panic + // handler is the last one installed + // + // color_eyre always uses color, but that's an issue we want to solve upstream + // (color_backtrace automatically disables color if stderr is a file) + color_eyre::config::HookBuilder::default() + .issue_url(concat!(env!("CARGO_PKG_REPOSITORY"), "/issues/new")) + .add_issue_metadata("version", env!("CARGO_PKG_VERSION")) + .add_issue_metadata("git commit", Self::GIT_COMMIT) + .issue_filter(|kind| match kind { + color_eyre::ErrorKind::NonRecoverable(_) => true, + color_eyre::ErrorKind::Recoverable(error) => { + !error.is::() + } + }) + .install() + .unwrap(); + Ok(vec![Box::new(terminal)]) } @@ -133,28 +151,6 @@ impl Application for ZebradApp { .transpose()? .unwrap_or_default(); - // Only use color if tracing output is being sent to a terminal - let use_color = config.tracing.use_color && atty::is(atty::Stream::Stdout); - - // color_eyre always uses color, so disable it if we don't want color - // (color_backtrace automatically disables color if stderr is a file) - if use_color { - // This MUST happen after `Terminal::new` to ensure our preferred panic - // handler is the last one installed - color_eyre::config::HookBuilder::default() - .issue_url(concat!(env!("CARGO_PKG_REPOSITORY"), "/issues/new")) - .add_issue_metadata("version", env!("CARGO_PKG_VERSION")) - .add_issue_metadata("git commit", Self::GIT_COMMIT) - .issue_filter(|kind| match kind { - color_eyre::ErrorKind::NonRecoverable(_) => true, - color_eyre::ErrorKind::Recoverable(error) => { - !error.is::() - } - }) - .install() - .unwrap(); - } - let config = command.process_config(config)?; self.config = Some(config);