From 348575854dcd90aecb4ec9e76fa94bf132f44308 Mon Sep 17 00:00:00 2001 From: Wez Furlong Date: Tue, 30 Jul 2019 08:39:59 -0700 Subject: [PATCH] Capture terminal errors and show them in a message box This helps diagnose problems where stderr is not visible. Let's also capture them to the `log` stream too, and clarify toml parsing errors, and fix the underlying problem with ssh_domains not being allowed to be left unspecified. --- src/config.rs | 5 +++-- src/main.rs | 27 +++++++++++++++++++++------ 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/src/config.rs b/src/config.rs index 217600097..aaab3313c 100644 --- a/src/config.rs +++ b/src/config.rs @@ -83,6 +83,7 @@ pub struct Config { #[serde(default = "UnixDomain::default_unix_domains")] pub unix_domains: Vec, + #[serde(default)] pub ssh_domains: Vec, /// When running in server mode, defines configuration for @@ -803,7 +804,7 @@ impl Config { Ok(file) => file, Err(err) => match err.kind() { std::io::ErrorKind::NotFound => continue, - _ => bail!("Error opening {}: {:?}", p.display(), err), + _ => bail!("Error opening {}: {}", p.display(), err), }, }; @@ -811,7 +812,7 @@ impl Config { file.read_to_string(&mut s)?; let cfg: Self = toml::from_str(&s) - .map_err(|e| format_err!("Error parsing TOML from {}: {:?}", p.display(), e))?; + .map_err(|e| format_err!("Error parsing TOML from {}: {}", p.display(), e))?; // Compute but discard the key bindings here so that we raise any // problems earlier than we use them. diff --git a/src/main.rs b/src/main.rs index 57043ee65..4d0b5fe5c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -244,13 +244,21 @@ fn run_terminal_gui(config: Arc, opts: &StartCommand) -> Fallibl } fn main() -> Result<(), Error> { - let opts = Opt::from_args(); - let config = Arc::new(if opts.skip_config { - config::Config::default_config() - } else { - config::Config::load()? - }); + let result = run(); + if let Err(e) = &result { + let message = e.to_string(); + tinyfiledialogs::message_box_ok( + "wezterm", + &message, + tinyfiledialogs::MessageBoxIcon::Error, + ); + log::error!("{}", message); + } + result +} + +fn run() -> Result<(), Error> { // This is a bit gross. // In order to not to automatically open a standard windows console when // we run, we use the windows_subsystem attribute at the top of this @@ -285,6 +293,13 @@ fn main() -> Result<(), Error> { }; pretty_env_logger::init(); + let opts = Opt::from_args(); + let config = Arc::new(if opts.skip_config { + config::Config::default_config() + } else { + config::Config::load()? + }); + match opts .cmd .as_ref()