From ef134fb142af156b6ea1c5bdcb651f60cd87c0a9 Mon Sep 17 00:00:00 2001 From: Takeshi KOMIYA Date: Wed, 10 Oct 2018 22:49:39 +0900 Subject: [PATCH] Fix #5493: gettext: crashed with broken template --- CHANGES | 1 + sphinx/builders/gettext.py | 14 +++++++++----- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/CHANGES b/CHANGES index 00ebf1e76..71593fa7d 100644 --- a/CHANGES +++ b/CHANGES @@ -19,6 +19,7 @@ Bugs fixed * #5490: latex: enumerated list causes a crash with recommonmark * #5492: sphinx-build fails to build docs w/ Python < 3.5.2 * #3704: latex: wrong ``\label`` positioning for figures with a legend +* #5493: gettext: crashed with broken template Testing -------- diff --git a/sphinx/builders/gettext.py b/sphinx/builders/gettext.py index b43dcfb3b..9981012a0 100644 --- a/sphinx/builders/gettext.py +++ b/sphinx/builders/gettext.py @@ -22,6 +22,7 @@ from six import iteritems, StringIO from sphinx.builders import Builder from sphinx.domains.python import pairindextypes +from sphinx.errors import ThemeError from sphinx.locale import __ from sphinx.util import split_index_msg, logging, status_iterator from sphinx.util.console import bold # type: ignore @@ -247,11 +248,14 @@ class MessageCatalogBuilder(I18nBuilder): for template in status_iterator(files, __('reading templates... '), "purple", # type: ignore # NOQA len(files), self.app.verbosity): - with open(template, 'r', encoding='utf-8') as f: # type: ignore - context = f.read() - for line, meth, msg in extract_translations(context): - origin = MsgOrigin(template, line) - self.catalogs['sphinx'].add(msg, origin) + try: + with open(template, 'r', encoding='utf-8') as f: # type: ignore + context = f.read() + for line, meth, msg in extract_translations(context): + origin = MsgOrigin(template, line) + self.catalogs['sphinx'].add(msg, origin) + except Exception as exc: + raise ThemeError('%s: %r' % (template, exc)) def build(self, docnames, summary=None, method='update'): # type: (Iterable[unicode], unicode, unicode) -> None