From 13c93d5270581e0867256c547c4770aafeb26615 Mon Sep 17 00:00:00 2001 From: Yuya Nishihara Date: Thu, 23 Nov 2023 09:10:13 +0900 Subject: [PATCH] cli: show executable name in error message, include underlying error details Since this is the error to spawn (or wait) process, command arguments aren't important. Let's make that clear by not showing full command string. #2614 --- cli/src/cli_util.rs | 11 ++++++----- cli/src/config.rs | 6 ++++++ cli/src/ui.rs | 4 ++-- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/cli/src/cli_util.rs b/cli/src/cli_util.rs index 155d6e557..d8d875e2e 100644 --- a/cli/src/cli_util.rs +++ b/cli/src/cli_util.rs @@ -2294,11 +2294,12 @@ pub fn run_ui_editor(settings: &UserSettings, edit_path: &PathBuf) -> Result<(), .config() .get("ui.editor") .map_err(|err| CommandError::ConfigError(format!("ui.editor: {err}")))?; - let exit_status = editor - .to_command() - .arg(edit_path) - .status() - .map_err(|_| user_error(format!("Failed to run editor '{editor}'")))?; + let exit_status = editor.to_command().arg(edit_path).status().map_err(|err| { + user_error(format!( + "Failed to run editor '{name}': {err}", + name = editor.split_name(), + )) + })?; if !exit_status.success() { return Err(user_error(format!( "Editor '{editor}' exited with an error" diff --git a/cli/src/config.rs b/cli/src/config.rs index 2060605f9..453d7dabe 100644 --- a/cli/src/config.rs +++ b/cli/src/config.rs @@ -447,6 +447,12 @@ pub enum CommandNameAndArgs { } impl CommandNameAndArgs { + /// Returns command name without arguments. + pub fn split_name(&self) -> Cow { + let (name, _) = self.split_name_and_args(); + name + } + /// Returns command name and arguments. /// /// The command name may be an empty string (as well as each argument.) diff --git a/cli/src/ui.rs b/cli/src/ui.rs index a94c125ef..0479aac4c 100644 --- a/cli/src/ui.rs +++ b/cli/src/ui.rs @@ -224,8 +224,8 @@ impl Ui { Err(e) => { writeln!( self.warning(), - "Failed to spawn pager '{cmd}': {e}", - cmd = self.pager_cmd, + "Failed to spawn pager '{name}': {e}", + name = self.pager_cmd.split_name(), ) .ok(); }