##// END OF EJS Templates
short error message on AliasError in run_cell...
MinRK -
Show More
@@ -38,7 +38,7 b' from IPython.core import page'
38 from IPython.core import prefilter
38 from IPython.core import prefilter
39 from IPython.core import shadowns
39 from IPython.core import shadowns
40 from IPython.core import ultratb
40 from IPython.core import ultratb
41 from IPython.core.alias import AliasManager
41 from IPython.core.alias import AliasManager, AliasError
42 from IPython.core.autocall import ExitAutocall
42 from IPython.core.autocall import ExitAutocall
43 from IPython.core.builtin_trap import BuiltinTrap
43 from IPython.core.builtin_trap import BuiltinTrap
44 from IPython.core.compilerop import CachingCompiler
44 from IPython.core.compilerop import CachingCompiler
@@ -2129,22 +2129,18 b' class InteractiveShell(Configurable, Magic):'
2129 cell = self.input_splitter.source_reset()
2129 cell = self.input_splitter.source_reset()
2130
2130
2131 with self.builtin_trap:
2131 with self.builtin_trap:
2132 prefilter_failed = False
2132 if len(cell.splitlines()) == 1:
2133 if len(cell.splitlines()) == 1:
2133 try:
2134 try:
2134 cell = self.prefilter_manager.prefilter_lines(cell)
2135 cell = self.prefilter_manager.prefilter_lines(cell)
2136 except AliasError as e:
2137 error(e)
2138 prefilter_failed=True
2135 except Exception:
2139 except Exception:
2136 # don't allow prefilter errors to crash IPython, because
2140 # don't allow prefilter errors to crash IPython
2137 # user code can be involved (e.g. aliases)
2138 self.showtraceback()
2141 self.showtraceback()
2139 if store_history:
2142 prefilter_failed = True
2140 self.history_manager.store_inputs(self.execution_count,
2143
2141 cell, raw_cell)
2142
2143 self.logger.log(cell, raw_cell)
2144 self.execution_count += 1
2145
2146 return
2147
2148 # Store raw and processed history
2144 # Store raw and processed history
2149 if store_history:
2145 if store_history:
2150 self.history_manager.store_inputs(self.execution_count,
2146 self.history_manager.store_inputs(self.execution_count,
@@ -2152,30 +2148,32 b' class InteractiveShell(Configurable, Magic):'
2152
2148
2153 self.logger.log(cell, raw_cell)
2149 self.logger.log(cell, raw_cell)
2154
2150
2155 cell_name = self.compile.cache(cell, self.execution_count)
2151 if not prefilter_failed:
2152 # don't run if prefilter failed
2153 cell_name = self.compile.cache(cell, self.execution_count)
2156
2154
2157 with self.display_trap:
2155 with self.display_trap:
2158 try:
2159 code_ast = ast.parse(cell, filename=cell_name)
2160 except (OverflowError, SyntaxError, ValueError, TypeError,
2161 MemoryError):
2162 self.showsyntaxerror()
2163 self.execution_count += 1
2164 return None
2165
2166 self.run_ast_nodes(code_ast.body, cell_name,
2167 interactivity="last_expr")
2168
2169 # Execute any registered post-execution functions.
2170 for func, status in self._post_execute.iteritems():
2171 if not status:
2172 continue
2173 try:
2156 try:
2174 func()
2157 code_ast = ast.parse(cell, filename=cell_name)
2175 except:
2158 except (OverflowError, SyntaxError, ValueError, TypeError,
2176 self.showtraceback()
2159 MemoryError):
2177 # Deactivate failing function
2160 self.showsyntaxerror()
2178 self._post_execute[func] = False
2161 self.execution_count += 1
2162 return None
2163
2164 self.run_ast_nodes(code_ast.body, cell_name,
2165 interactivity="last_expr")
2166
2167 # Execute any registered post-execution functions.
2168 for func, status in self._post_execute.iteritems():
2169 if not status:
2170 continue
2171 try:
2172 func()
2173 except:
2174 self.showtraceback()
2175 # Deactivate failing function
2176 self._post_execute[func] = False
2179
2177
2180 if store_history:
2178 if store_history:
2181 # Write output to the database. Does nothing unless
2179 # Write output to the database. Does nothing unless
@@ -20,7 +20,10 b' Authors'
20 #-----------------------------------------------------------------------------
20 #-----------------------------------------------------------------------------
21 # stdlib
21 # stdlib
22 import unittest
22 import unittest
23 from cStringIO import StringIO
24
23 from IPython.testing import decorators as dec
25 from IPython.testing import decorators as dec
26 from IPython.utils import io
24
27
25 #-----------------------------------------------------------------------------
28 #-----------------------------------------------------------------------------
26 # Tests
29 # Tests
@@ -96,4 +99,11 b' class InteractiveShellTestCase(unittest.TestCase):'
96 """Errors in prefilter can't crash IPython"""
99 """Errors in prefilter can't crash IPython"""
97 ip = get_ipython()
100 ip = get_ipython()
98 ip.run_cell('%alias parts echo first %s second %s')
101 ip.run_cell('%alias parts echo first %s second %s')
102 # capture stderr:
103 save_err = io.stderr
104 io.stderr = StringIO()
99 ip.run_cell('parts 1')
105 ip.run_cell('parts 1')
106 err = io.stderr.getvalue()
107 io.stderr = save_err
108 self.assertEquals(err.split(':')[0], 'ERROR')
109
General Comments 0
You need to be logged in to leave comments. Login now