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

If markdown is empty, plugin crashes the entire flow #1

Open
kallewesterling opened this issue May 16, 2021 · 0 comments
Open

If markdown is empty, plugin crashes the entire flow #1

kallewesterling opened this issue May 16, 2021 · 0 comments

Comments

@kallewesterling
Copy link

Line 104 makes the entire flow crash if one of the included markdown files in config's nav is empty:

next_line_chars = set( lines[ line_number + 1 ].strip() )

Here's the error, for reference:

Traceback (most recent call last):
  File "/Users/kallewesterling/opt/anaconda3/bin/mkdocs", line 8, in <module>
    sys.exit(cli())
  File "/Users/kallewesterling/opt/anaconda3/lib/python3.8/site-packages/click/core.py", line 829, in __call__
    return self.main(*args, **kwargs)
  File "/Users/kallewesterling/opt/anaconda3/lib/python3.8/site-packages/click/core.py", line 782, in main
    rv = self.invoke(ctx)
  File "/Users/kallewesterling/opt/anaconda3/lib/python3.8/site-packages/click/core.py", line 1259, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/Users/kallewesterling/opt/anaconda3/lib/python3.8/site-packages/click/core.py", line 1066, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/Users/kallewesterling/opt/anaconda3/lib/python3.8/site-packages/click/core.py", line 610, in invoke
    return callback(*args, **kwargs)
  File "/Users/kallewesterling/opt/anaconda3/lib/python3.8/site-packages/mkdocs/__main__.py", line 133, in serve_command
    serve.serve(
  File "/Users/kallewesterling/opt/anaconda3/lib/python3.8/site-packages/mkdocs/commands/serve.py", line 141, in serve
    config = builder()
  File "/Users/kallewesterling/opt/anaconda3/lib/python3.8/site-packages/mkdocs/commands/serve.py", line 136, in builder
    build(config, live_server=live_server, dirty=dirty)
  File "/Users/kallewesterling/opt/anaconda3/lib/python3.8/site-packages/mkdocs/commands/build.py", line 271, in build
    _populate_page(file.page, config, files, dirty)
  File "/Users/kallewesterling/opt/anaconda3/lib/python3.8/site-packages/mkdocs/commands/build.py", line 167, in _populate_page
    page.markdown = config['plugins'].run_event(
  File "/Users/kallewesterling/opt/anaconda3/lib/python3.8/site-packages/mkdocs/plugins.py", line 94, in run_event
    result = method(item, **kwargs)
  File "/Users/kallewesterling/opt/anaconda3/lib/python3.8/site-packages/mkdocs_nav_enhancements/__init__.py", line 118, in on_page_markdown
    new_title = self._look_for_title_in_markdown(markdown)
  File "/Users/kallewesterling/opt/anaconda3/lib/python3.8/site-packages/mkdocs_nav_enhancements/__init__.py", line 104, in _look_for_title_in_markdown
    next_line_chars = set( lines[ line_number + 1 ].strip() )
IndexError: list index out of range

I think a solution would be, maybe to wrap this in a try and except IndexError where the exception would just continue in the wrapping for loop (on line 74).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant