rust-lang / mdBook

Create book from markdown files. Like Gitbook but implemented in Rust
https://rust-lang.github.io/mdBook/
Mozilla Public License 2.0
18.32k stars 1.64k forks source link

Bug: Preprocessor failure returns a status code of 0 #1872

Open markmandel opened 2 years ago

markmandel commented 2 years ago

Context:

I have mdbook build running through my CI system so that we can test if the documentation builds, and links exist, etc.

I recently realised that the documentation was failing to build, because the preprocessor was failing, but since it didn't affect the subsequent tests it was passing and went unnoticed for a while.

Logs:

➜  docs git:(main) mdbook build
2022-08-08 17:55:52 [INFO] (mdbook::book): Book building has started
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: No such file or directory (os error 2)', src/main.rs:121:10
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
2022-08-08 17:56:11 [INFO] (mdbook::book): Running the html backend
➜  docs git:(main) echo $?
0
➜  docs git:(main) ./preprocessor.sh
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: No such file or directory (os error 2)', src/main.rs:121:10
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
➜  docs git:(main) echo $?
101

As you can see above, my preprocessor.sh (which is the preprocessor) fails when executing directly, and if run on it's own returns a status of 101.

But when run through mdbook, it exits with a 0 as if nothing failed at all.

I'd love it if mdbook build returned a non-zero error code on preprocessor failure.

ehuss commented 2 years ago

Mdbook will return an error if the preprocessor fails when doing the preprocess step. However, it doesn't fail during the "supports" step. Unfortunately the preprocessor API can't distinguish between "the preprocessor supports a given renderer" and "the preprocessor crashed". It only knows that a non-zero exit code means the renderer isn't supported.

I think ideally a more sophisticated interface would help here (such as requiring the preprocessor to return some structured message on stdout to positively indicate that it supports the renderer).

markmandel commented 2 years ago

I think ideally a more sophisticated interface would help here (such as requiring the preprocessor to return some structured message on stdout to positively indicate that it supports the renderer).

That would work too!

ankitrgadiya commented 1 year ago

Adding to the context, if the preprocessor is not found, in that case too mdbook returns non-zero exit code.

$ mdbook build
2023-07-11 23:42:51 [INFO] (mdbook::book): Book building has started
2023-07-11 23:42:51 [WARN] (mdbook::preprocess::cmd): The command wasn't found, is the "hide" preprocessor installed?
2023-07-11 23:42:51 [WARN] (mdbook::preprocess::cmd):   Command: mdbook-hide
Warning: The mdbook-toc preprocessor was built against version 0.4.27 of mdbook, but we're being called from version 0.4.31
2023-07-11 23:42:51 [INFO] (mdbook::book): Running the html backend