From b704c911ae2a90ce47f039a8bafaaac4854df192 Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Sun, 15 May 2016 11:33:30 +0200 Subject: [PATCH] Fix running qute:log and qute:plainlog This failed because dict.get('level') returned None with no level parameter, and the subsequent [0] raised: Traceback (most recent call last): File ".../qutebrowser/utils/utils.py", line 624, in wrapper return func(*args, **kwargs) File ".../qutebrowser/browser/network/networkmanager.py", line 445, in createRequest op, req, outgoing_data) File ".../qutebrowser/browser/network/qutescheme.py", line 107, in createRequest data = handler(self._win_id, request) File ".../qutebrowser/browser/network/qutescheme.py", line 189, in qute_log level = urllib.parse.parse_qs(request.url().query()).get('level')[0] TypeError: 'NoneType' object is not subscriptable --- qutebrowser/browser/network/qutescheme.py | 10 ++++++++-- tests/integration/features/misc.feature | 8 ++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/qutebrowser/browser/network/qutescheme.py b/qutebrowser/browser/network/qutescheme.py index 5da16a845..bf653ec6e 100644 --- a/qutebrowser/browser/network/qutescheme.py +++ b/qutebrowser/browser/network/qutescheme.py @@ -169,7 +169,10 @@ def qute_plainlog(_win_id, request): if log.ram_handler is None: text = "Log output was disabled." else: - level = urllib.parse.parse_qs(request.url().query()).get('level')[0] + try: + level = urllib.parse.parse_qs(request.url().query())['level'][0] + except KeyError: + level = 'vdebug' text = log.ram_handler.dump_log(html=False, level=level) html = jinja.render('pre.html', title='log', content=text) return html.encode('UTF-8', errors='xmlcharrefreplace') @@ -186,7 +189,10 @@ def qute_log(_win_id, request): if log.ram_handler is None: html_log = None else: - level = urllib.parse.parse_qs(request.url().query()).get('level')[0] + try: + level = urllib.parse.parse_qs(request.url().query())['level'][0] + except KeyError: + level = 'vdebug' html_log = log.ram_handler.dump_log(html=True, level=level) html = jinja.render('log.html', title='log', content=html_log) diff --git a/tests/integration/features/misc.feature b/tests/integration/features/misc.feature index 5ffa1274c..d9376fd96 100644 --- a/tests/integration/features/misc.feature +++ b/tests/integration/features/misc.feature @@ -418,3 +418,11 @@ Feature: Various utility commands. Scenario: Showing messages of an invalid level When I run :messages cataclysmic Then the error "Invalid log level cataclysmic!" should be shown + + Scenario: Using qute:log directly + When I open qute:log + Then no crash should happen + + Scenario: Using qute:plainlog directly + When I open qute:plainlog + Then no crash should happen