diff options
author | Daniel Hahler <git@thequod.de> | 2021-06-10 20:32:04 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-06-10 20:32:04 (GMT) |
commit | 6544b2532df82d137b71323445a07a6e29bcdec0 (patch) | |
tree | 82d643644f5274a19db30e8f0c10498d8b77b1ac /Lib/pdb.py | |
parent | 8a4f0850d75747af8c96ca0e7eef1f5c1abfba25 (diff) | |
download | cpython-6544b2532df82d137b71323445a07a6e29bcdec0.zip cpython-6544b2532df82d137b71323445a07a6e29bcdec0.tar.gz cpython-6544b2532df82d137b71323445a07a6e29bcdec0.tar.bz2 |
bpo-37022: Fix bug where pdb's do_p/do_pp commands swallow exceptions from repr (GH-18180)
Diffstat (limited to 'Lib/pdb.py')
-rwxr-xr-x | Lib/pdb.py | 33 |
1 files changed, 19 insertions, 14 deletions
@@ -384,8 +384,7 @@ class Pdb(bdb.Bdb, cmd.Cmd): sys.stdin = save_stdin sys.displayhook = save_displayhook except: - exc_info = sys.exc_info()[:2] - self.error(traceback.format_exception_only(*exc_info)[-1].strip()) + self._error_exc() def precmd(self, line): """Handle alias expansion and ';;' separator.""" @@ -1104,8 +1103,7 @@ class Pdb(bdb.Bdb, cmd.Cmd): try: sys.call_tracing(p.run, (arg, globals, locals)) except Exception: - exc_info = sys.exc_info()[:2] - self.error(traceback.format_exception_only(*exc_info)[-1].strip()) + self._error_exc() self.message("LEAVING RECURSIVE DEBUGGER") sys.settrace(self.trace_dispatch) self.lastcmd = p.lastcmd @@ -1163,8 +1161,7 @@ class Pdb(bdb.Bdb, cmd.Cmd): try: return eval(arg, self.curframe.f_globals, self.curframe_locals) except: - exc_info = sys.exc_info()[:2] - self.error(traceback.format_exception_only(*exc_info)[-1].strip()) + self._error_exc() raise def _getval_except(self, arg, frame=None): @@ -1178,23 +1175,31 @@ class Pdb(bdb.Bdb, cmd.Cmd): err = traceback.format_exception_only(*exc_info)[-1].strip() return _rstr('** raised %s **' % err) + def _error_exc(self): + exc_info = sys.exc_info()[:2] + self.error(traceback.format_exception_only(*exc_info)[-1].strip()) + + def _msg_val_func(self, arg, func): + try: + val = self._getval(arg) + except: + return # _getval() has displayed the error + try: + self.message(func(val)) + except: + self._error_exc() + def do_p(self, arg): """p expression Print the value of the expression. """ - try: - self.message(repr(self._getval(arg))) - except: - pass + self._msg_val_func(arg, repr) def do_pp(self, arg): """pp expression Pretty-print the value of the expression. """ - try: - self.message(pprint.pformat(self._getval(arg))) - except: - pass + self._msg_val_func(arg, pprint.pformat) complete_print = _complete_expression complete_p = _complete_expression |