diff --git a/tokio-console/src/config.rs b/tokio-console/src/config.rs index 9e0153e5d..04f14b917 100644 --- a/tokio-console/src/config.rs +++ b/tokio-console/src/config.rs @@ -330,6 +330,42 @@ impl Config { .clone() } + pub(crate) fn add_issue_metadata( + &self, + mut builder: color_eyre::config::HookBuilder, + ) -> color_eyre::config::HookBuilder { + macro_rules! add_issue_metadata { + ($self:ident, $builder:ident => + $( + $($name:ident).+ + ),+ + $(,)? + ) => { + $( + $builder = $builder.add_issue_metadata(concat!("config", $(".", stringify!($name)),+), format!("`{:?}`", $self$(.$name)+)); + )* + } + } + + add_issue_metadata! { + self, builder => + subcmd, + target_addr, + env_filter, + log_directory, + retain_for, + view_options.no_colors, + view_options.lang, + view_options.ascii_only, + view_options.truecolor, + view_options.palette, + view_options.toggles.color_durations, + view_options.toggles.color_terminated, + } + + builder + } + fn from_path(config_path: ConfigPath) -> color_eyre::Result> { ConfigFile::from_path(config_path)? .map(|config| config.try_into()) diff --git a/tokio-console/src/main.rs b/tokio-console/src/main.rs index 68bb5f402..c10b062a6 100644 --- a/tokio-console/src/main.rs +++ b/tokio-console/src/main.rs @@ -26,6 +26,13 @@ mod warnings; #[tokio::main] async fn main() -> color_eyre::Result<()> { let mut args = config::Config::parse()?; + // initialize error handling first, in case panics occur while setting up + // other stuff. + let styles = view::Styles::from_config(args.view_options.clone()); + styles.error_init(&args)?; + + args.trace_init()?; + tracing::debug!(?args.target_addr, ?args.view_options); match args.subcmd { Some(config::OptionalCmd::GenConfig) => { @@ -40,16 +47,10 @@ async fn main() -> color_eyre::Result<()> { None => {} } - let retain_for = args.retain_for(); - args.trace_init()?; - tracing::debug!(?args.target_addr, ?args.view_options); - let target = args.target_addr(); tracing::info!(?target, "using target addr"); - let styles = view::Styles::from_config(args.view_options); - styles.error_init()?; - + let retain_for = args.retain_for(); let (mut terminal, _cleanup) = term::init_crossterm()?; terminal.clear()?; let mut conn = conn::Connection::new(target); diff --git a/tokio-console/src/view/styles.rs b/tokio-console/src/view/styles.rs index 515308441..b71587c1d 100644 --- a/tokio-console/src/view/styles.rs +++ b/tokio-console/src/view/styles.rs @@ -47,12 +47,32 @@ impl Styles { } } - pub fn error_init(&self) -> color_eyre::Result<()> { - use color_eyre::config::{HookBuilder, Theme}; + pub fn error_init(&self, cfg: &crate::config::Config) -> color_eyre::Result<()> { + use color_eyre::{ + config::{HookBuilder, Theme}, + ErrorKind, + }; let mut builder = HookBuilder::new() .issue_url(concat!(env!("CARGO_PKG_REPOSITORY"), "/issues/new")) + .issue_filter(|kind| match kind { + // Only suggest reporting GitHub issues for panics, not for + // errors, so people don't open GitHub issues for stuff like not + // being able to find a config file or connections being + // terminated by remote hosts. + ErrorKind::NonRecoverable(_) => true, + ErrorKind::Recoverable(_) => false, + }) + // filter out `color-eyre`'s default set of frames to skip from + // backtraces. + // + // this includes `std::rt`, `color_eyre`'s own frames, and + // `tokio::runtime` & friends. + .add_default_filters() .add_issue_metadata("version", env!("CARGO_PKG_VERSION")); + // Add all the config values to the GitHub issue metadata + builder = cfg.add_issue_metadata(builder); + if self.palette == Palette::NoColors { // disable colors in error reports builder = builder.theme(Theme::new());