fix(jupyter): added handling of v3 format issues. Fixes RCCE-30
This commit is contained in:
parent
15bf624134
commit
f1a4e5b08f
1 changed files with 16 additions and 7 deletions
|
|
@ -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
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue