Skip to content

Commit

Permalink
Improve error message for invalid executors (#99)
Browse files Browse the repository at this point in the history
* Improve error message for invalid executors

* Add test for custom error
  • Loading branch information
brumhard committed May 3, 2023
1 parent 99e6a60 commit 5567ad8
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
17 changes: 16 additions & 1 deletion mask/src/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,22 @@ pub fn execute_command(cmd: Command, maskfile_path: String) -> Result<ExitStatus
child = add_utility_variables(child, maskfile_path);
child = add_flag_variables(child, &cmd);

child.spawn()?.wait()
child
.spawn()
.map_err(|e| {
if e.kind() != ErrorKind::NotFound {
return e;
}
Error::new(
ErrorKind::NotFound,
format!(
"program '{}' for executor '{}' not in PATH",
child.get_program().to_string_lossy(),
script.executor
),
)
})?
.wait()
}

fn prepare_command(cmd: &Command) -> process::Command {
Expand Down
22 changes: 22 additions & 0 deletions mask/tests/supported_runtimes_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,28 @@ echo "this won't do anything..."
.failure();
}

#[test]
fn custom_not_found_error_if_program_not_found() {
let (_temp, maskfile_path) = common::maskfile(
r#"
## missing
~~~notfound
echo "this won't do anything..."
~~~
"#,
);

common::run_mask(&maskfile_path)
.command("missing")
.assert()
.code(1)
.stderr(contains(format!(
"{} program 'notfound' for executor 'notfound' not in PATH",
"ERROR:".red()
)))
.failure();
}

#[cfg(windows)]
#[test]
fn powershell() {
Expand Down

0 comments on commit 5567ad8

Please sign in to comment.