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
321 stars 50 forks source link

Indicate the page where rendering failed #135

Closed anatoly-scherbakov closed 2 years ago

anatoly-scherbakov commented 2 years ago

I greatly appreciate #133 which helps to be certain that the site builds correctly, and to prevent errors from sneaking into production. There is one little caveat though: if, while rendering, the process fails it might be hard to understand on which page the failure happened.

I propose to print the page path in the error message.

github-actions[bot] commented 2 years ago

Welcome to this project and thank you!' first issue

fralau commented 2 years ago

Yes it makes sense.

For the record, could you provide an example of the error message you are getting (without the filename)?

anatoly-scherbakov commented 2 years ago

@fralau yes:

INFO     -  [macros] - ERROR # _Macro Rendering Error_

            **TypeError**: sequence item 65: expected str instance, span found
        Traceback (most recent call last):
          File "/home/anatoly/.pyenv/versions/3.8.12/envs/yeti.sh/lib/python3.8/site-packages/mkdocs_macros/plugin.py", line 480, in render
            return md_template.render(**page_variables)
          File "/home/anatoly/.pyenv/versions/3.8.12/envs/yeti.sh/lib/python3.8/site-packages/jinja2/environment.py", line 1291, in render
            self.environment.handle_exception()
          File "/home/anatoly/.pyenv/versions/3.8.12/envs/yeti.sh/lib/python3.8/site-packages/jinja2/environment.py", line 925, in handle_exception
            raise rewrite_traceback_stack(source=source)
          File "<template>", line 9, in top-level template code
          File "/home/anatoly/.pyenv/versions/3.8.12/envs/yeti.sh/lib/python3.8/site-packages/dominate/dom_tag.py", line 334, in __unicode__
            return self.render()
          File "/home/anatoly/.pyenv/versions/3.8.12/envs/yeti.sh/lib/python3.8/site-packages/dominate/dom_tag.py", line 340, in render
            return u''.join(data)
        TypeError: sequence item 65: expected str instance, span found


This is an error raised by my own code (a macro that I am calling).

I am preparing a PR right now.
anatoly-scherbakov commented 2 years ago

After the change:

INFO     -  [macros] - ERROR # _Macro Rendering Error_

            _File_: `index.md`

            _UndefinedError_: 'badoom' is undefined
        Traceback (most recent call last):
          File "/home/anatoly/research/mkdocs_macros_plugin/mkdocs_macros/plugin.py", line 481, in render
            return md_template.render(**page_variables)
          File "/home/anatoly/.pyenv/versions/3.8.12/envs/octadocs/lib/python3.8/site-packages/jinja2/environment.py", line 1291, in render
            self.environment.handle_exception()
          File "/home/anatoly/.pyenv/versions/3.8.12/envs/octadocs/lib/python3.8/site-packages/jinja2/environment.py", line 926, in handle_exception
            raise rewrite_traceback_stack(source=source)
          File "<template>", line 13, in top-level template code
          File "/home/anatoly/.pyenv/versions/3.8.12/envs/octadocs/lib/python3.8/site-packages/jinja2/environment.py", line 456, in getitem
            return obj[argument]
        jinja2.exceptions.UndefinedError: 'badoom' is undefined

        ```
anatoly-scherbakov commented 2 years ago

The PR: https://github.com/fralau/mkdocs_macros_plugin/pull/136

fralau commented 2 years ago

@anatoly-scherbakov Thanks for PR #136. My first impression is that it is a darn good job; let me check it in detail.

anatoly-scherbakov commented 2 years ago

I have spotted some issues there, pushed new commits :)