Skip to content

Commit 042ef54

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 91c665a commit 042ef54

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
@@ -541,6 +541,26 @@ def cell_execute(client, cell, index, execution_count, eval_default, store_histo
541541
if len(cell["metadata"]["tags"]) == 0:
542542
del cell["metadata"]["tags"]
543543

544+
# Check for display errors in output (respecting both global and cell settings)
545+
cell_allows_errors = client.allow_errors or allow_errors
546+
if not cell_allows_errors:
547+
for output in cell.outputs:
548+
if output.get('output_type') == 'error':
549+
trace("Uncaught error found in output")
550+
from nbclient.exceptions import CellExecutionError
551+
error_name = output.get('ename', 'Error')
552+
error_value = output.get('evalue', '')
553+
traceback = output.get('traceback', [])
554+
# Use same error raising mechanism as nbclient
555+
raise CellExecutionError.from_cell_and_msg(
556+
cell,
557+
{
558+
'ename': error_name,
559+
'evalue': error_value,
560+
'traceback': traceback
561+
}
562+
)
563+
544564
# return cell
545565
return cell
546566

0 commit comments

Comments
 (0)