No information about exceptions available from nbconvert output?

Chris Ball <[email protected]>
Newsgroups gmane.comp.python.ipython.devel
Message-ID <[email protected]>
Hi

If a notebook cell causes an exception, there doesn't seem to be any way
to see the traceback in the output of nbconvert. For instance, with the
command ``jupyter nbconvert --execute --to html hello.ipynb`` I get the
following output for various combinations of nbconvert version and
options, but the output never includes the actual traceback...

4.0.0:
```
$ jupyter nbconvert --execute --to html hello.ipynb
[...]
[NbConvertApp] ERROR | failed to run cell: CellExecutionError()
[NbConvertApp] ERROR | raise NotImplementedError('hello')
[NbConvertApp] ERROR | Error while converting 'hello.ipynb'
Traceback (most recent call last):
  File
  "/x/y/anaconda230/lib/python2.7/site-packages/nbconvert/nbconvertapp.py",
  line 332, in export_single_notebook
    output, resources = self.exporter.from_filename(notebook_filename,
    resources=resources)
  File
  "/x/y/anaconda230/lib/python2.7/site-packages/nbconvert/exporters/exporter.py",
  line 166, in from_filename
    return self.from_notebook_node(nbformat.read(f, as_version=4),
    resources=resources, **kw)
  File
  "/x/y/anaconda230/lib/python2.7/site-packages/nbconvert/exporters/html.py",
  line 65, in from_notebook_node
    return super(HTMLExporter, self).from_notebook_node(nb, resources,
    **kw)
  File
  "/x/y/anaconda230/lib/python2.7/site-packages/nbconvert/exporters/templateexporter.py",
  line 198, in from_notebook_node
    nb_copy, resources = super(TemplateExporter,
    self).from_notebook_node(nb, resources, **kw)
  File
  "/x/y/anaconda230/lib/python2.7/site-packages/nbconvert/exporters/exporter.py",
  line 131, in from_notebook_node
    nb_copy, resources = self._preprocess(nb_copy, resources)
  File
  "/x/y/anaconda230/lib/python2.7/site-packages/nbconvert/exporters/exporter.py",
  line 303, in _preprocess
    nbc, resc = preprocessor(nbc, resc)
  File
  "/x/y/anaconda230/lib/python2.7/site-packages/nbconvert/preprocessors/base.py",
  line 47, in __call__
    return self.preprocess(nb,resources)
  File
  "/x/y/anaconda230/lib/python2.7/site-packages/nbconvert/preprocessors/execute.py",
  line 83, in preprocess
    nb, resources = super(ExecutePreprocessor, self).preprocess(nb,
    resources)
  File
  "/x/y/anaconda230/lib/python2.7/site-packages/nbconvert/preprocessors/base.py",
  line 70, in preprocess
    nb.cells[index], resources = self.preprocess_cell(cell, resources,
    index)
  File
  "/x/y/anaconda230/lib/python2.7/site-packages/nbconvert/preprocessors/execute.py",
  line 97, in preprocess_cell
    outputs = self.run_cell(cell)
  File
  "/x/y/anaconda230/lib/python2.7/site-packages/nbconvert/preprocessors/execute.py",
  line 129, in run_cell
    raise CellExecutionError(msg['content']['traceback'])
CellExecutionError
```

4.0.0 with ``--Application.log_level=DEBUG``:
```
[...]
[NbConvertApp] Executing cell:
raise NotImplementedError('hello')
[NbConvertApp] ERROR | failed to run cell: CellExecutionError()
[NbConvertApp] ERROR | raise NotImplementedError('hello')
[NbConvertApp] ERROR | Error while converting 'hello.ipynb'
Traceback (most recent call last):
  File
  "/x/y/anaconda230/lib/python2.7/site-packages/nbconvert/nbconvertapp.py",
  line 332, in export_single_notebook
    output, resources = self.exporter.from_filename(notebook_filename,
    resources=resources)
  File
  "/x/y/anaconda230/lib/python2.7/site-packages/nbconvert/exporters/exporter.py",
  line 166, in from_filename
    return self.from_notebook_node(nbformat.read(f, as_version=4),
    resources=resources, **kw)
  File
  "/x/y/anaconda230/lib/python2.7/site-packages/nbconvert/exporters/html.py",
  line 65, in from_notebook_node
    return super(HTMLExporter, self).from_notebook_node(nb, resources,
    **kw)
  File
  "/x/y/anaconda230/lib/python2.7/site-packages/nbconvert/exporters/templateexporter.py",
  line 198, in from_notebook_node
    nb_copy, resources = super(TemplateExporter,
    self).from_notebook_node(nb, resources, **kw)
  File
  "/x/y/anaconda230/lib/python2.7/site-packages/nbconvert/exporters/exporter.py",
  line 131, in from_notebook_node
    nb_copy, resources = self._preprocess(nb_copy, resources)
  File
  "/x/y/anaconda230/lib/python2.7/site-packages/nbconvert/exporters/exporter.py",
  line 303, in _preprocess
    nbc, resc = preprocessor(nbc, resc)
  File
  "/x/y/anaconda230/lib/python2.7/site-packages/nbconvert/preprocessors/base.py",
  line 47, in __call__
    return self.preprocess(nb,resources)
  File
  "/x/y/anaconda230/lib/python2.7/site-packages/nbconvert/preprocessors/execute.py",
  line 83, in preprocess
    nb, resources = super(ExecutePreprocessor, self).preprocess(nb,
    resources)
  File
  "/x/y/anaconda230/lib/python2.7/site-packages/nbconvert/preprocessors/base.py",
  line 70, in preprocess
    nb.cells[index], resources = self.preprocess_cell(cell, resources,
    index)
  File
  "/x/y/anaconda230/lib/python2.7/site-packages/nbconvert/preprocessors/execute.py",
  line 97, in preprocess_cell
    outputs = self.run_cell(cell)
  File
  "/x/y/anaconda230/lib/python2.7/site-packages/nbconvert/preprocessors/execute.py",
  line 129, in run_cell
    raise CellExecutionError(msg['content']['traceback'])
CellExecutionError
```

