tarmstrong / nbdiff

A diffing and merging tool for the IPython Notebook.
http://nbdiff.org
MIT License
212 stars 28 forks source link

Provide useful error message when notebook file can't be parsed #164

Closed tarmstrong closed 10 years ago

tarmstrong commented 10 years ago

If I attempt to diff two notebooks, one of which has a missing comma somewhere, I get the following traceback. We should catch this error, display a useful error message, and exit the program gracefully.

$ nbdiff 1.ipynb 2.ipynb
Traceback (most recent call last):
  File "/home/tavish/envs/py27/bin/nbdiff", line 9, in <module>
    load_entry_point('nbdiff==0.0.0', 'console_scripts', 'nbdiff')()
  File "/home/tavish/capstone/nbdiff/nbdiff/commands.py", line 49, in diff
    notebook2 = parser.parse(open(args.after))
  File "/home/tavish/capstone/nbdiff/nbdiff/notebook_parser.py", line 7, in parse
    data = current.read(json_data, 'ipynb')
  File "/home/tavish/code/ipython/IPython/nbformat/current.py", line 188, in read
    return reads(fp.read(), format, **kwargs)
  File "/home/tavish/code/ipython/IPython/nbformat/current.py", line 137, in reads
    return reads_json(s, **kwargs)
  File "/home/tavish/code/ipython/IPython/nbformat/current.py", line 79, in reads_json
    nbf, minor, d = parse_json(s, **kwargs)
  File "/home/tavish/code/ipython/IPython/nbformat/current.py", line 55, in parse_json
    raise NotJSONError("Notebook does not appear to be JSON: %r" % s[:16])
IPython.nbformat.current.NotJSONError: Notebook does not appear to be JSON: '{\n "metadata": {'