# Buggy code
def tab_give(self, win_id: int = None):
    """Give the current tab to a new or existing window if win_id given.

    If no win_id is given, the tab will get detached into a new window.

    Args:
        win_id: The window ID of the window to give the current tab to.
    """
    if win_id == self._win_id:
        raise cmdexc.CommandError("Can't give a tab to the same window")

    if win_id is None:
        if self._count() < 2:
            raise cmdexc.CommandError("Cannot detach from a window with only one tab")

        tabbed_browser = self._new_tabbed_browser(private=self._tabbed_browser.private)
    else:
        tabbed_browser = objreg.get("tabbed-browser", scope="window", window=win_id)

    tabbed_browser.tabopen(self._current_url())
    self._tabbed_browser.close_tab(self._current_widget(), add_undo=False)


# Traceback (AttributeError)
23:08:35 DEBUG    commands   command:run:489 command called: tab-give ['1337']
23:08:35 DEBUG    commands   command:run:504 Calling qutebrowser.browser.commands.CommandDispatcher.tab_give(<qutebrowser.browser.commands.CommandDispatcher>, 1337)
23:08:35 ERROR    misc       crashsignal:exception_hook:216 Uncaught exception
Traceback (most recent call last):
File "/home/florian/proj/qutebrowser/git/qutebrowser/utils/objreg.py", line 200, in _get_window_registry
return win.registry
AttributeError: 'NoneType' object has no attribute 'registry'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/home/florian/proj/qutebrowser/git/qutebrowser/commands/runners.py", line 322, in run_safely
self.run(text, count)
File "/home/florian/proj/qutebrowser/git/qutebrowser/commands/runners.py", line 301, in run
result.cmd.run(self._win_id, args, count=count)
File "/home/florian/proj/qutebrowser/git/qutebrowser/commands/command.py", line 505, in run
self.handler(*posargs, **kwargs)
File "/home/florian/proj/qutebrowser/git/qutebrowser/browser/commands.py", line 559, in tab_give
window=win_id)
File "/home/florian/proj/qutebrowser/git/qutebrowser/utils/objreg.py", line 227, in get
reg = _get_registry(scope, window, tab)
File "/home/florian/proj/qutebrowser/git/qutebrowser/utils/objreg.py", line 216, in _get_registry
return _get_window_registry(window)
File "/home/florian/proj/qutebrowser/git/qutebrowser/utils/objreg.py", line 202, in _get_window_registry
raise RegistryUnavailableError('window')

# Fixed code
def tab_give(self, win_id: int = None):
    """Give the current tab to a new or existing window if win_id given.

    If no win_id is given, the tab will get detached into a new window.

    Args:
        win_id: The window ID of the window to give the current tab to.
    """
    if win_id == self._win_id:
        raise cmdexc.CommandError("Can't give a tab to the same window")

    if win_id is None:
        if self._count() < 2:
            raise cmdexc.CommandError("Cannot detach from a window with only one tab")

        tabbed_browser = self._new_tabbed_browser(private=self._tabbed_browser.private)
    else:
        if win_id not in objreg.window_registry:
            raise cmdexc.CommandError("There's no window with id {}!".format(win_id))

        tabbed_browser = objreg.get("tabbed-browser", scope="window", window=win_id)

    tabbed_browser.tabopen(self._current_url())
    self._tabbed_browser.close_tab(self._current_widget(), add_undo=False)