##// END OF EJS Templates
Capture errors in user's input lines and raises meaningfull exceptions.
gvaroquaux -
Show More
@@ -21,6 +21,7 b' import re'
21 import IPython
21 import IPython
22 import sys
22 import sys
23 import codeop
23 import codeop
24 import traceback
24
25
25 from frontendbase import FrontEndBase
26 from frontendbase import FrontEndBase
26 from IPython.kernel.core.interpreter import Interpreter
27 from IPython.kernel.core.interpreter import Interpreter
@@ -147,10 +148,18 b' class LineFrontEndBase(FrontEndBase):'
147 and not re.findall(r"\n[\t ]*\n[\t ]*$", string)):
148 and not re.findall(r"\n[\t ]*\n[\t ]*$", string)):
148 return False
149 return False
149 else:
150 else:
150 # Add line returns here, to make sure that the statement is
151 self.capture_output()
151 # complete.
152 try:
152 return codeop.compile_command(string.rstrip() + '\n\n',
153 # Add line returns here, to make sure that the statement is
153 "<string>", "exec")
154 # complete.
155 is_complete = codeop.compile_command(string.rstrip() + '\n\n',
156 "<string>", "exec")
157 self.release_output()
158 except Exception, e:
159 # XXX: Hack: return True so that the
160 # code gets executed and the error captured.
161 is_complete = True
162 return is_complete
154
163
155
164
156 def write(self, string, refresh=True):
165 def write(self, string, refresh=True):
@@ -324,6 +324,17 b' class WxController(ConsoleWidget, PrefilterFrontEnd):'
324
324
325
325
326 #--------------------------------------------------------------------------
326 #--------------------------------------------------------------------------
327 # FrontEndBase interface
328 #--------------------------------------------------------------------------
329
330 def render_error(self, e):
331 start_line = self.GetCurrentLine()
332 self.write('\n' + e + '\n')
333 for i in range(start_line, self.GetCurrentLine()):
334 self._markers[i] = self.MarkerAdd(i, _ERROR_MARKER)
335
336
337 #--------------------------------------------------------------------------
327 # ConsoleWidget interface
338 # ConsoleWidget interface
328 #--------------------------------------------------------------------------
339 #--------------------------------------------------------------------------
329
340
General Comments 0
You need to be logged in to leave comments. Login now