From ea83274fd3464e3630a6ae9b29d8b08ad5c3bd80 Mon Sep 17 00:00:00 2001 From: Chris Sewell Date: Wed, 1 Apr 2020 08:27:06 +0100 Subject: [PATCH] Add fix for corrupted stage records --- myst_nb/cache.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/myst_nb/cache.py b/myst_nb/cache.py index c0f96df0..7177df3d 100644 --- a/myst_nb/cache.py +++ b/myst_nb/cache.py @@ -102,7 +102,20 @@ def _stage_and_execute(env, exec_docnames, path_cache): pk_list.append(stage_record.pk) # can leverage parallel execution implemented in jupyter-cache here - execute_staged_nb(cache_base, pk_list or None) + try: + execute_staged_nb(cache_base, pk_list or None) + except OSError as err: + # This is a 'fix' for obscure cases, such as if you + # remove name.ipynb and add name.md (i.e. same name, different extension) + # and then name.ipynb isn't flagged for removal. + # Normally we want to keep the stage records available, so that we can retrieve + # execution tracebacks at the `add_notebook_outputs` stage, + # but we need to flush if it becomes 'corrupted' + LOGGER.error( + "Execution failed in an unexpected way, clearing staged notebooks: %s", err + ) + for record in cache_base.list_staged_records(): + cache_base.discard_staged_notebook(record.pk) def add_notebook_outputs(env, ntbk, file_path=None):