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
This commit is contained in:
Yuya Nishihara 2023-11-23 09:10:13 +09:00
parent 31def4b131
commit 13c93d5270
3 changed files with 14 additions and 7 deletions

View file

@ -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"

View file

@ -447,6 +447,12 @@ pub enum CommandNameAndArgs {
}
impl CommandNameAndArgs {
/// Returns command name without arguments.
pub fn split_name(&self) -> Cow<str> {
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.)

View file

@ -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();
}