dispatch: enter ipdb for "NameError 'ipdb' is not defined"

Summary:
This allows entering ipdb for code like: `ipdb` or `ipdb()`. It can be handy to
debug something.

Reviewed By: DurhamG

Differential Revision: D23278599

fbshipit-source-id: 4355dd1944617aeb795450935789f01f66f094eb
This commit is contained in:
Jun Wu 2020-08-27 18:11:28 -07:00 committed by Facebook GitHub Bot
parent 28fa0e1cfe
commit d92c80ebcc

View File

@ -725,18 +725,23 @@ def _callcatch(ui, func):
raise
except: # probably re-raises
# Potentially enter ipdb debugger when we hit an uncaught exception
ex = sys.exc_info()[1]
isipdb = isinstance(ex, NameError) and "'ipdb'" in str(ex)
if (
ui.configbool("devel", "debugger")
(ui.configbool("devel", "debugger") or isipdb)
and ui.interactive()
and not ui.pageractive
and not ui.plain()
and ui.formatted
):
ui.write_err(
_(
"Starting ipdb for this exception\nIf you don't want the behavior, set devel.debugger to False\n"
if isipdb:
ui.write_err(_("Starting ipdb for 'ipdb'\n"))
else:
ui.write_err(
_(
"Starting ipdb for this exception\nIf you don't want the behavior, set devel.debugger to False\n"
)
)
)
with demandimport.deactivated():
import ipdb