Skip to content
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

Tags plugin: Empty tags aren't handled properly #4683

Closed
5 tasks done
wilhelmer opened this issue Nov 28, 2022 · 5 comments
Closed
5 tasks done

Tags plugin: Empty tags aren't handled properly #4683

wilhelmer opened this issue Nov 28, 2022 · 5 comments
Labels
bug Issue reports a bug resolved Issue is resolved, yet unreleased if open

Comments

@wilhelmer
Copy link
Contributor

Contribution guidelines

I've found a bug and checked that ...

  • ... the problem doesn't occur with the mkdocs or readthedocs themes
  • ... the problem persists when all overrides are removed, i.e. custom_dir, extra_javascript and extra_css
  • ... the documentation does not mention anything about my problem
  • ... there are no open or closed issues that are related to my problem

Description

When adding an empty tag, the tags plugin throws an unhandled exception.

mkdocs.yml:

site_name: Test Project
theme:
    name: material
use_directory_urls: false
nav:
  - Welcome: index.md
plugins:
  - search
  - tags:
      tags_file: index.md

sample.md:

---
tags:
  - My tag
  - 
---

# Topic 1

Lorem ipsum

Build result:

  File "/opt/homebrew/bin/mkdocs", line 8, in <module>
    sys.exit(cli())
             ^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/click/core.py", line 1130, in __call__
    return self.main(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/click/core.py", line 1055, in main
    rv = self.invoke(ctx)
         ^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/click/core.py", line 1657, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/click/core.py", line 1404, in invoke
    return ctx.invoke(self.callback, **ctx.params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/click/core.py", line 760, in invoke
    return __callback(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/mkdocs/__main__.py", line 250, in build_command
    build.build(cfg, dirty=not clean)
  File "/opt/homebrew/lib/python3.11/site-packages/mkdocs/commands/build.py", line 308, in build
    _populate_page(file.page, config, files, dirty)
  File "/opt/homebrew/lib/python3.11/site-packages/mkdocs/commands/build.py", line 177, in _populate_page
    page.markdown = config.plugins.run_event(
                    ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/mkdocs/plugins.py", line 520, in run_event
    result = method(item, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/material/plugins/tags/plugin.py", line 100, in on_page_markdown
    return self._render_tag_index(markdown, page)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/material/plugins/tags/plugin.py", line 171, in _render_tag_index
    for name in sorted(
                ^^^^^^^
TypeError: '<' not supported between instances of 'NoneType' and 'str'

Expected behaviour

Missing tags should be handled properly, ideally with a proper error message.

Actual behaviour

See description

Steps to reproduce

See description

Package versions

  • Python: 3.11
  • MkDocs: 1.4.2
  • Material: Latest insider version

Configuration

See description

System information

  • Operating system: macOS Ventura
  • Browser: FF
@squidfunk
Copy link
Owner

Thanks for reporting. I'm unsure what to do here – what's the ideal workflow for you? We could issue a warning about the empty tag, filter it, and just go on. This would also fail --strict mode, which in my view would be desirable.

@squidfunk squidfunk added the bug Issue reports a bug label Nov 28, 2022
@wilhelmer
Copy link
Contributor Author

We could issue a warning about the empty tag, filter it, and just go on. This would also fail --strict mode, which in my view would be desirable.

Yes, I think that would be the best solution.

@squidfunk
Copy link
Owner

Fixed in squidfunk/mkdocs-material-insiders@9fdaf6d71 and squidfunk/mkdocs-material-insiders@07c8eff6d. I've also added a more explicit check for the tags format (must be a str, int, float or bool – everything else will not work), and ensured that the tags entry is a list. If the tag is left empty, the plugin now prints a warning:

WARNING  -  Page 'path/to/file.md' includes invalid tag: (empty)

@squidfunk
Copy link
Owner

Released as part of 8.5.10-insiders-4.26.6.

@squidfunk squidfunk added the resolved Issue is resolved, yet unreleased if open label Nov 28, 2022
@wilhelmer
Copy link
Contributor Author

Overdelivering as usual! 🚀 Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue reports a bug resolved Issue is resolved, yet unreleased if open
Projects
None yet
Development

No branches or pull requests

2 participants