Merge pull request #7658 from tk0miya/7646_errors_on_event_handlers

Fix: handle errors on event handlers (refs: #7629)
This commit is contained in:
Takeshi KOMIYA 2020-05-16 18:24:49 +09:00 committed by GitHub
commit 0c9754b6cb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 6 deletions

View File

@ -103,6 +103,7 @@ Bugs fixed
* #7628: imgconverter: runs imagemagick once unnecessary for builders not
supporting images
* #7610: incorrectly renders consecutive backslashes for docutils-0.16
* #7646: handle errors on event handlers
Testing
--------

View File

@ -16,7 +16,7 @@ from operator import attrgetter
from typing import Any, Callable, Dict, List, NamedTuple
from sphinx.deprecation import RemovedInSphinx40Warning
from sphinx.errors import ExtensionError
from sphinx.errors import ExtensionError, SphinxError
from sphinx.locale import __
from sphinx.util import logging
@ -100,11 +100,17 @@ class EventManager:
results = []
listeners = sorted(self.listeners[name], key=attrgetter("priority"))
for listener in listeners:
if self.app is None:
# for compatibility; RemovedInSphinx40Warning
results.append(listener.handler(*args))
else:
results.append(listener.handler(self.app, *args))
try:
if self.app is None:
# for compatibility; RemovedInSphinx40Warning
results.append(listener.handler(*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
def emit_firstresult(self, name: str, *args: Any) -> Any: