diff --git a/qutebrowser/utils/error.py b/qutebrowser/utils/error.py index 7ec29ed02..ee8a9f8af 100644 --- a/qutebrowser/utils/error.py +++ b/qutebrowser/utils/error.py @@ -49,12 +49,15 @@ def handle_fatal_exc(exc, args, title, *, pre_text='', post_text=''): post_text: The text to be displayed after the exception text. """ if args.no_err_windows: - log.misc.exception("Handling fatal {} with --no-err-windows!".format( - _get_name(exc))) - log.misc.error("title: {}".format(title)) - log.misc.error("pre_text: {}".format(pre_text)) - log.misc.error("post_text: {}".format(post_text)) - log.misc.error("exception text: {}".format(str(exc) or 'none')) + lines = [ + "Handling fatal {} with --no-err-windows!".format(_get_name(exc)), + "", + "title: {}".format(title), + "pre_text: {}".format(pre_text), + "post_text: {}".format(post_text), + "exception text: {}".format(str(exc) or 'none'), + ] + log.misc.exception('\n'.join(lines)) else: if pre_text: msg_text = '{}: {}'.format(pre_text, exc) diff --git a/tests/unit/misc/test_ipc.py b/tests/unit/misc/test_ipc.py index 841003b4a..1b76db547 100644 --- a/tests/unit/misc/test_ipc.py +++ b/tests/unit/misc/test_ipc.py @@ -601,16 +601,19 @@ class TestSendOrListen: with pytest.raises(ipc.Error): ipc.send_or_listen(args) - msgs = [e.message for e in caplog.records()] + records = caplog.records() + assert len(records) == 1 + error_msgs = [ 'Handling fatal misc.ipc.{} with --no-err-windows!'.format( exc_name), + '', 'title: Error while connecting to running instance!', 'pre_text: ', 'post_text: Maybe another instance is running but frozen?', 'exception text: {}'.format(exc_msg), ] - assert msgs[-5:] == error_msgs + assert records[0].msg == '\n'.join(error_msgs) @pytest.mark.posix # Flaky on Windows def test_error_while_listening(self, qlocalserver_mock, caplog, args): @@ -623,16 +626,19 @@ class TestSendOrListen: with pytest.raises(ipc.Error): ipc.send_or_listen(args) - msgs = [e.message for e in caplog.records()] + records = caplog.records() + assert len(records) == 1 + error_msgs = [ 'Handling fatal misc.ipc.ListenError with --no-err-windows!', + '', 'title: Error while connecting to running instance!', 'pre_text: ', 'post_text: Maybe another instance is running but frozen?', 'exception text: Error while listening to IPC server: Error ' 'string (error 4)', ] - assert msgs[-5:] == error_msgs + assert records[0].msg == '\n'.join(error_msgs) def test_long_username(fake_runtime_dir): diff --git a/tests/unit/utils/test_error.py b/tests/unit/utils/test_error.py index b49b02fa6..1631902ea 100644 --- a/tests/unit/utils/test_error.py +++ b/tests/unit/utils/test_error.py @@ -55,15 +55,19 @@ def test_no_err_windows(caplog, exc, name, exc_text): with caplog.atLevel(logging.ERROR): error.handle_fatal_exc(e, Args(no_err_windows=True), 'title', pre_text='pre', post_text='post') - msgs = [rec.message for rec in caplog.records()] + + records = caplog.records() + assert len(records) == 1 + expected = [ 'Handling fatal {} with --no-err-windows!'.format(name), + '', 'title: title', 'pre_text: pre', 'post_text: post', 'exception text: {}'.format(exc_text), ] - assert msgs[-5:] == expected + assert records[0].msg == '\n'.join(expected) @pytest.mark.parametrize('pre_text, post_text, expected', [