Skip to content

Commit 227929f

Browse files
committed
simplify by using bail! macro
1 parent 5d46488 commit 227929f

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

crates/ra_env/src/lib.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//! [`get_path_for_executable`](fn.get_path_for_executable.html).
33
//! See docs there for more information.
44
5-
use anyhow::{Error, Result};
5+
use anyhow::{bail, Result};
66
use std::env;
77
use std::path::{Path, PathBuf};
88
use std::process::Command;
@@ -27,10 +27,10 @@ pub fn get_path_for_executable(executable_name: impl AsRef<str>) -> Result<PathB
2727
if is_valid_executable(&path) {
2828
Ok(path.into())
2929
} else {
30-
Err(Error::msg(format!(
30+
bail!(
3131
"`{}` environment variable points to something that's not a valid executable",
3232
env_var
33-
)))
33+
)
3434
}
3535
} else {
3636
if is_valid_executable(executable_name) {
@@ -50,7 +50,10 @@ pub fn get_path_for_executable(executable_name: impl AsRef<str>) -> Result<PathB
5050
// to inherit environment variables including $PATH, $CARGO, $RUSTC, etc from that terminal;
5151
// but launching VSCode from Dock does not inherit environment variables from a terminal.
5252
// For more discussion, see #3118.
53-
Err(Error::msg(format!("Failed to find `{}` executable. Make sure `{}` is in `$PATH`, or set `${}` to point to a valid executable.", executable_name, executable_name, env_var)))
53+
bail!(
54+
"Failed to find `{}` executable. Make sure `{}` is in `$PATH`, or set `${}` to point to a valid executable.",
55+
executable_name, executable_name, env_var
56+
)
5457
}
5558
}
5659

0 commit comments

Comments
 (0)