From 29c462410dae6851599ac935817c80017b81c058 2011-05-04 22:04:10 From: MinRK Date: 2011-05-04 22:04:10 Subject: [PATCH] prevent errors in prefilter from crashing IPython closes gh-216 --- diff --git a/IPython/core/interactiveshell.py b/IPython/core/interactiveshell.py index 3761dc8..7e130d5 100644 --- a/IPython/core/interactiveshell.py +++ b/IPython/core/interactiveshell.py @@ -2130,7 +2130,20 @@ class InteractiveShell(Configurable, Magic): 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: diff --git a/IPython/core/tests/test_interactiveshell.py b/IPython/core/tests/test_interactiveshell.py index 3e930b7..cf1ea96 100644 --- a/IPython/core/tests/test_interactiveshell.py +++ b/IPython/core/tests/test_interactiveshell.py @@ -91,3 +91,9 @@ class InteractiveShellTestCase(unittest.TestCase): 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')