Skip to content

Commit d42e3ac

Browse files
Rollup merge of rust-lang#140556 - GuillaumeGomez:improve-rustdoc-gui-tool-error-output, r=clubby789
Improve error output in case `nodejs` or `npm` is not installed for rustdoc-gui test suite Fixes rust-lang#138134. It now looks like this: ![Screenshot From 2025-05-01 17-41-12](https://github.com/user-attachments/assets/ae7f2b37-3619-47ff-941d-5d9a7cdd9b6b) cc ``@kpreid``
2 parents 84ac890 + bc68d3a commit d42e3ac

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)