# Buggy code
def _remove_tab(self, tab, *, add_undo=True, new_undo=True, crashed=False):
    """Remove a tab from the tab list and delete it properly.

    Args:
        tab: The QWebView to be closed.
        add_undo: Whether the tab close can be undone.
        new_undo: Whether the undo entry should be a new item in the stack.
        crashed: Whether we're closing a tab with crashed renderer process.
    """
    idx = self.indexOf(tab)
    if idx == -1:
        if crashed:
            return
        raise TabDeletedError("tab {} is not contained in TabbedWidget!".format(tab))
    if tab is self._now_focused:
        self._now_focused = None
    if tab is objreg.get("last-focused-tab", None, scope="window", window=self._win_id):
        objreg.delete("last-focused-tab", scope="window", window=self._win_id)

    if tab.url().isEmpty():
        # There are some good reasons why a URL could be empty
        # (target="_blank" with a download, see [1]), so we silently ignore
        # this.
        # [1] https://github.com/qutebrowser/qutebrowser/issues/163
        pass
    elif not tab.url().isValid():
        # We display a warning for URLs which are not empty but invalid -
        # but we don't return here because we want the tab to close either
        # way.
        urlutils.invalid_url_error(tab.url(), "saving tab")
    elif add_undo:
        try:
            history_data = tab.history.serialize()
        except browsertab.WebTabError:
            pass  # special URL
        else:
            entry = UndoEntry(tab.url(), history_data, idx, tab.data.pinned)
            if new_undo or not self._undo_stack:
                self._undo_stack.append([entry])
            else:
                self._undo_stack[-1].append(entry)

    tab.shutdown()
    self.removeTab(idx)
    if not crashed:
        # WORKAROUND for a segfault when we delete the crashed tab.
        # see https://bugreports.qt.io/browse/QTBUG-58698
        tab.layout().unwrap()
        tab.deleteLater()


# 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 _remove_tab(self, tab, *, add_undo=True, new_undo=True, crashed=False):
    """Remove a tab from the tab list and delete it properly.

    Args:
        tab: The QWebView to be closed.
        add_undo: Whether the tab close can be undone.
        new_undo: Whether the undo entry should be a new item in the stack.
        crashed: Whether we're closing a tab with crashed renderer process.
    """
    idx = self.widget.indexOf(tab)
    if idx == -1:
        if crashed:
            return
        raise TabDeletedError("tab {} is not contained in TabbedWidget!".format(tab))
    if tab is self._now_focused:
        self._now_focused = None
    if tab is objreg.get("last-focused-tab", None, scope="window", window=self._win_id):
        objreg.delete("last-focused-tab", scope="window", window=self._win_id)

    if tab.url().isEmpty():
        # There are some good reasons why a URL could be empty
        # (target="_blank" with a download, see [1]), so we silently ignore
        # this.
        # [1] https://github.com/qutebrowser/qutebrowser/issues/163
        pass
    elif not tab.url().isValid():
        # We display a warning for URLs which are not empty but invalid -
        # but we don't return here because we want the tab to close either
        # way.
        urlutils.invalid_url_error(tab.url(), "saving tab")
    elif add_undo:
        try:
            history_data = tab.history.serialize()
        except browsertab.WebTabError:
            pass  # special URL
        else:
            entry = UndoEntry(tab.url(), history_data, idx, tab.data.pinned)
            if new_undo or not self._undo_stack:
                self._undo_stack.append([entry])
            else:
                self._undo_stack[-1].append(entry)

    tab.shutdown()
    self.widget.removeTab(idx)
    if not crashed:
        # WORKAROUND for a segfault when we delete the crashed tab.
        # see https://bugreports.qt.io/browse/QTBUG-58698
        tab.layout().unwrap()
        tab.deleteLater()