Skip to content

Exit if a preprocessor command is not found #2597

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

Bktero
Copy link

@Bktero Bktero commented Mar 16, 2025

A small change discussed in issue #2493

When a command is not found, log an error and exit the application instead of simply logging a warning. Indeed, the generator of the book will probably be wrong anyway, so exiting seems legit.

@rustbot rustbot added the S-waiting-on-review Status: waiting on a review label Mar 16, 2025
@ehuss
Copy link
Contributor

ehuss commented Mar 21, 2025

I don't think this is something we can do right now, since I believe there are some setups where it is expected to be allowed. Perhaps we could introduce an optional field like there is for renderers (like #1122)? Although that would need to default to false for now.

@szabgab
Copy link
Contributor

szabgab commented Mar 21, 2025

I think we could add an optional field as @ehuss suggested that would turn these warnings into errors. By default it would be false, but when a new book is created with init then it would be added to the book.toml file and it would be true.
Suggested name of the field: error_on_missing_preprocessor

@Bktero
Copy link
Author

Bktero commented Mar 22, 2025

I have added a commit that tries to implement this flag. Is this something like this you had in mind?

There are still 2 points that I need to figure out:;

  1. The flag isn't written to book.toml by the init command.
  2. The flag is considered to be true is missing from the file, because this is the default config. I think I can simply change it to false, and change init to force it to true.

@Bktero
Copy link
Author

Bktero commented Mar 22, 2025

I think I figured it out. I added another commit. Here is how I tested it.

First I created book:

$ ./target/debug/mdbook init my-new-book    

Do you want a .gitignore to be created? (y/n)
n
What title would you like to give the book? 
test
2025-03-22 14:56:11 [INFO] (mdbook::book::init): Creating a new book with stub content

All done, no errors...

The following book.toml was generated:

[book]
authors = ["Pierre Gradot"]
language = "en"
multilingual = false
src = "src"
title = "test"

[build]
build-dir = "book"
create-missing = true
error-on-missing-preprocessor = true
extra-watch-dirs = []
use-default-preprocessors = true

I add this at the end of te file (as in the linked issue):

[preprocessor.mermaid]
command = "not-a-real-binary"

I built the book and got an error:

$ ./target/debug/mdbook build my-new-book
2025-03-22 14:58:04 [INFO] (mdbook::book): Book building has started
2025-03-22 14:58:04 [ERROR] (mdbook::preprocess::cmd): The command "not-a-real-binary" wasn't found, is the "mermaid" preprocessor installed?

I changed the flag to false and I built again:

$ ./target/debug/mdbook build my-new-book
2025-03-22 14:58:19 [INFO] (mdbook::book): Book building has started
2025-03-22 14:58:19 [WARN] (mdbook::preprocess::cmd): The command "not-a-real-binary" wasn't found, is the "mermaid" preprocessor installed?
2025-03-22 14:58:19 [INFO] (mdbook::book): Running the html backend

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: waiting on a review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants