Handle empty messages in qt_message_handler
I can't reproduce this, but someone on KDE reported always getting a crash (as msg.splitlines()[0] gives an IndexError) when trying to select a file with Qt 5.9.3.
This commit is contained in:
parent
03a9cbdfb4
commit
67253726fa
@ -422,6 +422,9 @@ def qt_message_handler(msg_type, context, msg):
|
|||||||
'with: -9805', # flake8: disable=E131
|
'with: -9805', # flake8: disable=E131
|
||||||
]
|
]
|
||||||
|
|
||||||
|
if not msg:
|
||||||
|
msg = "Logged empty message!"
|
||||||
|
|
||||||
if any(msg.strip().startswith(pattern) for pattern in suppressed_msgs):
|
if any(msg.strip().startswith(pattern) for pattern in suppressed_msgs):
|
||||||
level = logging.DEBUG
|
level = logging.DEBUG
|
||||||
else:
|
else:
|
||||||
|
@ -25,12 +25,15 @@ import itertools
|
|||||||
import sys
|
import sys
|
||||||
import warnings
|
import warnings
|
||||||
|
|
||||||
|
import attr
|
||||||
import pytest
|
import pytest
|
||||||
import pytest_catchlog
|
import pytest_catchlog
|
||||||
|
|
||||||
from qutebrowser.utils import log
|
from qutebrowser.utils import log
|
||||||
from qutebrowser.misc import utilcmds
|
from qutebrowser.misc import utilcmds
|
||||||
|
|
||||||
|
from PyQt5 import QtCore
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(autouse=True)
|
@pytest.fixture(autouse=True)
|
||||||
def restore_loggers():
|
def restore_loggers():
|
||||||
@ -252,3 +255,22 @@ def test_ignore_py_warnings(caplog):
|
|||||||
assert len(caplog.records) == 1
|
assert len(caplog.records) == 1
|
||||||
msg = caplog.records[0].message.splitlines()[0]
|
msg = caplog.records[0].message.splitlines()[0]
|
||||||
assert msg.endswith("UserWarning: not hidden")
|
assert msg.endswith("UserWarning: not hidden")
|
||||||
|
|
||||||
|
|
||||||
|
class TestQtMessageHandler:
|
||||||
|
|
||||||
|
@attr.s
|
||||||
|
class Context:
|
||||||
|
|
||||||
|
"""Fake QMessageLogContext."""
|
||||||
|
|
||||||
|
function = attr.ib(default=None)
|
||||||
|
category = attr.ib(default=None)
|
||||||
|
file = attr.ib(default=None)
|
||||||
|
line = attr.ib(default=None)
|
||||||
|
|
||||||
|
def test_empty_message(self, caplog):
|
||||||
|
"""Make sure there's no crash with an empty message."""
|
||||||
|
log.qt_message_handler(QtCore.QtDebugMsg, self.Context(), "")
|
||||||
|
assert len(caplog.records) == 1
|
||||||
|
assert caplog.records[0].msg == "Logged empty message!"
|
||||||
|
Loading…
Reference in New Issue
Block a user