Skip to content

Commit 7a4d989

Browse files
committed
Setting error: false at cell level should have precedence
1 parent 217950f commit 7a4d989

File tree

2 files changed

+49
-2
lines changed

2 files changed

+49
-2
lines changed

src/resources/jupyter/notebook.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,7 @@ def cell_execute(client, cell, index, execution_count, eval_default, store_histo
517517

518518
# check options for eval and error
519519
eval = cell_options.get('eval', eval_default)
520-
allow_errors = cell_options.get('error', False)
520+
allow_errors = cell_options.get('error')
521521

522522
trace(f"cell_execute with eval={eval}")
523523

@@ -554,7 +554,7 @@ def cell_execute(client, cell, index, execution_count, eval_default, store_histo
554554
del cell["metadata"]["tags"]
555555

556556
# Check for display errors in output (respecting both global and cell settings)
557-
cell_allows_errors = client.allow_errors or allow_errors
557+
cell_allows_errors = allow_errors if allow_errors is not None else client.allow_errors
558558
if not cell_allows_errors:
559559
for output in cell.outputs:
560560
if output.get('output_type') == 'error':
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
---
2+
title: test
3+
format: html
4+
execute:
5+
error: true
6+
_quarto:
7+
tests:
8+
html:
9+
shouldError: default
10+
postRenderCleanup:
11+
- '${input_stem}.quarto_ipynb'
12+
---
13+
14+
With `error: true`, and `error: false` at cell level, this document should error at rendering.
15+
16+
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.
17+
18+
```{python}
19+
class BuggyDisplay:
20+
def __init__(self):
21+
self.data = "This works fine"
22+
23+
def _repr_html_(self):
24+
# HTML representation used for `format: html`
25+
return "<b>HTML fallback:</b> " + self.data
26+
27+
def _repr_markdown_(self):
28+
# This error happens during display, not execution
29+
# even if the markdown reprensentation is not used
30+
raise ValueError("Display phase error for Markdown!")
31+
32+
def __repr__(self):
33+
# This ensures the object has a string representation
34+
return self.data
35+
36+
# Create the object
37+
buggy = BuggyDisplay()
38+
```
39+
40+
```{python}
41+
#| error: false
42+
buggy
43+
```
44+
45+
```{python}
46+
print("Execution continued despite display error")
47+
```

0 commit comments

Comments
 (0)