-
Notifications
You must be signed in to change notification settings - Fork 433
Expand file tree
/
Copy pathdisplay-error-true-cell.qmd
More file actions
46 lines (37 loc) · 1.22 KB
/
display-error-true-cell.qmd
File metadata and controls
46 lines (37 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
---
title: test
format: html
_quarto:
tests:
html:
ensureHtmlElementContents:
selectors: ['div.cell-output-error']
matches: ['ValueError\: Display phase error for HTML']
noMatches: []
---
With `error: true` in cell, this document should not error at rendering and Exception at IPython.display level should be shown in output.
By default `nbconvert` does not throw exception for error thrown by IPython display, on purpose as document output is still valid as there are other representation.
```{python}
# First cell - create an object with a buggy _repr_html_ method
class 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 for HTML!")
def _repr_markdown_(self):
# Markdown representation as fallback when HTML fails
return "**Markdown fallback:** " + self.data
def __repr__(self):
# This ensures the object has a string representation
return self.data
# Create the object
buggy = BuggyDisplay()
```
```{python}
#| error: true
buggy
```
```{python}
print("Execution continued despite display error")
```