From f1d72e2670d759ef7556d680836113334bd88145 Mon Sep 17 00:00:00 2001 From: Scott Boggs Date: Sun, 28 Aug 2022 05:56:55 -0400 Subject: [PATCH] better error handling for nu_command::env::conig::utils::get_editor (#6430) --- crates/nu-command/src/env/config/config_env.rs | 2 +- crates/nu-command/src/env/config/config_nu.rs | 2 +- crates/nu-command/src/env/config/utils.rs | 15 +++++++++------ 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/crates/nu-command/src/env/config/config_env.rs b/crates/nu-command/src/env/config/config_env.rs index 9e91e77f48..ec41bf2537 100644 --- a/crates/nu-command/src/env/config/config_env.rs +++ b/crates/nu-command/src/env/config/config_env.rs @@ -58,7 +58,7 @@ impl Command for ConfigEnv { nu_config.push("env.nu"); let name = Spanned { - item: get_editor(engine_state, stack), + item: get_editor(engine_state, stack)?, span: Span { start: 0, end: 0 }, }; diff --git a/crates/nu-command/src/env/config/config_nu.rs b/crates/nu-command/src/env/config/config_nu.rs index 6eb9ff63d1..55a6c98ab6 100644 --- a/crates/nu-command/src/env/config/config_nu.rs +++ b/crates/nu-command/src/env/config/config_nu.rs @@ -58,7 +58,7 @@ impl Command for ConfigNu { nu_config.push("config.nu"); let name = Spanned { - item: get_editor(engine_state, stack), + item: get_editor(engine_state, stack)?, span: Span { start: 0, end: 0 }, }; diff --git a/crates/nu-command/src/env/config/utils.rs b/crates/nu-command/src/env/config/utils.rs index 91df864a61..f0c07a6f70 100644 --- a/crates/nu-command/src/env/config/utils.rs +++ b/crates/nu-command/src/env/config/utils.rs @@ -1,17 +1,20 @@ use nu_protocol::engine::{EngineState, Stack}; -pub(crate) fn get_editor(engine_state: &EngineState, stack: &mut Stack) -> String { +pub(crate) fn get_editor( + engine_state: &EngineState, + stack: &mut Stack, +) -> Result { let config = engine_state.get_config(); let env_vars = stack.get_env_vars(engine_state); if !config.buffer_editor.is_empty() { - config.buffer_editor.clone() + Ok(config.buffer_editor.clone()) } else if let Some(value) = env_vars.get("EDITOR") { - value.as_string().expect("Unknown type") + value.as_string() } else if let Some(value) = env_vars.get("VISUAL") { - value.as_string().expect("Unknown type") + value.as_string() } else if cfg!(target_os = "windows") { - "notepad".to_string() + Ok("notepad".to_string()) } else { - "nano".to_string() + Ok("nano".to_string()) } }