Improve error message for empty file
See original GitHub issueDescribe 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).
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
display an error message when file is empty - proper way?
There is no need to open() the file, just use os.stat() . >>> #create an empty file >>> f=open('testfile','w') >>> f.close() >>> #open...
Read more >Improve error message for empty files · Issue #58
Create a file "emtyfile.txt" that is empty. Be sure that its size is 0 bytes. Reset app server. Sync. This produced the error...
Read more >How To: Error: opened an empty file - Knowledge Base
Open Windows Explorer and navigate to the path specified in the error message. All profile configuration files are in the \profiles folder. Each...
Read more >Error message when attaching a file...'file appears to be ...
Hello, a error message appears when i am wanting to attach a file on outlook. It says 'This file seems to be empty...
Read more >Fix Central PTF Order Fails with "Empty File on Download ...
Bad or empty save files a. Issue the ; DLTPTF *ALL command (which will delete all of the PTF save files, cover letters,...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Thanks for reminding me. This should fix it: https://github.com/executablebooks/MyST-NB/pull/271
Cheers yeh this is a bug in myst-nb that should not raise an exception