# Buggy code
def check_mining_directory(self):
    # Check that credit mining directory exists, if not try to re-create it.
    if not os.path.exists(self.settings.save_path):
        try:
            os.makedirs(self.settings.save_path)
            error_message = (
                "Credit mining directory [%s]  does not exist. Tribler will re-create the "
                "directory and resume again.<br/>If you wish to disable credit mining entirely, "
                "please go to Settings >> ANONYMITY >> Token mining. "
                % self.settings.save_path.encode("utf-8")
            )
        except OSError:
            self.shutdown()
            error_message = (
                "Credit mining directory [%s] was deleted or does not exist and Tribler could not "
                "re-create the directory again. Credit mining will shutdown. Try restarting "
                "Tribler. <br/>If you wish to disable credit mining entirely, please go to "
                "Settings >> ANONYMITY >> Token mining. "
                % self.settings.save_path.encode("utf-8")
            )

        gui_message = {"message": error_message}
        self.session.notifier.notify(NTFY_CREDIT_MINING, NTFY_ERROR, None, gui_message)
        return False
    return True


# Traceback (RuntimeError)
Traceback (most recent call last):
File "TriblerGUI\core_manager.py", line 118, in on_received_state
RuntimeError: [Failure instance: Traceback: <type 'exceptions.ValueError'>: The filename, directory name, or volume label syntax is incorrect
run_tribler.py:85:start_tribler
Tribler\Core\Session.py:432:start
lib\site-packages\twisted\internet\defer.py:321:addCallback
lib\site-packages\twisted\internet\defer.py:310:addCallbacks
--- <exception caught here> ---
lib\site-packages\twisted\internet\defer.py:653:_runCallbacks
Tribler\Core\Session.py:429:load_checkpoint
Tribler\Core\Session.py:384:load_checkpoint
Tribler\Core\APIImplementation\LaunchManyCore.py:570:load_checkpoint
Tribler\Core\APIImplementation\LaunchManyCore.py:567:do_load_checkpoint
Tribler\Core\APIImplementation\LaunchManyCore.py:599:resume_download
Tribler\Core\TorrentDef.py:115:load_from_dict
Tribler\Core\TorrentDef.py:68:__init__
]

# Fixed code
def check_mining_directory(self):
    # Check that credit mining directory exists, if not try to re-create it.
    if not os.path.exists(self.settings.save_path):
        try:
            os.makedirs(self.settings.save_path)
            error_message = (
                "Credit mining directory [%s]  does not exist. Tribler will re-create the "
                "directory and resume again.<br/>If you wish to disable credit mining entirely, "
                "please go to Settings >> ANONYMITY >> Token mining. "
                % ensure_unicode(self.settings.save_path, "utf-8")
            )
        except OSError:
            self.shutdown()
            error_message = (
                "Credit mining directory [%s] was deleted or does not exist and Tribler could not "
                "re-create the directory again. Credit mining will shutdown. Try restarting "
                "Tribler. <br/>If you wish to disable credit mining entirely, please go to "
                "Settings >> ANONYMITY >> Token mining. "
                % self.settings.save_path.encode("utf-8")
            )

        gui_message = {"message": error_message}
        self.session.notifier.notify(NTFY_CREDIT_MINING, NTFY_ERROR, None, gui_message)
        return False
    return True