Skip to content

Commit

Permalink
Rollup merge of rust-lang#47387 - Rantanen:linkchecker-error-msg, r=s…
Browse files Browse the repository at this point in the history
…teveklabnik

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.)
  • Loading branch information
GuillaumeGomez authored Jan 16, 2018
2 parents bca76c1 + f7b4877 commit 3506c62
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/tools/linkchecker/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,17 @@ fn check(cache: &mut Cache,
for part in Path::new(base).join(url).components() {
match part {
Component::Prefix(_) |
Component::RootDir => panic!(),
Component::RootDir => {
// Avoid absolute paths as they make the docs not
// relocatable by making assumptions on where the docs
// are hosted relative to the site root.
*errors = true;
println!("{}:{}: absolute path - {}",
pretty_file.display(),
i + 1,
Path::new(base).join(url).display());
return;
}
Component::CurDir => {}
Component::ParentDir => { path.pop(); }
Component::Normal(s) => { path.push(s); }
Expand Down

0 comments on commit 3506c62

Please sign in to comment.