From 21a50cf9619423d8104c198b4636e1c548f7d248 Mon Sep 17 00:00:00 2001 From: George Edward Bulmer Date: Sun, 11 Feb 2018 17:46:09 +0000 Subject: [PATCH 1/8] Use the repr() of the exception instead of str() --- qutebrowser/config/configexc.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qutebrowser/config/configexc.py b/qutebrowser/config/configexc.py index 0a4986efa..b7df1eceb 100644 --- a/qutebrowser/config/configexc.py +++ b/qutebrowser/config/configexc.py @@ -92,7 +92,7 @@ class ConfigErrorDesc: traceback = attr.ib(None) def __str__(self): - return '{}: {}'.format(self.text, self.exception) + return '{}: {} '.format(self.text, repr(self.exception)) def with_text(self, text): """Get a new ConfigErrorDesc with the given text appended.""" From 72103ec73022b81b12923425a42e705f9f3ddadb Mon Sep 17 00:00:00 2001 From: George Edward Bulmer Date: Sun, 11 Feb 2018 23:16:04 +0000 Subject: [PATCH 2/8] Format error type in a different way --- qutebrowser/config/configexc.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/qutebrowser/config/configexc.py b/qutebrowser/config/configexc.py index b7df1eceb..1444f79ab 100644 --- a/qutebrowser/config/configexc.py +++ b/qutebrowser/config/configexc.py @@ -92,7 +92,8 @@ class ConfigErrorDesc: traceback = attr.ib(None) def __str__(self): - return '{}: {} '.format(self.text, repr(self.exception)) + return '{} - {}: {} '.format(self.text, + self.exception.__class__.__name__, self.exception) def with_text(self, text): """Get a new ConfigErrorDesc with the given text appended.""" From 164b2a3eef9b06ccfd150eb3d29369d0bff30151 Mon Sep 17 00:00:00 2001 From: George Edward Bulmer Date: Sun, 11 Feb 2018 23:20:24 +0000 Subject: [PATCH 3/8] Fix a lengthy line --- qutebrowser/config/configexc.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/qutebrowser/config/configexc.py b/qutebrowser/config/configexc.py index 1444f79ab..7be1ccf2a 100644 --- a/qutebrowser/config/configexc.py +++ b/qutebrowser/config/configexc.py @@ -93,7 +93,8 @@ class ConfigErrorDesc: def __str__(self): return '{} - {}: {} '.format(self.text, - self.exception.__class__.__name__, self.exception) + self.exception.__class__.__name__, + self.exception) def with_text(self, text): """Get a new ConfigErrorDesc with the given text appended.""" From ce8b457baca6a6bc92eceeecd17e1932c896ee98 Mon Sep 17 00:00:00 2001 From: George Edward Bulmer Date: Mon, 12 Feb 2018 13:43:22 +0000 Subject: [PATCH 4/8] Only display exception type if no traceback Update test to match --- qutebrowser/config/configexc.py | 8 +++++--- tests/unit/config/test_configexc.py | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/qutebrowser/config/configexc.py b/qutebrowser/config/configexc.py index 7be1ccf2a..c85aa2220 100644 --- a/qutebrowser/config/configexc.py +++ b/qutebrowser/config/configexc.py @@ -92,9 +92,11 @@ class ConfigErrorDesc: traceback = attr.ib(None) def __str__(self): - return '{} - {}: {} '.format(self.text, - self.exception.__class__.__name__, - self.exception) + if self.traceback: + return '{} - {}: {} '.format(self.text, + self.exception.__class__.__name__, + self.exception) + return '{}: {}'.format(self.text, self.exception) def with_text(self, text): """Get a new ConfigErrorDesc with the given text appended.""" diff --git a/tests/unit/config/test_configexc.py b/tests/unit/config/test_configexc.py index f415ed2fb..2f2ce435f 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 ', ] From b59a7cdcc0e0b7f961867a0d705aaa1c9b22f4c2 Mon Sep 17 00:00:00 2001 From: George Edward Bulmer Date: Mon, 12 Feb 2018 14:07:05 +0000 Subject: [PATCH 5/8] Report syntax errors as unhandled exceptions Update tests accordingly --- qutebrowser/config/configfiles.py | 2 +- tests/unit/config/test_configfiles.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) 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_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 From 5b718446b615c18d9f9274cc0317ff609245adce Mon Sep 17 00:00:00 2001 From: George Edward Bulmer Date: Mon, 12 Feb 2018 14:19:18 +0000 Subject: [PATCH 6/8] Add test for sourcing config with invalid source --- tests/unit/config/test_configcommands.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tests/unit/config/test_configcommands.py b/tests/unit/config/test_configcommands.py index c82195906..e1855349f 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: From 561e5d17b9450dec7a7b07de071f723f6d3610cc Mon Sep 17 00:00:00 2001 From: George Edward Bulmer Date: Mon, 12 Feb 2018 14:22:25 +0000 Subject: [PATCH 7/8] Remove extraneous space --- qutebrowser/config/configexc.py | 2 +- tests/unit/config/test_configcommands.py | 2 +- tests/unit/config/test_configexc.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/qutebrowser/config/configexc.py b/qutebrowser/config/configexc.py index c85aa2220..2c0e5a58f 100644 --- a/qutebrowser/config/configexc.py +++ b/qutebrowser/config/configexc.py @@ -93,7 +93,7 @@ class ConfigErrorDesc: def __str__(self): if self.traceback: - return '{} - {}: {} '.format(self.text, + return '{} - {}: {}'.format(self.text, self.exception.__class__.__name__, self.exception) return '{}: {}'.format(self.text, self.exception) diff --git a/tests/unit/config/test_configcommands.py b/tests/unit/config/test_configcommands.py index e1855349f..13b2ae943 100644 --- a/tests/unit/config/test_configcommands.py +++ b/tests/unit/config/test_configcommands.py @@ -318,7 +318,7 @@ class TestSource: expected = ("Errors occurred while reading config.py:\n" " Unhandled exception - ZeroDivisionError:" - " division by zero ") + " division by zero") assert str(excinfo.value) == expected diff --git a/tests/unit/config/test_configexc.py b/tests/unit/config/test_configexc.py index 2f2ce435f..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: Exception 2 ', + ' Error text 2 - Exception: Exception 2', ] From 9397cc74c1cd175d6a0ff08384290d8235fde050 Mon Sep 17 00:00:00 2001 From: George Edward Bulmer Date: Mon, 12 Feb 2018 14:24:53 +0000 Subject: [PATCH 8/8] Pylint indentation fix --- qutebrowser/config/configexc.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/qutebrowser/config/configexc.py b/qutebrowser/config/configexc.py index 2c0e5a58f..2067878b9 100644 --- a/qutebrowser/config/configexc.py +++ b/qutebrowser/config/configexc.py @@ -94,8 +94,8 @@ class ConfigErrorDesc: def __str__(self): if self.traceback: return '{} - {}: {}'.format(self.text, - self.exception.__class__.__name__, - self.exception) + self.exception.__class__.__name__, + self.exception) return '{}: {}'.format(self.text, self.exception) def with_text(self, text):