You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
---title: testformat: html---```{python}# First cell - create an object with a buggy _repr_html_ methodclass BuggyDisplay: def __init__(self): self.data = "This works fine" def _repr_html_(self): # This error happens during display, not execution raise ValueError("Display phase error!") def __repr__(self): # This ensures the object has a string representation return self.data# Create the objectbuggy = BuggyDisplay()``````{python}# Second cell - display the object (triggers error in _repr_html_)# This will show an error in the output but won't stop executionbuggy``````{python}# Third cell - proves execution continuesprint("Execution continued despite display error")```
The problem is that nbconvert (thus nbclient) is not throwing exception for error that happens in IPython step
quarto convert .\bug.qmd
jupyter nbconvert --to notebook --execute bug.ipynb
This does not fail. This means Quarto does not catch exception, and it behaves always as if error = true has been set.
Still unsure if this is expected behavior in nbconvert and Jupyter.
If we want to Quarto to fail, we can catch "output_type": "error" in output when no failure happened, and throw an exception from there possibly.
This needs a bit more investigation. Opening to track this happens.
The text was updated successfully, but these errors were encountered:
Still unsure if this is expected behavior in nbconvert and Jupyter.
From further reading, I think nbconvert does not fail on display error because it is not error in the code itself, and it does not prevent computing an output from the exectuted notebook because there are fallback representation.
Here the error is in the way cell are displayed. Tool using nbclient or nbconvert can decide what to do with those errors. This also allow to have fallback representation in output.
This is because all representations are computed. From my previous example, first cell can be changed to
classBuggyDisplay:
def__init__(self):
self.data="This works fine"def_repr_html_(self):
# This error happens during display, not executionraiseValueError("Display phase error!")
def_repr_markdown_(self):
# Markdown representation as fallback when HTML failsreturn"**Markdown fallback:** "+self.datadef__repr__(self):
# This ensures the object has a string representationreturnself.data# Create the objectbuggy=BuggyDisplay()
The error will be shown in output but the cell output quarto uses is now the markdown fallback.
If we inverse and make the markdown fail then the HTML is correctly used in output
classBuggyDisplay:
def__init__(self):
self.data="This works fine"def_repr_html_(self):
# This error happens during display, not execution# raise ValueError("Display phase error!")return"<b>HTML fallback:</b> "+self.datadef_repr_markdown_(self):
# Markdown representation as fallback when HTML fails# return "**Markdown fallback:** " + self.dataraiseValueError("Display phase error!")
def__repr__(self):
# This ensures the object has a string representationreturnself.data# Create the objectbuggy=BuggyDisplay()
but we still have an error shown in the ipynb output, and Quarto does show it.
So, nbconvert behavior is expected as the code does not error, but one of the representations does, which does not prevent having a "valid" output from their perspective.
In quarto, we need to decide what to do
Fail rendering when one of the displays fails?
Hide the error, as we already have a fallback to choose available representation anyway. In that case, we could pass the error as a warning in the console log (not in the output)
Other?
I have a fix for first so that we can discuss
cderv
linked a pull request
Mar 7, 2025
that will
close
this issue
cderv
added
needs-discussion
Issues that require a team-wide discussion before proceeding further
and removed
needs-discussion
Issues that require a team-wide discussion before proceeding further
labels
Mar 7, 2025
This is from an issue discussion about a great_tables example
I managed to reduce to a minimal example but
here is the original example
Here is the reproducible example
The problem is that
nbconvert
(thusnbclient
) is not throwing exception for error that happens in IPython stepquarto convert .\bug.qmd jupyter nbconvert --to notebook --execute bug.ipynb
This does not fail. This means Quarto does not catch exception, and it behaves always as if
error = true
has been set.Still unsure if this is expected behavior in
nbconvert
and Jupyter.If we want to Quarto to fail, we can catch
"output_type": "error"
in output when no failure happened, and throw an exception from there possibly.This needs a bit more investigation. Opening to track this happens.
The text was updated successfully, but these errors were encountered: