diff --git a/qutebrowser/config/configexc.py b/qutebrowser/config/configexc.py index 0a4986efa..2067878b9 100644 --- a/qutebrowser/config/configexc.py +++ b/qutebrowser/config/configexc.py @@ -92,6 +92,10 @@ class ConfigErrorDesc: traceback = attr.ib(None) def __str__(self): + if self.traceback: + return '{} - {}: {}'.format(self.text, + self.exception.__class__.__name__, + self.exception) return '{}: {}'.format(self.text, self.exception) def with_text(self, text): diff --git a/qutebrowser/config/configfiles.py b/qutebrowser/config/configfiles.py index 692474075..3dccc129f 100644 --- a/qutebrowser/config/configfiles.py +++ b/qutebrowser/config/configfiles.py @@ -419,7 +419,7 @@ def read_config_py(filename, raising=False): desc = configexc.ConfigErrorDesc("Error while compiling", e) raise configexc.ConfigFileErrors(basename, [desc]) except SyntaxError as e: - desc = configexc.ConfigErrorDesc("Syntax Error", e, + desc = configexc.ConfigErrorDesc("Unhandled exception", e, traceback=traceback.format_exc()) raise configexc.ConfigFileErrors(basename, [desc]) diff --git a/tests/unit/config/test_configcommands.py b/tests/unit/config/test_configcommands.py index c82195906..13b2ae943 100644 --- a/tests/unit/config/test_configcommands.py +++ b/tests/unit/config/test_configcommands.py @@ -309,6 +309,18 @@ class TestSource: " While setting 'foo': No option 'foo'") assert str(excinfo.value) == expected + def test_invalid_source(self, commands, config_tmpdir): + pyfile = config_tmpdir / 'config.py' + pyfile.write_text('1/0', encoding='utf-8') + + with pytest.raises(cmdexc.CommandError) as excinfo: + commands.config_source() + + expected = ("Errors occurred while reading config.py:\n" + " Unhandled exception - ZeroDivisionError:" + " division by zero") + assert str(excinfo.value) == expected + class TestEdit: diff --git a/tests/unit/config/test_configexc.py b/tests/unit/config/test_configexc.py index f415ed2fb..87f3abb6a 100644 --- a/tests/unit/config/test_configexc.py +++ b/tests/unit/config/test_configexc.py @@ -74,7 +74,7 @@ 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', + ' Error text 2 - Exception: Exception 2', ] diff --git a/tests/unit/config/test_configfiles.py b/tests/unit/config/test_configfiles.py index 341fad689..06633ffc7 100644 --- a/tests/unit/config/test_configfiles.py +++ b/tests/unit/config/test_configfiles.py @@ -550,7 +550,7 @@ class TestConfigPy: assert len(excinfo.value.errors) == 1 error = excinfo.value.errors[0] assert isinstance(error.exception, SyntaxError) - assert error.text == "Syntax Error" + assert error.text == "Unhandled exception" exception_text = 'invalid syntax (config.py, line 1)' assert str(error.exception) == exception_text