Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nodebook throws a KeyError when an Exception is caught and bound to a variable #21

Open
neon-ninja opened this issue Nov 7, 2021 · 0 comments

Comments

@neon-ninja
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant