Make -P (pdb) work better with exceptions triggered from events

Previously, if an exception was raised from an event listener, and the
`-P` option was specified, the debugger would be started not for the
original error but for the `ExtensionError` wrapping it that was
raised by `EventManager.emit`.  That made it difficult to debug the
error.

With this change, when `-P` is specified, wrapping of errors in
`ExtensionError` is disabled, which allows pdb to debug the original
error.
This commit is contained in:
Jeremy Maitin-Shepard
2022-07-03 17:56:14 -07:00
parent 7e76f2c307
commit 66f9ee4afd
5 changed files with 31 additions and 3 deletions

View File

@@ -19,11 +19,16 @@ def test_event_priority():
assert result == [3, 1, 2, 5, 4]
class FakeApp:
def __init__(self, pdb: bool = False):
self.pdb = pdb
def test_event_allowed_exceptions():
def raise_error(app):
raise RuntimeError
events = EventManager(object()) # pass an dummy object as an app
events = EventManager(FakeApp()) # pass an dummy object as an app
events.connect('builder-inited', raise_error, priority=500)
# all errors are converted to ExtensionError
@@ -33,3 +38,19 @@ def test_event_allowed_exceptions():
# Allow RuntimeError (pass-through)
with pytest.raises(RuntimeError):
events.emit('builder-inited', allowed_exceptions=(RuntimeError,))
def test_event_pdb():
def raise_error(app):
raise RuntimeError
events = EventManager(FakeApp(pdb=True)) # pass an dummy object as an app
events.connect('builder-inited', raise_error, priority=500)
# errors aren't converted
with pytest.raises(RuntimeError):
events.emit('builder-inited')
# Allow RuntimeError (pass-through)
with pytest.raises(RuntimeError):
events.emit('builder-inited', allowed_exceptions=(RuntimeError,))