mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Merge pull request #7658 from tk0miya/7646_errors_on_event_handlers
Fix: handle errors on event handlers (refs: #7629)
This commit is contained in:
commit
0c9754b6cb
1
CHANGES
1
CHANGES
@ -103,6 +103,7 @@ Bugs fixed
|
|||||||
* #7628: imgconverter: runs imagemagick once unnecessary for builders not
|
* #7628: imgconverter: runs imagemagick once unnecessary for builders not
|
||||||
supporting images
|
supporting images
|
||||||
* #7610: incorrectly renders consecutive backslashes for docutils-0.16
|
* #7610: incorrectly renders consecutive backslashes for docutils-0.16
|
||||||
|
* #7646: handle errors on event handlers
|
||||||
|
|
||||||
Testing
|
Testing
|
||||||
--------
|
--------
|
||||||
|
@ -16,7 +16,7 @@ from operator import attrgetter
|
|||||||
from typing import Any, Callable, Dict, List, NamedTuple
|
from typing import Any, Callable, Dict, List, NamedTuple
|
||||||
|
|
||||||
from sphinx.deprecation import RemovedInSphinx40Warning
|
from sphinx.deprecation import RemovedInSphinx40Warning
|
||||||
from sphinx.errors import ExtensionError
|
from sphinx.errors import ExtensionError, SphinxError
|
||||||
from sphinx.locale import __
|
from sphinx.locale import __
|
||||||
from sphinx.util import logging
|
from sphinx.util import logging
|
||||||
|
|
||||||
@ -100,11 +100,17 @@ class EventManager:
|
|||||||
results = []
|
results = []
|
||||||
listeners = sorted(self.listeners[name], key=attrgetter("priority"))
|
listeners = sorted(self.listeners[name], key=attrgetter("priority"))
|
||||||
for listener in listeners:
|
for listener in listeners:
|
||||||
if self.app is None:
|
try:
|
||||||
# for compatibility; RemovedInSphinx40Warning
|
if self.app is None:
|
||||||
results.append(listener.handler(*args))
|
# for compatibility; RemovedInSphinx40Warning
|
||||||
else:
|
results.append(listener.handler(*args))
|
||||||
results.append(listener.handler(self.app, *args))
|
else:
|
||||||
|
results.append(listener.handler(self.app, *args))
|
||||||
|
except SphinxError:
|
||||||
|
raise
|
||||||
|
except Exception as exc:
|
||||||
|
raise ExtensionError(__("Handler %r for event %r threw an exception") %
|
||||||
|
(listener.handler, name)) from exc
|
||||||
return results
|
return results
|
||||||
|
|
||||||
def emit_firstresult(self, name: str, *args: Any) -> Any:
|
def emit_firstresult(self, name: str, *args: Any) -> Any:
|
||||||
|
Loading…
Reference in New Issue
Block a user