# Buggy code
def run(self):
    self.mode.common.log("OnionThread", "run")

    try:
        self.mode.app.start_onion_service()
        self.success.emit()

    except (
        TorTooOld,
        TorErrorInvalidSetting,
        TorErrorAutomatic,
        TorErrorSocketPort,
        TorErrorSocketFile,
        TorErrorMissingPassword,
        TorErrorUnreadableCookieFile,
        TorErrorAuthError,
        TorErrorProtocolError,
        BundledTorTimeout,
        OSError,
    ) as e:
        self.error.emit(e.args[0])
        return

    self.mode.app.stay_open = not self.mode.common.settings.get(
        "close_after_first_download"
    )

    # start onionshare http service in new thread
    self.mode.web_thread = WebThread(self.mode)
    self.mode.web_thread.start()

    # wait for modules in thread to load, preventing a thread-related cx_Freeze crash
    time.sleep(0.2)


# Traceback (TypeError)
user@onionshare:~/git/onionshare$ ./dev_scripts/onionshare-gui --debug
OnionShare 2.0.dev | https://onionshare.org/
[Sep 19 2018 02:14:55 PM] Onion.__init__
[Sep 19 2018 02:14:55 PM] OnionShare.__init__
[Sep 19 2018 02:14:55 PM] OnionShareGui.__init__
[Sep 19 2018 02:14:55 PM] Settings.__init__
[Sep 19 2018 02:14:55 PM] Settings.load
[Sep 19 2018 02:14:55 PM] Settings.load: Trying to load /home/user/.config/onionshare/onionshare.json
[Sep 19 2018 02:14:55 PM] Uploads.__init__
[Sep 19 2018 02:14:56 PM] TorConnectionDialog.__init__
[Sep 19 2018 02:14:56 PM] TorConnectionDialog.start
[Sep 19 2018 02:14:56 PM] TorConnectionThread.__init__
[Sep 19 2018 02:14:56 PM] TorConnectionThread.run
[Sep 19 2018 02:14:56 PM] Onion.connect
[Sep 19 2018 02:14:56 PM] TorConnectionDialog._connected_to_tor
[Sep 19 2018 02:14:56 PM] OnionShareGui.receive_mode_clicked
[Sep 19 2018 02:14:57 PM] Mode.start_server
[Sep 19 2018 02:14:57 PM] Uploads.reset
[Sep 19 2018 02:14:57 PM] OnionShare.set_stealth: stealth=False
[Sep 19 2018 02:14:57 PM] Mode.start_server: Starting an onion thread
[Sep 19 2018 02:14:57 PM] OnionThread.__init__
[Sep 19 2018 02:14:57 PM] OnionThread.run
[Sep 19 2018 02:14:57 PM] OnionShare.start_onion_service
[Sep 19 2018 02:14:57 PM] Onion.start_onion_service
Configuring onion service on port 17610.
Starting ephemeral Tor onion service and awaiting publication
[Sep 19 2018 02:14:57 PM] Onion.start_onion_service: key_type=ED25519-V3
[Sep 19 2018 02:16:06 PM] Settings.save
Settings saved to /home/user/.config/onionshare/onionshare.json
[Sep 19 2018 02:16:06 PM] WebThread.__init__
[Sep 19 2018 02:16:06 PM] WebThread.run
[Sep 19 2018 02:16:06 PM] Web.start: port=17610, stay_open=True, persistent_slug=None
[Sep 19 2018 02:16:06 PM] Web.generate_slug: persistent_slug=None
[Sep 19 2018 02:16:06 PM] Mode.start_server_step2
[Sep 19 2018 02:16:06 PM] Mode.start_server_step3
[Sep 19 2018 02:16:06 PM] Web.generate_slug: built random slug: "carnation-banner"
Traceback (most recent call last):
File "/home/user/git/onionshare/onionshare_gui/server_status.py", line 286, in start_server_finished
self.copy_url()
File "/home/user/git/onionshare/onionshare_gui/server_status.py", line 321, in copy_url
clipboard.setText(self.get_url())
File "/home/user/git/onionshare/onionshare_gui/server_status.py", line 341, in get_url
url = 'http://{0:s}/{1:s}'.format(self.app.onion_host, self.web.slug)
TypeError: unsupported format string passed to NoneType.__format__
Aborted

# Fixed code
def run(self):
    self.mode.common.log("OnionThread", "run")

    self.mode.app.stay_open = not self.mode.common.settings.get(
        "close_after_first_download"
    )

    # start onionshare http service in new thread
    self.mode.web_thread = WebThread(self.mode)
    self.mode.web_thread.start()

    # wait for modules in thread to load, preventing a thread-related cx_Freeze crash
    time.sleep(0.2)

    try:
        self.mode.app.start_onion_service()
        self.success.emit()

    except (
        TorTooOld,
        TorErrorInvalidSetting,
        TorErrorAutomatic,
        TorErrorSocketPort,
        TorErrorSocketFile,
        TorErrorMissingPassword,
        TorErrorUnreadableCookieFile,
        TorErrorAuthError,
        TorErrorProtocolError,
        BundledTorTimeout,
        OSError,
    ) as e:
        self.error.emit(e.args[0])
        return