diff --git a/config/src/config.rs b/config/src/config.rs index eb14e9573..42b8f10d4 100644 --- a/config/src/config.rs +++ b/config/src/config.rs @@ -731,17 +731,7 @@ impl Config { std::env::remove_var("WEZTERM_CONFIG_FILE"); std::env::remove_var("WEZTERM_CONFIG_DIR"); - fn try_default() -> anyhow::Result { - let config = default_config_with_overrides_applied()?.compute_extra_defaults(None); - - Ok(LoadedConfig { - config: Ok(config), - file_name: None, - lua: Some(make_lua_context(Path::new(""))?), - }) - } - - match try_default() { + match Self::try_default() { Err(err) => LoadedConfig { config: Err(err), file_name: None, @@ -751,6 +741,16 @@ impl Config { } } + pub fn try_default() -> anyhow::Result { + let config = default_config_with_overrides_applied()?.compute_extra_defaults(None); + + Ok(LoadedConfig { + config: Ok(config), + file_name: None, + lua: Some(make_lua_context(Path::new(""))?), + }) + } + fn try_load( path_item: &PathPossibility, overrides: &wezterm_dynamic::Value, diff --git a/wezterm-gui/src/overlay/debug.rs b/wezterm-gui/src/overlay/debug.rs index d220a0aac..ab77fdc52 100644 --- a/wezterm-gui/src/overlay/debug.rs +++ b/wezterm-gui/src/overlay/debug.rs @@ -130,13 +130,17 @@ impl LineEditorHost for LuaReplHost { pub fn show_debug_overlay(mut term: TermWizTerminal, gui_win: GuiWin) -> anyhow::Result<()> { term.no_grab_mouse_in_raw_mode(); - let config::LoadedConfig { - lua, - config, - file_name: _, - } = config::Config::load(); - config?; - let lua = lua.ok_or_else(|| anyhow::anyhow!("failed to setup lua context"))?; + let config::LoadedConfig { lua, .. } = config::Config::load(); + // Try hard to fall back to some kind of working lua context even + // if the user's config file is temporarily out of whack + let lua = match lua { + Some(lua) => lua, + None => match config::Config::try_default() { + Ok(config::LoadedConfig { lua: Some(lua), .. }) => lua, + _ => config::lua::make_lua_context(std::path::Path::new(""))?, + }, + }; + lua.load("wezterm = require 'wezterm'").exec()?; lua.globals().set("window", gui_win)?;