Skip to content

Commit

Permalink
cli: show executable name in error message, include underlying error …
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
yuja committed Nov 23, 2023
1 parent 31def4b commit 13c93d5
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
11 changes: 6 additions & 5 deletions cli/src/cli_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
6 changes: 6 additions & 0 deletions cli/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.)
Expand Down
4 changes: 2 additions & 2 deletions cli/src/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down

0 comments on commit 13c93d5

Please sign in to comment.