Skip to content

Commit 3506c62

Browse files
Rollup merge of rust-lang#47387 - Rantanen:linkchecker-error-msg, r=steveklabnik
Report errors instead of panic!() when linkcheck encounters absolute paths The RBE contained some absolute links that failed the link check in rust-lang#46196. Diagnosing these issues was needlessly complicated, thanks to the linkchecker just panicing instead of reporting proper errors. This PR replaces the panic with a proper `*errors = true` + error message handling. The linkchecker itself doesn't have any tests so I intentionally didn't touch anything else than the code that previously did the `panic!()`. A small code quality improvement might be made by binding the `Path::new(base).join(url)` into a variable before the for-loop and using this resolved url in both the for loop and the error message. r? @steveklabnik (If not for any other reason than having r on the rust-lang#46196.)
2 parents bca76c1 + f7b4877 commit 3506c62

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/tools/linkchecker/main.rs

+11-1
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,17 @@ fn check(cache: &mut Cache,
192192
for part in Path::new(base).join(url).components() {
193193
match part {
194194
Component::Prefix(_) |
195-
Component::RootDir => panic!(),
195+
Component::RootDir => {
196+
// Avoid absolute paths as they make the docs not
197+
// relocatable by making assumptions on where the docs
198+
// are hosted relative to the site root.
199+
*errors = true;
200+
println!("{}:{}: absolute path - {}",
201+
pretty_file.display(),
202+
i + 1,
203+
Path::new(base).join(url).display());
204+
return;
205+
}
196206
Component::CurDir => {}
197207
Component::ParentDir => { path.pop(); }
198208
Component::Normal(s) => { path.push(s); }

0 commit comments

Comments
 (0)