Skip to content

build-lectures: tracebacks from display-time errors pass -W and get published #247

Closed

Description

@mmcky

A traceback can reach a published page while every check stays green. When the exception happens while IPython displays a cell's result, rather than while the cell's code runs, the kernel reports the cell as successful. nbclient does not raise CellExecutionError, and myst-nb renders the traceback without a Sphinx warning. So -W never fires, the status page shows ✅, and build-lectures reports success. This issue proposes a check in build-lectures that fails the step when an executed notebook holds an error output.

Where it happened

On python-advanced.quantecon.org, the Black–Litterman lecture shows two tracebacks where its two decolletage(λ) figures should be: TypeError: only 0-dimensional arrays can be converted to Python scalars. The cells pass length-1 arrays to ax.text, which NumPy 2.4 no longer accepts. Matplotlib only converts those coordinates when the inline backend draws the figure, inside IPython's display formatter, so the error happens after the cell's own code has finished. QuantEcon/lecture-python-advanced.myst#403 repairs the lecture itself.

Release archives of that site:

Release NumPy Tracebacks on the page Status page
publish-2026jun25 2.3.5 0 ✅
publish-2026jul08 2.3.5 0 ✅
publish-2026aug02 2.4.6 2 ✅
publish-2026nov01 (live) 2.4.6 2 ✅

Everything that could have caught it was green:

That repo calls jb build directly rather than through build-lectures, but build-lectures makes the same decision: its build step passes or fails on the jb build exit code alone, so it would have passed too. The extra-args description (build-lectures/action.yml lines 35-37) implies that with -W, a notebook that raises an exception fails the build. This notebook raised one and did not.

Why -W does not see it

  1. IPython's display formatters catch any exception a formatter raises, print it with showtraceback, and carry on (IPython/core/formatters.py lines 279-294). The traceback becomes an error output on the cell, but the execute_reply status stays ok.
  2. nbclient decides whether to raise CellExecutionError from that status alone, and returns early unless it is error (nbclient/client.py lines 899-913). So allow_errors=False lets the cell through, and execution continues.
  3. myst-nb renders an error output as a code block and emits no warning (myst_nb/core/render.py lines 538-562). With no warning, -W has nothing to promote, and no reports/<doc>.err.log is written.

Reproduction

This cell reproduces it without depending on NumPy or Matplotlib versions:

class DisplayFails:
    def _repr_html_(self):
        raise ValueError("harness: deliberate display-time error")

DisplayFails()

Run locally with IPython 9.15.0, nbclient 0.11.0 and myst-nb 1.4.0, the versions in the live site's build:

  • nbclient with allow_errors=False: kernel reply status ok, outputs error (ValueError) and execute_result, no exception, and the next cell runs. A plain 1/0 cell, for comparison, gets status error and raises CellExecutionError.
  • A one-page myst-nb book with the lecture's ax.text pattern, built with sphinx-build -W --keep-going, exits 0, and the page contains the traceback.

Proposed change

Add a step to build-lectures, after "Build lectures", that reads the executed notebooks and fails when one holds an error output.

  • Where to look. myst-nb writes every notebook it renders, outputs included, to <outdir>/../jupyter_execute/<docname>.ipynb, whether it executed the notebook or took it from the cache (myst_nb/sphinx_ext.py lines 171-179). For build-lectures that is <output-dir>/_build/jupyter_execute/. Reading the notebooks rather than the HTML covers the pdflatex builder too, and gives the exception name and message for the report.
  • What counts. Any output with output_type: error, except in a cell tagged raises-exception or a notebook whose metadata.execution.allow_errors is true. These are the same exemptions nbclient honours for an exception the cell raises.
  • What it reports. One ::error file=<source>:: annotation per hit, naming the document, the cell index and ename: evalue, then the traceback in a log group behind ::stop-commands::, as "Report build failure" does for each err.log (lines 282-297).
  • A new input, error-outputs. fail (the default) fails the step, warn annotates and passes, and ignore skips the check. A book that sets execute.allow_errors: true would set this to warn or ignore. build-jupyter-cache calls build-lectures for each builder, so it would get the check as well, and should pass the input through.
  • Stale notebooks. _build/jupyter_execute travels in a restored build cache, and a lecture removed from the book leaves its notebook behind. Scan only notebooks that still have a source document under source-dir.

The script needs only the Python standard library, which the build environment already has.

Harness assertion

build-fail-guard (test-actions.yml lines 822-907) stages a cell that raises, which -W already catches. Alongside it:

  1. A build-display-error-guard job that derives display_error.md from lecture1.md the same way, appends the DisplayFails cell above, and asserts that build-lectures reports failure and that the log names display_error and harness: deliberate display-time error. It should also assert that no reports/display_error.err.log exists, which pins this as the case -W misses.
  2. A control in a job that is meant to pass, such as env-hit-build: a fixture page with a cell tagged raises-exception, so the exemption is tested and the job stays green.

Today the first job goes red, because the build passes. Both jobs pass after the change.

Rollout

Consumers on @v0 get a new default with the next v0 release, and any site that is already publishing a hidden traceback goes red on its next build. Before releasing, grep each lecture site's HTML for class="output traceback" to see which sites that is. Alternatively, ship with warn as the default for one release.

Out of scope

Warnings printed to stderr, such as DeprecationWarnings, also show on the page, and pass for a different reason: myst-nb's nb_output_stderr defaults to show. Whether to flag those is a separate decision, because many of them are deliberate or harmless.

Priority

Medium. No build breaks, but this let a broken page ship for three months while every check passed. The next NumPy or Matplotlib deprecation that expires inside figure rendering will slip through the same way.

Claude Code (on behalf of mmcky)

Activity

  1. added
    enhancement
    on Nov 4, 2026
  2. mmcky commented on Nov 5, 2026

    @mmcky
    ContributorAuthor

    A correction to "Why -W does not see it", found while building #256: since ipykernel 7.3.0 (released 2026-06-10), the gap is narrower than step 1 above describes, but it is still open for figures.

    What changed. ipykernel now marks the execute_reply as error when a traceback is shown while the displayhook is formatting a cell's last value. _showtraceback sets _last_traceback_during_displayhook when the displayhook has a message open (zmqshell.py lines 700-703 at v7.4.0), and do_execute replies error when it is set (ipkernel.py lines 468-473). nbclient then raises CellExecutionError, and -W fails the build.

    So the reproducer above no longer reproduces. A cell whose last value has a _repr_html_ that raises (DisplayFails()) fails -W under ipykernel 7.4.0. Run 41975613328 shows myst-nb reporting Executing notebook failed: CellExecutionError for it, with IPython 9.18.1. This issue's local reproduction used IPython 9.15.0 and an earlier ipykernel.

    What still slips through. Output shown through display() never opens a displayhook message, so a formatter error there still leaves the cell ok. That is how a figure reaches the page: plt.show(), and the inline backend's flush after the cell, both call display(fig). So the Black–Litterman ax.text case still passes -W under ipykernel 7.4.0. So do the 27 tracebacks on tools-techniques' five_preferences (RuntimeError: Failed to process string with tex because latex could not be found). The reproducer that still works on current versions is:

    from IPython.display import display
    
    class DisplayFails:
        def _repr_html_(self):
            raise ValueError("harness: deliberate display-time error")
    
    display(DisplayFails())

    Run 41976251440 shows it: myst-nb cached the notebook as executed successfully, and jb build -W printed build succeeded. with the traceback on the page. #256's build-display-error-guard job uses this form. That job also asserts that no reports/display_error.err.log is written, so it will say so if a later ipykernel closes this path too.

    Claude Code (on behalf of mmcky)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions