fix(jupyter): Catching validation error in order to avoid app crash ic case of formatting issues. Fixes: RCCE-26

This commit is contained in:
Serhii Ilin 2024-01-10 11:52:49 +02:00
parent 843367a511
commit 6d73c8da73

View file

@ -538,10 +538,20 @@ class MarkupRenderer(object):
body = '\n'.join([header, css, js, body])
return body, resources
# TODO: In the event of a newer jupyter notebook version, consider increasing the as_version parameter
notebook = nbformat.reads(source, as_version=4)
(body, resources) = as_html(notebook)
return body
captured_errors = {}
# 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)
try:
(body, resources) = as_html(notebook)
except AttributeError:
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>
"""
return body
class RstTemplateRenderer(object):