✨ NEW: Add execution_fail_on_error configuration#296
Conversation
|
Thanks for submitting your first pull request! You are awesome! 🤗 |
Codecov Report
@@ Coverage Diff @@
## master #296 +/- ##
==========================================
- Coverage 87.48% 87.14% -0.34%
==========================================
Files 12 12
Lines 1334 1346 +12
==========================================
+ Hits 1167 1173 +6
- Misses 167 173 +6
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
|
The flag name seems reasonable to me! One thought - do we imagine any other activity also triggering this "force a failure" mode? If not, then we could also just be more explicit and call this something like For the implementation, is there any behavior of the Sphinx logger that can force it to fail? (e.g., I would have assumed the critical( would have made Sphinx fail by default, but maybe I am hoping to much from Sphinx 😄 . If not, then this seems fine to me. |
Great thought - I gave it a try, but it doesn't look like this causes sphinx to fail without the Looking at the sphinx app source (https://github.com/sphinx-doc/sphinx/blob/master/sphinx/application.py) it seems that build failures result in regular Python exceptions, so I think that is sphinx's preferred mechanism for a hard build failure. It might be worth defining a custom exception type (e.g. |
|
One other thing: I know that |
|
Here's how try:
rststring, resources = exporter.from_notebook_node(nb, resources)
except nbconvert.preprocessors.execute.CellExecutionError as e:
lines = str(e).split('\n')
lines[0] = 'CellExecutionError in {}:'.format(
env.doc2path(env.docname, base=None))
lines.append("You can ignore this error by setting the following "
"in conf.py:\n\n nbsphinx_allow_errors = True\n")
raise NotebookError('\n'.join(lines))
except Exception as e:
raise NotebookError(type(e).__name__ + ' in ' +
env.doc2path(env.docname, base=None) + ':\n' +
str(e))Perhaps we should follow their lead and call the flag something like |
|
In the case of with timer:
try:
executenb(
nb,
cwd=cwd,
timeout=timeout,
allow_errors=allow_errors,
record_timing=False,
)
except (CellExecutionError, CellTimeoutError) as err:
error = err
exc_string = "".join(traceback.format_exc())
return ExecutionResult(nb, timer.last_split, error, exc_string)So to do the equivalent of |
|
Hey yeh thanks @jakevdp, thats what I was just about to point out; all execution is done via jupyter-cache, which uses nbclient (the use of nbconvert is essentially deprecated) |
577948c to
f11cb23
Compare
|
I changed to |
|
I've been testing this change with the JAX docs in jax-ml/jax#5537; the most recent push shows the intended behavior, i.e. the cell contents and error are reported directly in the build log, which means the problem can be easily identified from the output of a CI documentation build. |
|
Added some docs... I think this is ready for a review. Code coverage delta is not great, but that is primarily because I added some conditions to error handling blocks that already have no tests. Let me know if you'd like me to invest some time in trying to add coverage for those cases. |
1ad44bc to
aa5cb9d
Compare
choldgraf
left a comment
There was a problem hiding this comment.
Just one quick comment, but other than that this looks great to me :-)
| ) | ||
| LOGGER.error(message) | ||
| if env.config["execution_fail_on_error"]: | ||
| raise ExecutionError(str(result.err)) |
There was a problem hiding this comment.
do we have access to the name of the file being executed here? Perhaps the error string could be something like:
f"""
Execution failed for file: {file-name}
{str(result.err))
"""
(if it is already obvious from your implementation which file the error came from, then disregard this!)
There was a problem hiding this comment.
Great idea! I added the file path to the error message. The sphinx-build error now looks something like this:
Exception occurred:
File "/Users/jakevdp/github/executablebooks/MyST-NB/myst_nb/execution.py", line 153, in generate_notebook_outputs
raise ExecutionError(
myst_nb.execution.ExecutionError: Execution failed for file: /Users/jakevdp/github/google/jax/docs/myst_nb_test.md
An error occurred while executing the following cell:
------------------
assert x[0] == 4321
------------------
---------------------------------------------------------------------------
AssertionError Traceback (most recent call last)
<ipython-input-3-381fab23ad2d> in <module>
----> 1 assert x[0] == 4321
AssertionError:
AssertionError:
The full traceback has been saved in /var/folders/lr/h5hbphfs7_54btrvfk4qb7qc00h5r8/T/sphinx-err-1hoea1rl.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!|
I pushed a typo fix a few days back, and need another review now. Thanks! |
choldgraf
left a comment
There was a problem hiding this comment.
This still LGTM 👍. I'll wait a day or two to see if @chrisjsewell wants more changes. Is this an urgent improvement on your end @jakevdp ?
|
Thanks! No, it's not urgent. We're currently working around this by monkey-patching the sphinx logger that myst-nb uses to report errors. |
|
thanks @jakevdp, sorry bare with me I do want to have a quick look over this |
|
thanks @jakevdp this will be super helpful once this is merged. |
|
FWIW, JAX no longer needs this, because I managed to fix all our warnings so we can run |
choldgraf
left a comment
There was a problem hiding this comment.
Thanks for the update @jakevdp - sorry this one slowed down a bit.
I'm +1 on this - though I think @chrisjsewell wants to hold off on merging?
71d779f to
9607206
Compare
|
Thanks! I just rebased and force pushed to fix conflicts that had come up on master, so a new review is required. |
|
Superseded by #404 cheers |
This is a bare-bones implementation of the flag discussed in #248. This PR is incomplete; in particular a few things remain to be addressed:
I'd be happy for any input on this, and I'm happy to iterate on the design given any feedback or recommendations. Thanks!