Permalink
Browse files

prevent errors in prefilter from crashing IPython

closes gh-216
  • Loading branch information...
1 parent e61c64c commit 29c462410dae6851599ac935817c80017b81c058 @minrk committed May 4, 2011
Showing with 20 additions and 1 deletion.
  1. +14 −1 IPython/core/interactiveshell.py
  2. +6 −0 IPython/core/tests/test_interactiveshell.py
@@ -2130,7 +2130,20 @@ def run_cell(self, raw_cell, store_history=True):
with self.builtin_trap:
if len(cell.splitlines()) == 1:
- cell = self.prefilter_manager.prefilter_lines(cell)
+ try:
+ cell = self.prefilter_manager.prefilter_lines(cell)
+ except Exception:
+ # don't allow prefilter errors to crash IPython, because
+ # user code can be involved (e.g. aliases)
+ self.showtraceback()
+ if store_history:
+ self.history_manager.store_inputs(self.execution_count,
+ cell, raw_cell)
+
+ self.logger.log(cell, raw_cell)
+ self.execution_count += 1
+
+ return
# Store raw and processed history
if store_history:
@@ -91,3 +91,9 @@ def test_magic_names_in_string(self):
ip = get_ipython()
ip.run_cell('a = """\n%exit\n"""')
self.assertEquals(ip.user_ns['a'], '\n%exit\n')
+
+ def test_alias_crash(self):
+ """Errors in prefilter can't crash IPython"""
+ ip = get_ipython()
+ ip.run_cell('%alias parts echo first %s second %s')
+ ip.run_cell('parts 1')

0 comments on commit 29c4624

Please sign in to comment.