From 6d73c8da73af6c51605faba3a2403ead46bbedb8 Mon Sep 17 00:00:00 2001 From: Serhii Ilin Date: Wed, 10 Jan 2024 11:52:49 +0200 Subject: [PATCH] fix(jupyter): Catching validation error in order to avoid app crash ic case of formatting issues. Fixes: RCCE-26 --- rhodecode/lib/markup_renderer.py | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/rhodecode/lib/markup_renderer.py b/rhodecode/lib/markup_renderer.py index d2d1a40b..583b5e7f 100644 --- a/rhodecode/lib/markup_renderer.py +++ b/rhodecode/lib/markup_renderer.py @@ -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 = '
'.join(str(error) for error in captured_errors.values()) + body = f""" +
+

Invalid Notebook!

+

{error_messages}

+
+ """ + return body class RstTemplateRenderer(object):