Only log a single message in utils.error.

This helps with seeing the full message with logfail.
This commit is contained in:
Florian Bruhin 2015-09-09 09:01:40 +02:00
parent 9d9372c6a8
commit a4bc4ad478
3 changed files with 25 additions and 12 deletions

View File

@ -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. post_text: The text to be displayed after the exception text.
""" """
if args.no_err_windows: if args.no_err_windows:
log.misc.exception("Handling fatal {} with --no-err-windows!".format( lines = [
_get_name(exc))) "Handling fatal {} with --no-err-windows!".format(_get_name(exc)),
log.misc.error("title: {}".format(title)) "",
log.misc.error("pre_text: {}".format(pre_text)) "title: {}".format(title),
log.misc.error("post_text: {}".format(post_text)) "pre_text: {}".format(pre_text),
log.misc.error("exception text: {}".format(str(exc) or 'none')) "post_text: {}".format(post_text),
"exception text: {}".format(str(exc) or 'none'),
]
log.misc.exception('\n'.join(lines))
else: else:
if pre_text: if pre_text:
msg_text = '{}: {}'.format(pre_text, exc) msg_text = '{}: {}'.format(pre_text, exc)

View File

@ -601,16 +601,19 @@ class TestSendOrListen:
with pytest.raises(ipc.Error): with pytest.raises(ipc.Error):
ipc.send_or_listen(args) ipc.send_or_listen(args)
msgs = [e.message for e in caplog.records()] records = caplog.records()
assert len(records) == 1
error_msgs = [ error_msgs = [
'Handling fatal misc.ipc.{} with --no-err-windows!'.format( 'Handling fatal misc.ipc.{} with --no-err-windows!'.format(
exc_name), exc_name),
'',
'title: Error while connecting to running instance!', 'title: Error while connecting to running instance!',
'pre_text: ', 'pre_text: ',
'post_text: Maybe another instance is running but frozen?', 'post_text: Maybe another instance is running but frozen?',
'exception text: {}'.format(exc_msg), 'exception text: {}'.format(exc_msg),
] ]
assert msgs[-5:] == error_msgs assert records[0].msg == '\n'.join(error_msgs)
@pytest.mark.posix # Flaky on Windows @pytest.mark.posix # Flaky on Windows
def test_error_while_listening(self, qlocalserver_mock, caplog, args): def test_error_while_listening(self, qlocalserver_mock, caplog, args):
@ -623,16 +626,19 @@ class TestSendOrListen:
with pytest.raises(ipc.Error): with pytest.raises(ipc.Error):
ipc.send_or_listen(args) ipc.send_or_listen(args)
msgs = [e.message for e in caplog.records()] records = caplog.records()
assert len(records) == 1
error_msgs = [ error_msgs = [
'Handling fatal misc.ipc.ListenError with --no-err-windows!', 'Handling fatal misc.ipc.ListenError with --no-err-windows!',
'',
'title: Error while connecting to running instance!', 'title: Error while connecting to running instance!',
'pre_text: ', 'pre_text: ',
'post_text: Maybe another instance is running but frozen?', 'post_text: Maybe another instance is running but frozen?',
'exception text: Error while listening to IPC server: Error ' 'exception text: Error while listening to IPC server: Error '
'string (error 4)', 'string (error 4)',
] ]
assert msgs[-5:] == error_msgs assert records[0].msg == '\n'.join(error_msgs)
def test_long_username(fake_runtime_dir): def test_long_username(fake_runtime_dir):

View File

@ -55,15 +55,19 @@ def test_no_err_windows(caplog, exc, name, exc_text):
with caplog.atLevel(logging.ERROR): with caplog.atLevel(logging.ERROR):
error.handle_fatal_exc(e, Args(no_err_windows=True), 'title', error.handle_fatal_exc(e, Args(no_err_windows=True), 'title',
pre_text='pre', post_text='post') pre_text='pre', post_text='post')
msgs = [rec.message for rec in caplog.records()]
records = caplog.records()
assert len(records) == 1
expected = [ expected = [
'Handling fatal {} with --no-err-windows!'.format(name), 'Handling fatal {} with --no-err-windows!'.format(name),
'',
'title: title', 'title: title',
'pre_text: pre', 'pre_text: pre',
'post_text: post', 'post_text: post',
'exception text: {}'.format(exc_text), 'exception text: {}'.format(exc_text),
] ]
assert msgs[-5:] == expected assert records[0].msg == '\n'.join(expected)
@pytest.mark.parametrize('pre_text, post_text, expected', [ @pytest.mark.parametrize('pre_text, post_text, expected', [