fralau / mkdocs-macros-plugin

Create richer and more beautiful pages in MkDocs, by using variables and calls to macros in the markdown code.
https://mkdocs-macros-plugin.readthedocs.io
Other
318 stars 50 forks source link

mkdocs build not failing on mkdocs-macros-plugin error #153

Closed skwde closed 1 year ago

skwde commented 1 year ago

A macro error (e.g. Macro Syntax Error) is not exiting the build / serve of the mkdocs page, even though

mkdocs serve -a localhost:8010 --verbose --strict

is used.

Here is how you can reproduce the issue

mkdocs new test
cd test

cat <<EOT >> mkdocs.yml
plugins:
  - search
  - macros
EOT

cat <<EOT >> docs/index.md

## Test

{{ <abc> }}
EOT

This gives the error

INFO     -  [macros] - ERROR # _Macro Syntax Error_
            _Line 21 in Markdown file:_ **unexpected '<'**
            ```python
            {{ <abc> }}

Then the only way to identify the syntax error is to look at the page and see something like 

![Screenshot 2023-02-24 at 12 59 35](https://user-images.githubusercontent.com/26454702/221173932-bedb624f-ea71-4207-8963-5f165064b420.png)

The relevant(?) package versions I am using:

python 3.10.6 mkdocs 1.4.2 mkdocs-macros-plugin 0.7.0 jinja2 3.1.2

github-actions[bot] commented 1 year ago

Welcome to this project and thank you!' first issue

fralau commented 1 year ago

Thanks a lot for your comment. So far, I was not aware there was a --strictoption in mkdocs serve, and no one mentioned it here. I had not studied why it doesn't have the effect you expected with mkdocs-macros.

The standard way to achieve that effect (abord the build) is to use the on_error_fail option in the config file, (see #133 and documentation).

Would that solve it for you?

skwde commented 1 year ago

Thanks for your quick response and sorry that I missed this in the documentation. I only checked the section https://mkdocs-macros-plugin.readthedocs.io/en/latest/#installation for possible options.

I now set the option

on_error_fail: true

but the build / serve process does not stop, instead it continues silently with

DEBUG    -  [macros] - Undefined behavior: <class 'jinja2.runtime.DebugUndefined'>

while simply rendering as standard text. See below.

Screenshot 2023-02-24 at 14 56 47

fralau commented 1 year ago

mkdocs-macros does no raise an error in that case. If you want to raise an error in that case as well:

on_undefined: strict

See the full explanation.

skwde commented 1 year ago

@fralau thanks for your feedback.

I can conform that this now works.

Only after adding

on_undefined: strict

an error is raised in both cases, serving and building.