Commit 46a32afb authored by Yusei Tahara's avatar Yusei Tahara

jupyter: make jupyter environment recoverable even if setup function does not work.

parent 5c999848
...@@ -119,6 +119,15 @@ def Base_executeJupyter(self, python_expression=None, reference=None, \ ...@@ -119,6 +119,15 @@ def Base_executeJupyter(self, python_expression=None, reference=None, \
return serialized_result return serialized_result
def mergeTracebackListIntoResultDict(result_dict, error_result_dict_list):
if error_result_dict_list:
if result_dict['traceback'] is None:
result_dict['traceback'] = []
for error_result_dict in error_result_dict_list:
result_dict['traceback'].append(error_result_dict['traceback'])
result_dict['status'] = error_result_dict['status']
return result_dict
def Base_runJupyterCode(self, jupyter_code, old_notebook_context): def Base_runJupyterCode(self, jupyter_code, old_notebook_context):
""" """
Function to execute jupyter code and update the context dictionary. Function to execute jupyter code and update the context dictionary.
...@@ -178,6 +187,7 @@ def Base_runJupyterCode(self, jupyter_code, old_notebook_context): ...@@ -178,6 +187,7 @@ def Base_runJupyterCode(self, jupyter_code, old_notebook_context):
inject_variable_dict = {} inject_variable_dict = {}
current_var_dict = {} current_var_dict = {}
current_setup_dict = {} current_setup_dict = {}
setup_error_return_dict_list = []
# Execute only if jupyter_code is not empty # Execute only if jupyter_code is not empty
if jupyter_code: if jupyter_code:
...@@ -308,10 +318,7 @@ def Base_runJupyterCode(self, jupyter_code, old_notebook_context): ...@@ -308,10 +318,7 @@ def Base_runJupyterCode(self, jupyter_code, old_notebook_context):
error_return_dict = getErrorMessageForException(self, e, notebook_context) error_return_dict = getErrorMessageForException(self, e, notebook_context)
additional_information = "An error happened when trying to run the one of your setup functions:" additional_information = "An error happened when trying to run the one of your setup functions:"
error_return_dict['traceback'].insert(0, additional_information) error_return_dict['traceback'].insert(0, additional_information)
# As in any other user's code execution, transaction needs to be setup_error_return_dict_list.append(error_return_dict)
# aborted.
transaction.abort()
return error_return_dict
# Iterating over envinronment.define calls captured by the environment collector # Iterating over envinronment.define calls captured by the environment collector
# that are functions and saving them as setup functions. # that are functions and saving them as setup functions.
...@@ -350,7 +357,8 @@ def Base_runJupyterCode(self, jupyter_code, old_notebook_context): ...@@ -350,7 +357,8 @@ def Base_runJupyterCode(self, jupyter_code, old_notebook_context):
# Abort the current transaction. As a consequence, the notebook lines # Abort the current transaction. As a consequence, the notebook lines
# are not added if an exception occurs. # are not added if an exception occurs.
transaction.abort() transaction.abort()
return getErrorMessageForException(self, e, notebook_context) return mergeTracebackListIntoResultDict(getErrorMessageForException(self, e, notebook_context),
setup_error_return_dict_list)
# Execute the interactive nodes with 'single' mode # Execute the interactive nodes with 'single' mode
for node in to_run_interactive: for node in to_run_interactive:
...@@ -362,7 +370,8 @@ def Base_runJupyterCode(self, jupyter_code, old_notebook_context): ...@@ -362,7 +370,8 @@ def Base_runJupyterCode(self, jupyter_code, old_notebook_context):
# Abort the current transaction. As a consequence, the notebook lines # Abort the current transaction. As a consequence, the notebook lines
# are not added if an exception occurs. # are not added if an exception occurs.
transaction.abort() transaction.abort()
return getErrorMessageForException(self, e, notebook_context) return mergeTracebackListIntoResultDict(getErrorMessageForException(self, e, notebook_context),
setup_error_return_dict_list)
mime_type = display_data['mime_type'] or mime_type mime_type = display_data['mime_type'] or mime_type
inject_variable_dict['_print'].write("\n".join(removed_setup_message_list) + display_data['result']) inject_variable_dict['_print'].write("\n".join(removed_setup_message_list) + display_data['result'])
...@@ -403,7 +412,7 @@ def Base_runJupyterCode(self, jupyter_code, old_notebook_context): ...@@ -403,7 +412,7 @@ def Base_runJupyterCode(self, jupyter_code, old_notebook_context):
'evalue': evalue, 'evalue': evalue,
'ename': ename, 'ename': ename,
'traceback': tb_list} 'traceback': tb_list}
return result return mergeTracebackListIntoResultDict(result, setup_error_return_dict_list)
class EnvironmentUndefineError(TypeError): class EnvironmentUndefineError(TypeError):
......
...@@ -46,12 +46,12 @@ ...@@ -46,12 +46,12 @@
<key> <string>text_content_warning_message</string> </key> <key> <string>text_content_warning_message</string> </key>
<value> <value>
<tuple> <tuple>
<string>W:302, 10: Use of exec (exec-used)</string> <string>W:312, 10: Use of exec (exec-used)</string>
<string>W:348, 10: Use of exec (exec-used)</string> <string>W:355, 10: Use of exec (exec-used)</string>
<string>W:360, 10: Use of exec (exec-used)</string> <string>W:368, 10: Use of exec (exec-used)</string>
<string>W:444, 6: No exception type(s) specified (bare-except)</string> <string>W:453, 6: No exception type(s) specified (bare-except)</string>
<string>W:697, 6: Use of exec (exec-used)</string> <string>W:706, 6: Use of exec (exec-used)</string>
<string>W:923, 2: Redefining name \'IFrame\' from outer scope (line 4) (redefined-outer-name)</string> <string>W:932, 2: Redefining name \'IFrame\' from outer scope (line 4) (redefined-outer-name)</string>
<string>W: 18, 0: Unused log imported from Products.ERP5Type.Log (unused-import)</string> <string>W: 18, 0: Unused log imported from Products.ERP5Type.Log (unused-import)</string>
</tuple> </tuple>
</value> </value>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment