Jupyter-book: Improve error message for empty file

Created on 12 Sep 2020  路  5Comments  路  Source: executablebooks/jupyter-book

Describe the bug

Running jb build . on a directory with an empty file results in an error message, if possible and easy, should provide a better error message.

To Reproduce

Steps to reproduce the behavior:

Run the following steps

jb create bug_empty_file
cd bug_empty_file
touch test.md
jb build .

Running Jupyter-Book v0.8.0
Source Folder: /Users/firasm/junk/bug_empty_file
Config Path: /Users/firasm/junk/bug_empty_file/_config.yml
Output Path: /Users/firasm/junk/bug_empty_file/_build/html
Running Sphinx v2.4.4
making output directory... done
myst v0.12.8: MdParserConfig(renderer='sphinx', commonmark_only=False, dmath_enable=True, dmath_allow_labels=True, dmath_allow_space=True, dmath_allow_digits=True, amsmath_enable=False, deflist_enable=False, update_mathjax=True, admonition_enable=False, figure_enable=False, disable_syntax=[], html_img_enable=False, url_schemes=['mailto', 'http', 'https'])
building [mo]: targets for 0 po files that are out of date
building [html]: targets for 5 source files that are out of date
updating environment: [new config] 5 added, 0 changed, 0 removed
checking for /Users/firasm/junk/bug_empty_file/references.bib in bibtex cache... not found
parsing bibtex file /Users/firasm/junk/bug_empty_file/references.bib... parsed 5 entries
Executing: notebooks in: /Users/firasm/junk/bug_empty_file                      
WARNING: Found a content page that is not in _toc.yml: test.md.                 

Exception occurred:
  File "/Users/firasm/.pyenv/versions/3.8.3/lib/python3.8/site-packages/myst_nb/converter.py", line 98, in is_myst_notebook
    front_matter.get("jupytext", {})
AttributeError: 'NoneType' object has no attribute 'get'
The full traceback has been saved in /var/folders/64/bfv2dn992m17r4ztvfrt93rh0000gn/T/sphinx-err-rku0qvxj.log, if you want to report the issue to the developers.
Please also report this if it was a user error, so that a better error message can be provided next time.
A bug report can be filed in the tracker at <https://github.com/sphinx-doc/sphinx/issues>. Thanks!
Traceback (most recent call last):
  File "/Users/firasm/.pyenv/versions/3.8.3/lib/python3.8/site-packages/jupyter_book/sphinx.py", line 141, in build_sphinx
    app.build(force_all, filenames)
  File "/Users/firasm/.pyenv/versions/3.8.3/lib/python3.8/site-packages/sphinx/application.py", line 349, in build
    self.builder.build_update()
  File "/Users/firasm/.pyenv/versions/3.8.3/lib/python3.8/site-packages/sphinx/builders/__init__.py", line 297, in build_update
    self.build(to_build,
  File "/Users/firasm/.pyenv/versions/3.8.3/lib/python3.8/site-packages/sphinx/builders/__init__.py", line 311, in build
    updated_docnames = set(self.read())
  File "/Users/firasm/.pyenv/versions/3.8.3/lib/python3.8/site-packages/sphinx/builders/__init__.py", line 418, in read
    self._read_serial(docnames)
  File "/Users/firasm/.pyenv/versions/3.8.3/lib/python3.8/site-packages/sphinx/builders/__init__.py", line 439, in _read_serial
    self.read_doc(docname)
  File "/Users/firasm/.pyenv/versions/3.8.3/lib/python3.8/site-packages/sphinx/builders/__init__.py", line 479, in read_doc
    doctree = read_doc(self.app, self.env, self.env.doc2path(docname))
  File "/Users/firasm/.pyenv/versions/3.8.3/lib/python3.8/site-packages/sphinx/io.py", line 316, in read_doc
    pub.publish()
  File "/Users/firasm/.pyenv/versions/3.8.3/lib/python3.8/site-packages/docutils/core.py", line 217, in publish
    self.document = self.reader.read(self.source, self.parser,
  File "/Users/firasm/.pyenv/versions/3.8.3/lib/python3.8/site-packages/sphinx/io.py", line 130, in read
    self.parse()
  File "/Users/firasm/.pyenv/versions/3.8.3/lib/python3.8/site-packages/docutils/readers/__init__.py", line 77, in parse
    self.parser.parse(self.input, document)
  File "/Users/firasm/.pyenv/versions/3.8.3/lib/python3.8/site-packages/myst_nb/parser.py", line 51, in parse
    converter = get_nb_converter(
  File "/Users/firasm/.pyenv/versions/3.8.3/lib/python3.8/site-packages/myst_nb/converter.py", line 66, in get_nb_converter
    if is_myst_notebook(source_iter):
  File "/Users/firasm/.pyenv/versions/3.8.3/lib/python3.8/site-packages/myst_nb/converter.py", line 98, in is_myst_notebook
    front_matter.get("jupytext", {})
AttributeError: 'NoneType' object has no attribute 'get'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/Users/firasm/.pyenv/versions/3.8.3/bin/jb", line 8, in <module>
    sys.exit(main())
  File "/Users/firasm/.pyenv/versions/3.8.3/lib/python3.8/site-packages/click/core.py", line 829, in __call__
    return self.main(*args, **kwargs)
  File "/Users/firasm/.pyenv/versions/3.8.3/lib/python3.8/site-packages/click/core.py", line 782, in main
    rv = self.invoke(ctx)
  File "/Users/firasm/.pyenv/versions/3.8.3/lib/python3.8/site-packages/click/core.py", line 1259, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/Users/firasm/.pyenv/versions/3.8.3/lib/python3.8/site-packages/click/core.py", line 1066, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/Users/firasm/.pyenv/versions/3.8.3/lib/python3.8/site-packages/click/core.py", line 610, in invoke
    return callback(*args, **kwargs)
  File "/Users/firasm/.pyenv/versions/3.8.3/lib/python3.8/site-packages/jupyter_book/commands/__init__.py", line 259, in build
    builder_specific_actions(
  File "/Users/firasm/.pyenv/versions/3.8.3/lib/python3.8/site-packages/jupyter_book/commands/__init__.py", line 485, in builder_specific_actions
    raise RuntimeError(_message_box(msg, color="red", doprint=False)) from result
RuntimeError: 
===============================================================================

There was an error in building your book. Look above for the cause.

===============================================================================

Expected behavior

An error message of the type "JB encountered an error when parsing one of your files - check if there is an empty file in your directory.

Environment

  • Python Version [e.g. 3.7.1]: 3.8.3
  • Package versions or output of jupyter-book --version: 0.8.0
  • Operating System: macOS 10.15.6

Additional Context

(note, in case anyone is wondering - this happened because I created a couple of empty files that I was going to fill in last night - but by the time I woke up, I forgot the files were empty and couldn't figure out why the build was failing).

bug

All 5 comments

Cheers yeh this is a bug in myst-nb that should not raise an exception

Hi all, I have experienced this issue too. @chrisjsewell I could not find an open issue in the myst-nb repo regarding this bug. Shall I open one or have you already fixed it in a feature branch?
Cheers.

Thanks for reminding me. This should fix it: https://github.com/executablebooks/MyST-NB/pull/271

Hi @firasm you can probably close this issue now 馃挭

Great! Thanks all :-)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

AakashGfude picture AakashGfude  路  4Comments

darribas picture darribas  路  4Comments

sidneymbell picture sidneymbell  路  5Comments

Cyb3rWard0g picture Cyb3rWard0g  路  5Comments

TomDonoghue picture TomDonoghue  路  4Comments