# Buggy code
def handle(self, e, *, dry_run=False):
    """Handle a new keypress.

    Separate the keypress into count/command, then check if it matches
    any possible command, and either run the command, ignore it, or
    display an error.

    Args:
        e: the KeyPressEvent from Qt.
        dry_run: Don't actually execute anything, only check whether there
                 would be a match.

    Return:
        A QKeySequence match.
    """
    key = e.key()
    txt = str(keyutils.KeyInfo.from_event(e))
    self._debug_log(
        "Got key: 0x{:x} / modifiers: 0x{:x} / text: '{}' / dry_run {}".format(
            key, int(e.modifiers()), txt, dry_run
        )
    )

    if keyutils.is_modifier_key(key):
        self._debug_log("Ignoring, only modifier")
        return QKeySequence.NoMatch

    try:
        sequence = self._sequence.append_event(e)
    except keyutils.KeyParseError as ex:
        self._debug_log("{} Aborting keychain.".format(ex))
        self.clear_keystring()
        return QKeySequence.NoMatch

    # First, try a straightforward match
    match, binding = self._match_key(sequence)

    # If that doesn't match, try a key_mapping
    if match == QKeySequence.NoMatch:
        mapped = sequence.with_mappings(config.val.bindings.key_mappings)
        if sequence != mapped:
            self._debug_log("Mapped {} -> {}".format(sequence, mapped))
            match, binding = self._match_key(mapped)
            sequence = mapped

    # If that doesn't match either, try treating it as count.
    if (
        match == QKeySequence.NoMatch
        and txt.isdigit()
        and self._supports_count
        and not (not self._count and txt == "0")
    ):
        assert len(txt) == 1, txt
        if not dry_run:
            self._count += txt
            self.keystring_updated.emit(self._count + str(self._sequence))
        return QKeySequence.ExactMatch

    if dry_run:
        return match

    self._sequence = sequence

    if match == QKeySequence.ExactMatch:
        self._debug_log("Definitive match for '{}'.".format(sequence))
        count = int(self._count) if self._count else None
        self.clear_keystring()
        self.execute(binding, count)
    elif match == QKeySequence.PartialMatch:
        self._debug_log("No match for '{}' (added {})".format(sequence, txt))
        self.keystring_updated.emit(self._count + str(sequence))
    elif match == QKeySequence.NoMatch:
        self._debug_log("Giving up with '{}', no matches".format(sequence))
        self.clear_keystring()
    else:
        raise utils.Unreachable("Invalid match value {!r}".format(match))

    return match


# Traceback (ValueError)
16:39:44 DEBUG    init       app:_init_modules:468 Initializing websettings...
16:39:45 ERROR    misc       crashsignal:exception_hook:216 Uncaught exception
Traceback (most recent call last):
File "/bin/qutebrowser", line 11, in <module>
load_entry_point('qutebrowser==1.1.1', 'gui_scripts', 'qutebrowser')()
File "/usr/lib/python3.6/site-packages/qutebrowser/qutebrowser.py", line 188, in main
return app.run(args)
File "/usr/lib/python3.6/site-packages/qutebrowser/app.py", line 137, in run
init(args, crash_handler)
File "/usr/lib/python3.6/site-packages/qutebrowser/app.py", line 163, in init
_init_modules(args, crash_handler)
File "/usr/lib/python3.6/site-packages/qutebrowser/app.py", line 469, in _init_modules
websettings.init(args)
File "/usr/lib/python3.6/site-packages/qutebrowser/config/websettings.py", line 215, in init
webenginesettings.init(args)
File "/usr/lib/python3.6/site-packages/qutebrowser/browser/webengine/webenginesettings.py", line 297, in init
websettings.init_mappings(MAPPINGS)
File "/usr/lib/python3.6/site-packages/qutebrowser/config/websettings.py", line 198, in init_mappings
mapping.set(value)
File "/usr/lib/python3.6/site-packages/qutebrowser/config/websettings.py", line 72, in set
self._set(value, settings=settings)
File "/usr/lib/python3.6/site-packages/qutebrowser/browser/webengine/webenginesettings.py", line 154, in _set
filenames = [self._find_installed(code) for code in value]
File "/usr/lib/python3.6/site-packages/qutebrowser/browser/webengine/webenginesettings.py", line 154, in <listcomp>
filenames = [self._find_installed(code) for code in value]
File "/usr/lib/python3.6/site-packages/qutebrowser/browser/webengine/webenginesettings.py", line 143, in _find_installed
local_filename = spell.local_filename(code)
File "/usr/lib/python3.6/site-packages/qutebrowser/browser/webengine/spell.py", line 64, in local_filename
all_installed = local_files(code)
File "/usr/lib/python3.6/site-packages/qutebrowser/browser/webengine/spell.py", line 51, in local_files
for matching_dict in sorted(matching_dicts, key=version, reverse=True):
File "/usr/lib/python3.6/site-packages/qutebrowser/browser/webengine/spell.py", line 36, in version
.format(filename))
ValueError: the given dictionary file name is malformed: /usr/share/qt/qtwebengine_dictionaries/en-US.bdic

# Fixed code
def handle(self, e, *, dry_run=False):
    """Handle a new keypress.

    Separate the keypress into count/command, then check if it matches
    any possible command, and either run the command, ignore it, or
    display an error.

    Args:
        e: the KeyPressEvent from Qt.
        dry_run: Don't actually execute anything, only check whether there
                 would be a match.

    Return:
        A QKeySequence match.
    """
    key = e.key()
    txt = str(keyutils.KeyInfo.from_event(e))
    self._debug_log(
        "Got key: 0x{:x} / modifiers: 0x{:x} / text: '{}' / dry_run {}".format(
            key, int(e.modifiers()), txt, dry_run
        )
    )

    if keyutils.is_modifier_key(key):
        self._debug_log("Ignoring, only modifier")
        return QKeySequence.NoMatch

    try:
        sequence = self._sequence.append_event(e)
    except keyutils.KeyParseError as ex:
        self._debug_log("{} Aborting keychain.".format(ex))
        self.clear_keystring()
        return QKeySequence.NoMatch

    match, binding = self._match_key(sequence)
    if match == QKeySequence.NoMatch:
        match, binding, sequence = self._match_without_modifiers(sequence)
    if match == QKeySequence.NoMatch:
        match, binding, sequence = self._match_key_mapping(sequence)
    if match == QKeySequence.NoMatch:
        was_count = self._match_count(sequence, dry_run)
        if was_count:
            return QKeySequence.ExactMatch

    if dry_run:
        return match

    self._sequence = sequence

    if match == QKeySequence.ExactMatch:
        self._debug_log("Definitive match for '{}'.".format(sequence))
        count = int(self._count) if self._count else None
        self.clear_keystring()
        self.execute(binding, count)
    elif match == QKeySequence.PartialMatch:
        self._debug_log("No match for '{}' (added {})".format(sequence, txt))
        self.keystring_updated.emit(self._count + str(sequence))
    elif match == QKeySequence.NoMatch:
        self._debug_log("Giving up with '{}', no matches".format(sequence))
        self.clear_keystring()
    else:
        raise utils.Unreachable("Invalid match value {!r}".format(match))

    return match