Skip to content

Commit

Permalink
fix: stop executing cells when an error is encountered (replaces voil…
Browse files Browse the repository at this point in the history
…a-dashboards#530)

Co-authored-by: martinRenou <[email protected]>
  • Loading branch information
maartenbreddels and martinRenou committed Aug 19, 2020
1 parent ee1e938 commit e387710
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 5 deletions.
4 changes: 3 additions & 1 deletion tests/app/syntax_error_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,6 @@ def voila_args(notebook_directory, voila_args_extra):
async def test_syntax_error(capsys, http_server_client, syntax_error_notebook):
response = await http_server_client.fetch(syntax_error_notebook)
assert response.code == 200
assert 'There was an error when executing cell' in response.body.decode('utf-8')
output = response.body.decode('utf-8')
assert 'There was an error when executing cell' in output
assert 'This should not be executed' not in output
9 changes: 9 additions & 0 deletions tests/notebooks/syntax_error.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,15 @@
"source": [
"this is a syntax error"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"print('This should ' + 'not be executed')"
]
}
],
"metadata": {
Expand Down
3 changes: 0 additions & 3 deletions voila/execute.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,6 @@ async def execute_cell(self, cell, resources, cell_index, store_history=True):
self.log.error(e)
self.show_code_cell_timeout(cell)
raise e
except CellExecutionError as e:
self.log.error(e)
result = cell

# Strip errors and traceback if not in debug mode
if self.should_strip_error():
Expand Down
9 changes: 8 additions & 1 deletion voila/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,12 @@
import nbformat

from nbconvert.preprocessors import ClearOutputPreprocessor
from nbclient.exceptions import CellExecutionError
from nbclient.util import ensure_async
from tornado.httputil import split_host_and_port

from ._version import __version__
from .execute import VoilaExecutor
from .execute import VoilaExecutor, strip_code_cell_warnings
from .exporter import VoilaExporter


Expand Down Expand Up @@ -182,6 +183,12 @@ async def _jinja_cell_generator(self, nb, kernel_id):
except TimeoutError:
output_cell = input_cell
break
except CellExecutionError as e:
if self.executor.should_strip_error():
strip_code_cell_warnings(input_cell)
self.executor.strip_code_cell_errors(input_cell)
output_cell = input_cell
break
except Exception as e:
self.log.exception('Error at server while executing cell: %r', input_cell)
output_cell = nbformat.v4.new_code_cell()
Expand Down

0 comments on commit e387710

Please sign in to comment.