mkdocs-material icon indicating copy to clipboard operation
mkdocs-material copied to clipboard

Tags plugin: sometimes crashes on empty tags

Open godot42x opened this issue 2 years ago • 3 comments

Context

I'm migrating my docs repo. And was tried to use mkdocs with material theme to build blog somewhat. I use obsidian as the editor. And the default metadata's tags will be empty. Also that I level it empty in most files. Which looks like:

Author: "@godot42" Date: "{{date}} {{time}}" pub: false pub-category: tags:

But as I enabled the tags plugin, empty tags section will be considered as a exception.

Bug description

The error messages and traceback: ERROR - Error building page 'Arc/Game/ECS_With_UI.md': 'NoneType' object is not iterable Traceback (most recent call last): File "C:\Users\norm\miniconda3\lib\runpy.py", line 197, in _run_module_as_main return _run_code(code, main_globals, None, File "C:\Users\norm\miniconda3\lib\runpy.py", line 87, in run_code exec(code, run_globals) File "C:\Users\norm\miniconda3\Scripts\mkdocs.exe_main.py", line 7, in File "C:\Users\norm\miniconda3\lib\site-packages\click\core.py", line 1157, in call return self.main(*args, **kwargs) File "C:\Users\norm\miniconda3\lib\site-packages\click\core.py", line 1078, in main rv = self.invoke(ctx) File "C:\Users\norm\miniconda3\lib\site-packages\click\core.py", line 1688, in invoke return _process_result(sub_ctx.command.invoke(sub_ctx)) File "C:\Users\norm\miniconda3\lib\site-packages\click\core.py", line 1434, in invoke return ctx.invoke(self.callback, **ctx.params) File "C:\Users\norm\miniconda3\lib\site-packages\click\core.py", line 783, in invoke return _callback(*args, **kwargs) File "C:\Users\norm\miniconda3\lib\site-packages\mkdocs_main.py", line 270, in serve_command serve.serve(**kwargs) File "C:\Users\norm\miniconda3\lib\site-packages\mkdocs\commands\serve.py", line 86, in serve builder(config) File "C:\Users\norm\miniconda3\lib\site-packages\mkdocs\commands\serve.py", line 67, in builder build(config, live_server=None if is_clean else server, dirty=is_dirty) File "C:\Users\norm\miniconda3\lib\site-packages\mkdocs\commands\build.py", line 349, in build _build_page( File "C:\Users\norm\miniconda3\lib\site-packages\mkdocs\commands\build.py", line 222, in _build_page context = config.plugins.on_page_context(context, page=page, config=config, nav=nav) File "C:\Users\norm\miniconda3\lib\site-packages\mkdocs\plugins.py", line 583, in on_page_context return self.run_event('page_context', context, page=page, config=config, nav=nav) File "C:\Users\norm\miniconda3\lib\site-packages\mkdocs\plugins.py", line 507, in run_event result = method(item, **kwargs) File "C:\Users\norm\miniconda3\lib\site-packages\material\plugins\tags\plugin.py", line 117, in on_page_context context["tags"] = [ TypeError: 'NoneType' object is not iterable

Related links

Reproduction

9.5.18-tags_plugins_exception.zip

Steps to reproduce

Run mkdocs when tags of metadata is empty

Browser

No response

Before submitting

godot42x avatar Apr 24 '24 20:04 godot42x

Hello! I noticed that many of my notes currently have empty tags in the metadata section. Are these empty tags considered valid for mkdocs? I just encountered an exception in the source code related to this when I execute build/serve process to create a blog. And the exception which I've already addressed by making modifications and testing them thoroughly. Everything seems to be working smoothly now (just made a simple test)🎉🎉! Or are there any spec considerations I might have overlooked? I have just gone ahead and created a pull request for this issue: https://github.com/squidfunk/mkdocs-material/pull/7098.

godot42x avatar Apr 24 '24 20:04 godot42x

Thanks for reporting and creating the PR! I've ran your reproduction, and can't observe the problem. However, looking at the code, your proposed changes definitely make sense to better safe guard against such errors, and I can't rule out that it might be related to some other version of some other package that is causing the problem.

squidfunk avatar Apr 25 '24 02:04 squidfunk

Released as part of 9.5.19

squidfunk avatar Apr 25 '24 04:04 squidfunk