From 200e439a3051326d0c6a1191f89628aded094f40 Mon Sep 17 00:00:00 2001 From: Martin Tournoij Date: Mon, 3 Apr 2017 02:29:38 +0100 Subject: [PATCH] Fix crash of :debug-log-filter when --filter wasn't given There was no `LogFilter`. The fix is to always initialize a `LogFilter()` with `None`. as the "filter". Fixes #2303. --- CHANGELOG.asciidoc | 1 + qutebrowser/misc/utilcmds.py | 9 ++++++--- qutebrowser/utils/log.py | 5 +++-- tests/end2end/features/utilcmds.feature | 4 ++++ 4 files changed, 14 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc index 5f51fe822..74bf9e661 100644 --- a/CHANGELOG.asciidoc +++ b/CHANGELOG.asciidoc @@ -52,6 +52,7 @@ Fixed - Crash when pressing ctrl-c while a config error is shown - Crash when the key config isn't writable - Crash when unbinding an unbound key in the key config +- Crash when using `:debug-log-filter` when `--filter` wasn't given on startup. - Various rare crashes v0.10.1 diff --git a/qutebrowser/misc/utilcmds.py b/qutebrowser/misc/utilcmds.py index e617c1af2..1998e8341 100644 --- a/qutebrowser/misc/utilcmds.py +++ b/qutebrowser/misc/utilcmds.py @@ -295,13 +295,16 @@ def debug_log_filter(filters: str): Args: filters: A comma separated list of logger names. """ - if set(filters.split(',')).issubset(log.LOGGER_NAMES): - log.console_filter.names = filters.split(',') - else: + if not set(filters.split(',')).issubset(log.LOGGER_NAMES): raise cmdexc.CommandError("filters: Invalid value {} - expected one " "of: {}".format(filters, ', '.join(log.LOGGER_NAMES))) + if log.console_filter is None: + raise cmdexc.CommandError("No log.console_filter. Not attached " + "to a console?") + log.console_filter.names = filters.split(',') + @cmdutils.register() @cmdutils.argument('current_win_id', win_id=True) diff --git a/qutebrowser/utils/log.py b/qutebrowser/utils/log.py index 7c96d4072..9c660f035 100644 --- a/qutebrowser/utils/log.py +++ b/qutebrowser/utils/log.py @@ -182,9 +182,10 @@ def init_log(args): root = logging.getLogger() global console_filter if console is not None: + console_filter = LogFilter(None) if args.logfilter is not None: - console_filter = LogFilter(args.logfilter.split(',')) - console.addFilter(console_filter) + console_filter.names = args.logfilter.split(',') + console.addFilter(console_filter) root.addHandler(console) if ram is not None: root.addHandler(ram) diff --git a/tests/end2end/features/utilcmds.feature b/tests/end2end/features/utilcmds.feature index f9c43be98..aee57e053 100644 --- a/tests/end2end/features/utilcmds.feature +++ b/tests/end2end/features/utilcmds.feature @@ -164,3 +164,7 @@ Feature: Miscellaneous utility commands exposed to the user. Scenario: Using debug-log-filter with invalid filter When I run :debug-log-filter blah Then the error "filters: Invalid value blah - expected one of: statusbar, *" should be shown + + Scenario: Using debug-log-filter + When I run :debug-log-filter webview + Then no crash should happen