# Buggy code
def resume_download(self, filename, setupDelay=0):
    try:
        pstate = self.load_download_pstate(filename)
        if not pstate:
            return
    except Exception as e:
        self._logger.exception("tlm: could not open checkpoint file %s", str(filename))
        return

    metainfo = pstate.get("state", "metainfo")
    if not metainfo:
        self._logger.error(
            "tlm: could not resume checkpoint %s; metainfo not found", filename
        )
        return

    try:
        tdef = (
            TorrentDefNoMetainfo(
                metainfo["infohash"], metainfo["name"], metainfo.get("url", None)
            )
            if "infohash" in metainfo
            else TorrentDef.load_from_dict(metainfo)
        )
    except ValueError as e:
        self._logger.exception(
            "tlm: could not restore tdef from metainfo dict: %s %s ",
            e,
            text_type(metainfo),
        )
        return

    if pstate.has_option("download_defaults", "saveas") and isinstance(
        pstate.get("download_defaults", "saveas"), tuple
    ):
        pstate.set(
            "download_defaults", "saveas", pstate.get("download_defaults", "saveas")[-1]
        )

    # If save_path is relative, make it global instead

    dscfg = DownloadStartupConfig(pstate, state_dir=self.session.config.get_state_dir())

    self._logger.debug(
        "tlm: load_checkpoint: resumedata %s",
        "len %s "
        % (
            len(pstate.get("state", "engineresumedata"))
            if pstate.get("state", "engineresumedata")
            else "None"
        ),
    )
    if not (tdef and dscfg):
        self._logger.info(
            "tlm: could not resume checkpoint %s %s %s", filename, tdef, dscfg
        )
        return

    if dscfg.get_dest_dir() == "":  # removed torrent ignoring
        self._logger.info(
            "tlm: removing checkpoint %s destdir is %s", filename, dscfg.get_dest_dir()
        )
        os.remove(filename)
        return

    try:
        if self.download_exists(tdef.get_infohash()):
            self._logger.info(
                "tlm: not resuming checkpoint because download has already been added"
            )
        elif (
            dscfg.get_credit_mining()
            and not self.session.config.get_credit_mining_enabled()
        ):
            self._logger.info(
                "tlm: not resuming checkpoint since token mining is disabled"
            )
        else:
            self.add(tdef, dscfg, pstate, setupDelay=setupDelay)
    except Exception as e:
        self._logger.exception(
            "tlm: load check_point: exception while adding download %s", tdef
        )


# Traceback (RuntimeError)
Traceback (most recent call last):
File "TriblerGUI\event_request_manager.py", line 114, in on_read_data
RuntimeError: [Failure instance: Traceback: <type 'exceptions.TypeError'>: string indices must be integers
lib\site-packages\twisted\internet\defer.py:1442:gotResult
lib\site-packages\twisted\internet\defer.py:1389:_inlineCallbacks
lib\site-packages\twisted\internet\defer.py:459:callback
lib\site-packages\twisted\internet\defer.py:567:_startRunCallbacks
--- <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:576:load_checkpoint
Tribler\Core\APIImplementation\LaunchManyCore.py:573:do_load_checkpoint
Tribler\Core\APIImplementation\LaunchManyCore.py:610:resume_download
]

# Fixed code
def resume_download(self, filename, setupDelay=0):
    try:
        pstate = self.load_download_pstate(filename)
        if not pstate:
            return
    except Exception as e:
        self._logger.exception("tlm: could not open checkpoint file %s", str(filename))
        return

    metainfo = pstate.get("state", "metainfo")
    if not metainfo:
        self._logger.error(
            "tlm: could not resume checkpoint %s; metainfo not found", filename
        )
        return
    if not isinstance(metainfo, dict):
        self._logger.error(
            "tlm: could not resume checkpoint %s; metainfo is not dict %s %s",
            filename,
            type(metainfo),
            repr(metainfo),
        )
        return

    try:
        tdef = (
            TorrentDefNoMetainfo(
                metainfo["infohash"], metainfo["name"], metainfo.get("url", None)
            )
            if "infohash" in metainfo
            else TorrentDef.load_from_dict(metainfo)
        )
    except ValueError as e:
        self._logger.exception(
            "tlm: could not restore tdef from metainfo dict: %s %s ",
            e,
            text_type(metainfo),
        )
        return

    if pstate.has_option("download_defaults", "saveas") and isinstance(
        pstate.get("download_defaults", "saveas"), tuple
    ):
        pstate.set(
            "download_defaults", "saveas", pstate.get("download_defaults", "saveas")[-1]
        )

    # If save_path is relative, make it global instead

    dscfg = DownloadStartupConfig(pstate, state_dir=self.session.config.get_state_dir())

    self._logger.debug(
        "tlm: load_checkpoint: resumedata %s",
        "len %s "
        % (
            len(pstate.get("state", "engineresumedata"))
            if pstate.get("state", "engineresumedata")
            else "None"
        ),
    )
    if not (tdef and dscfg):
        self._logger.info(
            "tlm: could not resume checkpoint %s %s %s", filename, tdef, dscfg
        )
        return

    if dscfg.get_dest_dir() == "":  # removed torrent ignoring
        self._logger.info(
            "tlm: removing checkpoint %s destdir is %s", filename, dscfg.get_dest_dir()
        )
        os.remove(filename)
        return

    try:
        if self.download_exists(tdef.get_infohash()):
            self._logger.info(
                "tlm: not resuming checkpoint because download has already been added"
            )
        elif (
            dscfg.get_credit_mining()
            and not self.session.config.get_credit_mining_enabled()
        ):
            self._logger.info(
                "tlm: not resuming checkpoint since token mining is disabled"
            )
        else:
            self.add(tdef, dscfg, pstate, setupDelay=setupDelay)
    except Exception as e:
        self._logger.exception(
            "tlm: load check_point: exception while adding download %s", tdef
        )