From ec66eda67fd3a4de626299bd979cb174a2dd87bd Mon Sep 17 00:00:00 2001 From: Eliza Weisman Date: Fri, 5 Aug 2022 12:51:52 -0700 Subject: [PATCH] feat(console): init error handling before subcmds (#365) This way, if running a subcommand panics/errors, we still get nice `color-eyre` reports. --- tokio-console/src/main.rs | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/tokio-console/src/main.rs b/tokio-console/src/main.rs index 68bb5f402..50f6eb720 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.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);