Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

emit error when doc generation fails #55933

Merged
merged 1 commit into from
Dec 5, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/librustdoc/html/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,8 @@ impl Impl {

#[derive(Debug)]
pub struct Error {
file: PathBuf,
error: io::Error,
pub file: PathBuf,
pub error: io::Error,
}

impl error::Error for Error {
Expand Down
18 changes: 15 additions & 3 deletions src/librustdoc/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -387,9 +387,21 @@ fn main_args(args: &[String]) -> isize {
info!("going to format");
let (error_format, treat_err_as_bug, ui_testing) = diag_opts;
let diag = core::new_handler(error_format, None, treat_err_as_bug, ui_testing);
html::render::run(krate, renderopts, passes.into_iter().collect(), renderinfo, &diag)
.expect("failed to generate documentation");
0
match html::render::run(
krate,
renderopts,
passes.into_iter().collect(),
renderinfo,
&diag,
) {
Ok(_) => rustc_driver::EXIT_SUCCESS,
Err(e) => {
diag.struct_err(&format!("couldn't generate documentation: {}", e.error))
.note(&format!("failed to create or modify \"{}\"", e.file.display()))
.emit();
rustc_driver::EXIT_FAILURE
}
}
})
}

Expand Down
25 changes: 25 additions & 0 deletions src/test/run-make-fulldeps/rustdoc-io-error/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
-include ../tools.mk

# This test verifies that rustdoc doesn't ICE when it encounters an IO error
# while generating files. Ideally this would be a rustdoc-ui test, so we could
# verify the error message as well.

OUTPUT_DIR := "$(TMPDIR)/rustdoc-io-error"

# Ignore Windows: the test uses `chmod`.
ifndef IS_WINDOWS

# This test operates by creating a temporary directory and modifying its
# permissions so that it is not writable. We have to take special care to set
# the permissions back to normal so that it's able to be deleted later.
all:
mkdir -p $(OUTPUT_DIR)
chmod u-w $(OUTPUT_DIR)
-$(shell $(RUSTDOC) -o $(OUTPUT_DIR) foo.rs)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this save the exit status into $(.SHELLSTATUS) for later? I'm not familiar with this syntax.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool, thanks for the link!

chmod u+w $(OUTPUT_DIR)
exit $($(.SHELLSTATUS) -eq 1)

else
all:

endif
1 change: 1 addition & 0 deletions src/test/run-make-fulldeps/rustdoc-io-error/foo.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub struct Foo;