Log error information when config init fails
This commit is contained in:
parent
884f73f349
commit
e4d05e3fec
@ -665,6 +665,7 @@ def init(parent=None):
|
|||||||
if config_api.errors:
|
if config_api.errors:
|
||||||
raise configexc.ConfigFileErrors('config.py', config_api.errors)
|
raise configexc.ConfigFileErrors('config.py', config_api.errors)
|
||||||
except configexc.ConfigFileErrors as e:
|
except configexc.ConfigFileErrors as e:
|
||||||
|
log.config.exception("Error while loading config.py")
|
||||||
errbox = msgbox.msgbox(parent=None,
|
errbox = msgbox.msgbox(parent=None,
|
||||||
title="Error while reading config",
|
title="Error while reading config",
|
||||||
text=e.to_html(),
|
text=e.to_html(),
|
||||||
@ -682,6 +683,7 @@ def init(parent=None):
|
|||||||
desc = configexc.ConfigErrorDesc("Error", e)
|
desc = configexc.ConfigErrorDesc("Error", e)
|
||||||
raise configexc.ConfigFileErrors('autoconfig.yml', [desc])
|
raise configexc.ConfigFileErrors('autoconfig.yml', [desc])
|
||||||
except configexc.ConfigFileErrors as e:
|
except configexc.ConfigFileErrors as e:
|
||||||
|
log.config.exception("Error while loading autoconfig.yml")
|
||||||
errbox = msgbox.msgbox(parent=None,
|
errbox = msgbox.msgbox(parent=None,
|
||||||
title="Error while reading config",
|
title="Error while reading config",
|
||||||
text=e.to_html(),
|
text=e.to_html(),
|
||||||
|
@ -19,6 +19,8 @@
|
|||||||
|
|
||||||
"""Exceptions related to config parsing."""
|
"""Exceptions related to config parsing."""
|
||||||
|
|
||||||
|
from qutebrowser.utils import utils
|
||||||
|
|
||||||
|
|
||||||
class Error(Exception):
|
class Error(Exception):
|
||||||
|
|
||||||
@ -87,13 +89,20 @@ class ConfigErrorDesc:
|
|||||||
self.exception = exception
|
self.exception = exception
|
||||||
self.traceback = traceback
|
self.traceback = traceback
|
||||||
|
|
||||||
|
def __repr__(self):
|
||||||
|
return utils.get_repr(self, text=self.text, exception=self.exception)
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return '{}: {}'.format(self.text, self.exception)
|
||||||
|
|
||||||
|
|
||||||
class ConfigFileErrors(Error):
|
class ConfigFileErrors(Error):
|
||||||
|
|
||||||
"""Raised when multiple errors occurred inside the config."""
|
"""Raised when multiple errors occurred inside the config."""
|
||||||
|
|
||||||
def __init__(self, basename, errors):
|
def __init__(self, basename, errors):
|
||||||
super().__init__("Errors occurred while reading {}".format(basename))
|
super().__init__("Errors occurred while reading {}:\n{}".format(
|
||||||
|
basename, '\n'.join(' {}'.format(e) for e in errors)))
|
||||||
self.basename = basename
|
self.basename = basename
|
||||||
self.errors = errors
|
self.errors = errors
|
||||||
|
|
||||||
|
@ -20,6 +20,7 @@
|
|||||||
|
|
||||||
import copy
|
import copy
|
||||||
import types
|
import types
|
||||||
|
import logging
|
||||||
import unittest.mock
|
import unittest.mock
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
@ -884,7 +885,7 @@ def init_patch(qapp, fake_save_manager, monkeypatch, config_tmpdir,
|
|||||||
@pytest.mark.parametrize('config_py', [True, 'error', False])
|
@pytest.mark.parametrize('config_py', [True, 'error', False])
|
||||||
@pytest.mark.parametrize('invalid_yaml', ['42', 'unknown', False])
|
@pytest.mark.parametrize('invalid_yaml', ['42', 'unknown', False])
|
||||||
# pylint: disable=too-many-branches
|
# pylint: disable=too-many-branches
|
||||||
def test_init(init_patch, fake_save_manager, config_tmpdir, mocker,
|
def test_init(init_patch, fake_save_manager, config_tmpdir, mocker, caplog,
|
||||||
load_autoconfig, config_py, invalid_yaml):
|
load_autoconfig, config_py, invalid_yaml):
|
||||||
# Prepare files
|
# Prepare files
|
||||||
autoconfig_file = config_tmpdir / 'autoconfig.yml'
|
autoconfig_file = config_tmpdir / 'autoconfig.yml'
|
||||||
@ -912,7 +913,8 @@ def test_init(init_patch, fake_save_manager, config_tmpdir, mocker,
|
|||||||
msgbox_mock = mocker.patch('qutebrowser.config.config.msgbox.msgbox',
|
msgbox_mock = mocker.patch('qutebrowser.config.config.msgbox.msgbox',
|
||||||
autospec=True)
|
autospec=True)
|
||||||
|
|
||||||
config.init()
|
with caplog.at_level(logging.ERROR):
|
||||||
|
config.init()
|
||||||
|
|
||||||
# Check error messages
|
# Check error messages
|
||||||
expected_errors = []
|
expected_errors = []
|
||||||
|
@ -20,6 +20,8 @@
|
|||||||
|
|
||||||
import textwrap
|
import textwrap
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
|
||||||
from qutebrowser.config import configexc
|
from qutebrowser.config import configexc
|
||||||
from qutebrowser.utils import usertypes
|
from qutebrowser.utils import usertypes
|
||||||
|
|
||||||
@ -47,11 +49,24 @@ def test_duplicate_key_error():
|
|||||||
assert str(e) == "Duplicate key asdf"
|
assert str(e) == "Duplicate key asdf"
|
||||||
|
|
||||||
|
|
||||||
def test_config_file_errors():
|
@pytest.fixture
|
||||||
|
def errors():
|
||||||
|
"""Get a ConfigFileErrors object."""
|
||||||
err1 = configexc.ConfigErrorDesc("Error text 1", Exception("Exception 1"))
|
err1 = configexc.ConfigErrorDesc("Error text 1", Exception("Exception 1"))
|
||||||
err2 = configexc.ConfigErrorDesc("Error text 2", Exception("Exception 2"),
|
err2 = configexc.ConfigErrorDesc("Error text 2", Exception("Exception 2"),
|
||||||
"Fake traceback")
|
"Fake traceback")
|
||||||
errors = configexc.ConfigFileErrors("config.py", [err1, err2])
|
return configexc.ConfigFileErrors("config.py", [err1, err2])
|
||||||
|
|
||||||
|
|
||||||
|
def test_config_file_errors_str(errors):
|
||||||
|
assert str(errors).splitlines() == [
|
||||||
|
'Errors occurred while reading config.py:',
|
||||||
|
' Error text 1: Exception 1',
|
||||||
|
' Error text 2: Exception 2',
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
def test_config_file_errors_html(errors):
|
||||||
html = errors.to_html()
|
html = errors.to_html()
|
||||||
assert textwrap.dedent(html) == textwrap.dedent("""
|
assert textwrap.dedent(html) == textwrap.dedent("""
|
||||||
Errors occurred while reading config.py:
|
Errors occurred while reading config.py:
|
||||||
|
Loading…
Reference in New Issue
Block a user