bpo-35931: Gracefully handle SyntaxError in pdb debug command (GH-11782) · python/cpython@6f35219
@@ -1093,10 +1093,16 @@ def do_debug(self, arg):
10931093sys.settrace(None)
10941094globals = self.curframe.f_globals
10951095locals = self.curframe_locals
1096+try:
1097+code = compile(arg, "<string>", "exec")
1098+except SyntaxError:
1099+exc_info = sys.exc_info()[:2]
1100+self.error(traceback.format_exception_only(*exc_info)[-1].strip())
1101+return
10961102p = Pdb(self.completekey, self.stdin, self.stdout)
10971103p.prompt = "(%s) " % self.prompt.strip()
10981104self.message("ENTERING RECURSIVE DEBUGGER")
1099-sys.call_tracing(p.run, (arg, globals, locals))
1105+sys.call_tracing(p.run, (code, globals, locals))
11001106self.message("LEAVING RECURSIVE DEBUGGER")
11011107sys.settrace(self.trace_dispatch)
11021108self.lastcmd = p.lastcmd