fix(jupyter): added handling of v3 format issues. Fixes RCCE-30

This commit is contained in:
Serhii Ilin 2024-01-12 13:22:42 +02:00
parent 15bf624134
commit f1a4e5b08f

View file

@ -539,18 +539,27 @@ class MarkupRenderer(object):
return body, resources
captured_errors = {}
error_body = """
<div style="text-align: center;">
<h3>Invalid Notebook!</h3>
<p>{}</p>
</div>
"""
# TODO: In the event of a newer jupyter notebook version, consider increasing the as_version parameter
notebook = nbformat.reads(source, as_version=4, capture_validation_error=captured_errors)
if captured_errors:
error_messages = '<br>'.join(str(error) for error in captured_errors.values())
body = f"""
<div style="text-align: center;">
<h3>Invalid Notebook!</h3>
<p>{error_messages}</p>
</div>
"""
body = error_body.format(error_messages)
else:
body, _ = as_html(notebook)
try:
body, _ = as_html(notebook)
except AttributeError:
try:
nbformat.validate(nbformat.reader.reads(source))
except nbformat.ValidationError as exc:
body = error_body.format(str(exc))
else:
raise
return body