nodebook throws a KeyError when an Exception is caught and bound to a variable
neon-ninja opened this issue · 0 comments
neon-ninja commented
In a nodebook enabled notebook, the cell:
try:
1/0
except Exception as e:
print(e)
throws the following Exception, instead of catching the the ZeroDivisionError:
---------------------------------------------------------------------------
KeyError Traceback (most recent call last)
<ipython-input-2-5f477361abed> in <module>
----> 1 get_ipython().run_cell_magic('execute_cell', ' 0683b3b36079448da8789b4c92d28340', 'try:\n 1/0\nexcept Exception as e:\n print(e)\n')
/usr/local/lib/python3.8/dist-packages/IPython/core/interactiveshell.py in run_cell_magic(self, magic_name, line, cell)
2401 with self.builtin_trap:
2402 args = (magic_arg_s, cell)
-> 2403 result = fn(*args, **kwargs)
2404 return result
2405
~/git/nodebook/nodebook/ipython/nodebookext.py in execute_cell(line, cell)
79 # update code and run
80 NODEBOOK_STATE['nodebook'].update_code(cell_id, cell)
---> 81 res, objs = NODEBOOK_STATE['nodebook'].run_node(cell_id)
82
83 # update prompts
~/git/nodebook/nodebook/nodebookcore.py in run_node(self, node_id)
114 input_hashes = {}
115 for var in node.inputs.keys():
--> 116 val_hash = self._find_latest_output(node.parent, var)
117 if val_hash is not None:
118 input_objs[var] = self.variables[val_hash]
~/git/nodebook/nodebook/nodebookcore.py in _find_latest_output(self, node, var)
139 return None
140 else:
--> 141 raise KeyError("name '%s' is not defined" % var)
142
143 if var in node.outputs:
KeyError: "name 'e' is not defined"
Setting e = None
beforehand seems to work as a workaround.