mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
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:
@@ -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,))
|
||||
|
||||
Reference in New Issue
Block a user