Skip to content

Commit bc68d3a

Browse files
Improve error output in case nodejs or npm is not installed for rustdoc-gui test suite
1 parent d2eadb7 commit bc68d3a

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

src/tools/rustdoc-gui-test/src/config.rs

+13-4
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ pub(crate) struct Config {
2020
impl Config {
2121
pub(crate) fn from_args(args: Vec<String>) -> Self {
2222
let mut opts = Options::new();
23-
opts.reqopt("", "nodejs", "absolute path of nodejs", "PATH")
24-
.reqopt("", "npm", "absolute path of npm", "PATH")
23+
opts.optopt("", "nodejs", "absolute path of nodejs", "PATH")
24+
.optopt("", "npm", "absolute path of npm", "PATH")
2525
.reqopt("", "out-dir", "output path of doc compilation", "PATH")
2626
.reqopt("", "rust-src", "root source of the rust source", "PATH")
2727
.reqopt(
@@ -47,9 +47,18 @@ impl Config {
4747
Err(f) => panic!("{:?}", f),
4848
};
4949

50+
let Some(nodejs) = matches.opt_str("nodejs").map(PathBuf::from) else {
51+
eprintln!("`nodejs` was not provided. If not available, please install it");
52+
std::process::exit(1);
53+
};
54+
let Some(npm) = matches.opt_str("npm").map(PathBuf::from) else {
55+
eprintln!("`npm` was not provided. If not available, please install it");
56+
std::process::exit(1);
57+
};
58+
5059
Self {
51-
nodejs: matches.opt_str("nodejs").map(PathBuf::from).expect("nodejs isn't available"),
52-
npm: matches.opt_str("npm").map(PathBuf::from).expect("npm isn't available"),
60+
nodejs,
61+
npm,
5362
rust_src: matches.opt_str("rust-src").map(PathBuf::from).unwrap(),
5463
out_dir: matches.opt_str("out-dir").map(PathBuf::from).unwrap(),
5564
initial_cargo: matches.opt_str("initial-cargo").map(PathBuf::from).unwrap(),

0 commit comments

Comments
 (0)