Skip to content

Commit f8122fc

Browse files
committed
jupyter - Add error handling for display errors in notebook cell execution
`nbclient` does not error out when a cell has error due to display error. This PR adds error handling for display errors in notebook cell so that `quarto render` will error out. `error: true` control the behavior to allow or not the error.
1 parent 1b82bf3 commit f8122fc

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

src/resources/jupyter/notebook.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -553,6 +553,26 @@ def cell_execute(client, cell, index, execution_count, eval_default, store_histo
553553
if len(cell["metadata"]["tags"]) == 0:
554554
del cell["metadata"]["tags"]
555555

556+
# Check for display errors in output (respecting both global and cell settings)
557+
cell_allows_errors = client.allow_errors or allow_errors
558+
if not cell_allows_errors:
559+
for output in cell.outputs:
560+
if output.get('output_type') == 'error':
561+
trace("Uncaught error found in output")
562+
from nbclient.exceptions import CellExecutionError
563+
error_name = output.get('ename', 'Error')
564+
error_value = output.get('evalue', '')
565+
traceback = output.get('traceback', [])
566+
# Use same error raising mechanism as nbclient
567+
raise CellExecutionError.from_cell_and_msg(
568+
cell,
569+
{
570+
'ename': error_name,
571+
'evalue': error_value,
572+
'traceback': traceback
573+
}
574+
)
575+
556576
# return cell
557577
return cell
558578

0 commit comments

Comments
 (0)