Current master (71e80ef6f4930a06087b8bd32f0e209af1393e59):
```
[...]
[NbConvertApp] ERROR | Error while converting 'hello.ipynb'
Traceback (most recent call last):
  File
  "/x/y/anaconda230/lib/python2.7/site-packages/nbconvert/nbconvertapp.py",
  line 335, in export_single_notebook
    output, resources = self.exporter.from_filename(notebook_filename,
    resources=resources)
  File
  "/x/y/anaconda230/lib/python2.7/site-packages/nbconvert/exporters/exporter.py",
  line 165, in from_filename
    return self.from_notebook_node(nbformat.read(f, as_version=4),
    resources=resources, **kw)
  File
  "/x/y/anaconda230/lib/python2.7/site-packages/nbconvert/exporters/html.py",
  line 65, in from_notebook_node
    return super(HTMLExporter, self).from_notebook_node(nb, resources,
    **kw)
  File
  "/x/y/anaconda230/lib/python2.7/site-packages/nbconvert/exporters/templateexporter.py",
  line 196, in from_notebook_node
    nb_copy, resources = super(TemplateExporter,
    self).from_notebook_node(nb, resources, **kw)
  File
  "/x/y/anaconda230/lib/python2.7/site-packages/nbconvert/exporters/exporter.py",
  line 130, in from_notebook_node
    nb_copy, resources = self._preprocess(nb_copy, resources)
  File
  "/x/y/anaconda230/lib/python2.7/site-packages/nbconvert/exporters/exporter.py",
  line 302, in _preprocess
    nbc, resc = preprocessor(nbc, resc)
  File
  "/x/y/anaconda230/lib/python2.7/site-packages/nbconvert/preprocessors/base.py",
  line 47, in __call__
    return self.preprocess(nb,resources)
  File
  "/x/y/anaconda230/lib/python2.7/site-packages/nbconvert/preprocessors/execute.py",
  line 83, in preprocess
    nb, resources = super(ExecutePreprocessor, self).preprocess(nb,
    resources)
  File
  "/x/y/anaconda230/lib/python2.7/site-packages/nbconvert/preprocessors/base.py",
  line 70, in preprocess
    nb.cells[index], resources = self.preprocess_cell(cell, resources,
    index)
  File
  "/x/y/anaconda230/lib/python2.7/site-packages/nbconvert/preprocessors/execute.py",
  line 112, in preprocess_cell
    raise CellExecutionError(msg)
CellExecutionError
```

Current master with with ``--Application.log_level=DEBUG``:
```
[...]
[NbConvertApp] Executing cell:
raise NotImplementedError('hello')
[NbConvertApp] output: status
[NbConvertApp] output: execute_input
[NbConvertApp] output: error
[NbConvertApp] output: status
[NbConvertApp] ERROR | Error while converting 'hello.ipynb'
Traceback (most recent call last):
  File
  "/x/y/anaconda230/lib/python2.7/site-packages/nbconvert/nbconvertapp.py",
  line 335, in export_single_notebook
    output, resources = self.exporter.from_filename(notebook_filename,
    resources=resources)
  File
  "/x/y/anaconda230/lib/python2.7/site-packages/nbconvert/exporters/exporter.py",
  line 165, in from_filename
    return self.from_notebook_node(nbformat.read(f, as_version=4),
    resources=resources, **kw)
  File
  "/x/y/anaconda230/lib/python2.7/site-packages/nbconvert/exporters/html.py",
  line 65, in from_notebook_node
    return super(HTMLExporter, self).from_notebook_node(nb, resources,
    **kw)
  File
  "/x/y/anaconda230/lib/python2.7/site-packages/nbconvert/exporters/templateexporter.py",
  line 196, in from_notebook_node
    nb_copy, resources = super(TemplateExporter,
    self).from_notebook_node(nb, resources, **kw)
  File
  "/x/y/anaconda230/lib/python2.7/site-packages/nbconvert/exporters/exporter.py",
  line 130, in from_notebook_node
    nb_copy, resources = self._preprocess(nb_copy, resources)
  File
  "/x/y/anaconda230/lib/python2.7/site-packages/nbconvert/exporters/exporter.py",
  line 302, in _preprocess
    nbc, resc = preprocessor(nbc, resc)
  File
  "/x/y/anaconda230/lib/python2.7/site-packages/nbconvert/preprocessors/base.py",
  line 47, in __call__
    return self.preprocess(nb,resources)
  File
  "/x/y/anaconda230/lib/python2.7/site-packages/nbconvert/preprocessors/execute.py",
  line 83, in preprocess
    nb, resources = super(ExecutePreprocessor, self).preprocess(nb,
    resources)
  File
  "/x/y/anaconda230/lib/python2.7/site-packages/nbconvert/preprocessors/base.py",
  line 70, in preprocess
    nb.cells[index], resources = self.preprocess_cell(cell, resources,
    index)
  File
  "/x/y/anaconda230/lib/python2.7/site-packages/nbconvert/preprocessors/execute.py",
  line 112, in preprocess_cell
    raise CellExecutionError(msg)
CellExecutionError
```

Am I doing something wrong, or does what I'm looking for make no sense?

I could run nbconvert with ``--allow-errors`` and then inspect the html,
but that seems like a difficult way to obtain the information (e.g. on a
build server where nbconvert is being used to test a notebook).


Thanks
Chris
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.