# Buggy code
def filter(self, record):
    # type: (logging.LogRecord) -> bool
    if getattr(record, "skip_warningsiserror", False):
        # disabled by DisableWarningIsErrorFilter
        return True
    elif self.app.warningiserror:
        location = getattr(record, "location", "")
        message = record.msg.replace("%", "%%")
        if location:
            raise SphinxWarning(location + ":" + message % record.args)
        else:
            raise SphinxWarning(message % record.args)
    else:
        return True


# Traceback (TypeError)
# Sphinx version: 1.6.4
# Python version: 2.7.12 (CPython)
# Docutils version: 0.14
# Jinja2 version: 2.9.6
# Last messages:

# Loaded extensions:
Traceback (most recent call last):
File "/home/ian/git/openstack/horizon/.tox/venv/local/lib/python2.7/site-packages/sphinx/setup_command.py", line 191, in run
warningiserror=self.warning_is_error)
File "/home/ian/git/openstack/horizon/.tox/venv/local/lib/python2.7/site-packages/sphinx/application.py", line 196, in __init__
self.setup_extension(extension)
File "/home/ian/git/openstack/horizon/.tox/venv/local/lib/python2.7/site-packages/sphinx/application.py", line 456, in setup_extension
self.registry.load_extension(self, extname)
File "/home/ian/git/openstack/horizon/.tox/venv/local/lib/python2.7/site-packages/sphinx/registry.py", line 207, in load_extension
metadata = mod.setup(app)
File "/home/ian/git/openstack/horizon/.tox/venv/local/lib/python2.7/site-packages/sphinx/ext/todo.py", line 231, in setup
app.add_node(todolist)
File "/home/ian/git/openstack/horizon/.tox/venv/local/lib/python2.7/site-packages/sphinx/application.py", line 530, in add_node
type='app', subtype='add_node')
File "/usr/lib/python2.7/logging/__init__.py", line 1456, in warning
self.logger.warning(msg, *args, **kwargs)
File "/usr/lib/python2.7/logging/__init__.py", line 1179, in warning
self._log(WARNING, msg, args, **kwargs)
File "/usr/lib/python2.7/logging/__init__.py", line 1286, in _log
self.handle(record)
File "/usr/lib/python2.7/logging/__init__.py", line 1296, in handle
self.callHandlers(record)
File "/usr/lib/python2.7/logging/__init__.py", line 1336, in callHandlers
hdlr.handle(record)
File "/usr/lib/python2.7/logging/__init__.py", line 755, in handle
rv = self.filter(record)
File "/usr/lib/python2.7/logging/__init__.py", line 617, in filter
if not f.filter(record):
File "/home/ian/git/openstack/horizon/.tox/venv/local/lib/python2.7/site-packages/sphinx/util/logging.py", line 363, in filter
raise SphinxWarning(message % record.args)
TypeError: not all arguments converted during string formatting

# Fixed code
def filter(self, record):
    # type: (logging.LogRecord) -> bool
    if getattr(record, "skip_warningsiserror", False):
        # disabled by DisableWarningIsErrorFilter
        return True
    elif self.app.warningiserror:
        location = getattr(record, "location", "")
        try:
            message = record.msg % record.args
        except TypeError:
            message = record.msg  # use record.msg itself

        if location:
            raise SphinxWarning(location + ":" + message)
        else:
            raise SphinxWarning(message)
    else:
        return True