# Buggy code
def set_repository(
    self, repository, relative_install_dir=None, changeset_revision=None
):
    self.repository = repository
    # Shed related tool panel configs are only relevant to Galaxy.
    if self.app.name == "galaxy":
        if relative_install_dir is None and self.repository is not None:
            tool_path, relative_install_dir = self.repository.get_tool_relative_path(
                self.app
            )
        if changeset_revision is None and self.repository is not None:
            self.set_changeset_revision(self.repository.changeset_revision)
        else:
            self.set_changeset_revision(changeset_revision)
        self.shed_config_dict = repository.get_shed_config_dict(self.app, {})
        self.metadata_dict = {
            "shed_config_filename": self.shed_config_dict.get("config_filename", None)
        }
    else:
        if relative_install_dir is None and self.repository is not None:
            relative_install_dir = repository.repo_path(self.app)
        if changeset_revision is None and self.repository is not None:
            self.set_changeset_revision(self.repository.tip(self.app))
        else:
            self.set_changeset_revision(changeset_revision)
        self.shed_config_dict = {}
        self.metadata_dict = {}
    self.set_relative_install_dir(relative_install_dir)
    self.set_repository_files_dir()
    self.resetting_all_metadata_on_repository = False
    self.updating_installed_repository = False
    self.persist = False
    self.invalid_file_tups = []


# Traceback (ParseError)
Nov 09 13:22:10 sn04.bi.uni-freiburg.de uwsgi[4107748]: [pid: 4124485|app: 0|req: 9911/42155] 88.66.136.83 () {84 vars in 1575 bytes} [Sat Nov  9 13:22:10 2019] POST /admin_toolshed/repository_installation_status_updates => generated 2 bytes in 23 msecs (HTTP/1.1 200) 3 headers in 96 bytes (1 switches on core 0)
Nov 09 13:22:11 sn04.bi.uni-freiburg.de uwsgi[3191341]: galaxy.datatypes.registry DEBUG 2019-11-09 13:22:11,317 [p:119216,w:4,m:0] [Thread-1] Loaded external metadata tool: __SET_METADATA__
Nov 09 13:22:11 sn04.bi.uni-freiburg.de uwsgi[3191341]: galaxy.tools.special_tools DEBUG 2019-11-09 13:22:11,323 [p:119216,w:4,m:0] [Thread-1] Loaded history import tool: __IMPORT_HISTORY__
Nov 09 13:22:11 sn04.bi.uni-freiburg.de uwsgi[3191341]: galaxy.tools.special_tools DEBUG 2019-11-09 13:22:11,327 [p:119216,w:4,m:0] [Thread-1] Loaded data fetch tool: __DATA_FETCH__
Nov 09 13:22:11 sn04.bi.uni-freiburg.de uwsgi[3191341]: galaxy.tools.special_tools DEBUG 2019-11-09 13:22:11,330 [p:119216,w:4,m:0] [Thread-1] Loaded history export tool: __EXPORT_HISTORY__
Nov 09 13:22:11 sn04.bi.uni-freiburg.de uwsgi[3191341]: galaxy.queue_worker INFO 2019-11-09 13:22:11,332 [p:119216,w:4,m:0] [Thread-1] Queuing async task rebuild_toolbox_search_index for main.web.4.
Nov 09 13:22:11 sn04.bi.uni-freiburg.de uwsgi[3191341]: galaxy.queue_worker DEBUG 2019-11-09 13:22:11,336 [p:119216,w:4,m:0] [Thread-1] Toolbox reload (29743.348 ms)
Nov 09 13:22:11 sn04.bi.uni-freiburg.de uwsgi[3191341]: galaxy.queue_worker INFO 2019-11-09 13:22:11,338 [p:119216,w:4,m:0] [Thread-1] Instance 'main.web.4' received 'reload_toolbox' task, executing now.
Nov 09 13:22:11 sn04.bi.uni-freiburg.de uwsgi[3191341]: galaxy.queue_worker DEBUG 2019-11-09 13:22:11,338 [p:119216,w:4,m:0] [Thread-1] Executing toolbox reload on 'main.web.4'
Nov 09 13:22:12 sn04.bi.uni-freiburg.de uwsgi[3843198]: 115.146.92.55 - - [09/Nov/2019:13:22:11 +0200] "GET /api/jobs/4d16a9b9d521c9b3?key=59001665ead9d0bfd82dad0c0253dda0 HTTP/1.1" 200 - "-" "python-requests/2.22.0"
Nov 09 13:22:12 sn04.bi.uni-freiburg.de uwsgi[3843198]: [pid: 3882852|app: 0|req: 11155/55634] 115.146.92.55 () {70 vars in 992 bytes} [Sat Nov  9 13:22:11 2019] GET /api/jobs/4d16a9b9d521c9b3?key=59001665ead9d0bfd82dad0c0253dda0 => generated 1118 bytes in 88 msecs (HTTP/1.1 200) 2 headers in 110 bytes (1 switches on core 0)
Nov 09 13:22:12 sn04.bi.uni-freiburg.de uwsgi[3843198]: galaxy.tools.search DEBUG 2019-11-09 13:22:12,036 [p:228435,w:4,m:0] [Thread-1] Toolbox index finished (29660.792 ms)
Nov 09 13:22:12 sn04.bi.uni-freiburg.de uwsgi[3191341]: galaxy.util ERROR 2019-11-09 13:22:12,537 [p:119216,w:4,m:0] [Thread-1] Error parsing file /opt/galaxy/mutable-config/integrated_tool_panel.xml
Nov 09 13:22:12 sn04.bi.uni-freiburg.de uwsgi[3191341]: Traceback (most recent call last):
Nov 09 13:22:12 sn04.bi.uni-freiburg.de uwsgi[3191341]: File "lib/galaxy/util/__init__.py", line 236, in parse_xml
Nov 09 13:22:12 sn04.bi.uni-freiburg.de uwsgi[3191341]: root = tree.parse(fname, parser=ElementTree.XMLParser(target=DoctypeSafeCallbackTarget()))
Nov 09 13:22:12 sn04.bi.uni-freiburg.de uwsgi[3191341]: File "/usr/lib64/python2.7/xml/etree/ElementTree.py", line 657, in parse
Nov 09 13:22:12 sn04.bi.uni-freiburg.de uwsgi[3191341]: self._root = parser.close()
Nov 09 13:22:12 sn04.bi.uni-freiburg.de uwsgi[3191341]: File "/usr/lib64/python2.7/xml/etree/ElementTree.py", line 1654, in close
Nov 09 13:22:12 sn04.bi.uni-freiburg.de uwsgi[3191341]: self._raiseerror(v)
Nov 09 13:22:12 sn04.bi.uni-freiburg.de uwsgi[3191341]: File "/usr/lib64/python2.7/xml/etree/ElementTree.py", line 1506, in _raiseerror
Nov 09 13:22:12 sn04.bi.uni-freiburg.de uwsgi[3191341]: raise err
Nov 09 13:22:12 sn04.bi.uni-freiburg.de uwsgi[3191341]: ParseError: unclosed token: line 10952, column 8
Nov 09 13:22:12 sn04.bi.uni-freiburg.de uwsgi[3191341]: galaxy.queue_worker ERROR 2019-11-09 13:22:12,538 [p:119216,w:4,m:0] [Thread-1] Error running control task type: reload_toolbox
Nov 09 13:22:12 sn04.bi.uni-freiburg.de uwsgi[3191341]: Traceback (most recent call last):
Nov 09 13:22:12 sn04.bi.uni-freiburg.de uwsgi[3191341]: File "lib/galaxy/queue_worker.py", line 372, in process_task
Nov 09 13:22:12 sn04.bi.uni-freiburg.de uwsgi[3191341]: result = f(self.app, **body['kwargs'])
Nov 09 13:22:12 sn04.bi.uni-freiburg.de uwsgi[3191341]: File "lib/galaxy/queue_worker.py", line 171, in reload_toolbox
Nov 09 13:22:12 sn04.bi.uni-freiburg.de uwsgi[3191341]: _get_new_toolbox(app)
Nov 09 13:22:12 sn04.bi.uni-freiburg.de uwsgi[3191341]: File "lib/galaxy/queue_worker.py", line 188, in _get_new_toolbox
Nov 09 13:22:12 sn04.bi.uni-freiburg.de uwsgi[3191341]: new_toolbox = tools.ToolBox(tool_configs, app.config.tool_path, app)
Nov 09 13:22:12 sn04.bi.uni-freiburg.de uwsgi[3191341]: File "lib/galaxy/tools/__init__.py", line 253, in __init__
Nov 09 13:22:12 sn04.bi.uni-freiburg.de uwsgi[3191341]: app=app,
Nov 09 13:22:12 sn04.bi.uni-freiburg.de uwsgi[3191341]: File "lib/galaxy/tools/toolbox/base.py", line 1163, in __init__
Nov 09 13:22:12 sn04.bi.uni-freiburg.de uwsgi[3191341]: super(BaseGalaxyToolBox, self).__init__(config_filenames, tool_root_dir, app)
Nov 09 13:22:12 sn04.bi.uni-freiburg.de uwsgi[3191341]: File "lib/galaxy/tools/toolbox/base.py", line 100, in __init__
Nov 09 13:22:12 sn04.bi.uni-freiburg.de uwsgi[3191341]: self._init_integrated_tool_panel(app.config)
Nov 09 13:22:12 sn04.bi.uni-freiburg.de uwsgi[3191341]: File "lib/galaxy/tools/toolbox/integrated_panel.py", line 39, in _init_integrated_tool_panel
Nov 09 13:22:12 sn04.bi.uni-freiburg.de uwsgi[3191341]: self._load_integrated_tool_panel_keys()
Nov 09 13:22:12 sn04.bi.uni-freiburg.de uwsgi[3191341]: File "lib/galaxy/tools/toolbox/base.py", line 445, in _load_integrated_tool_panel_keys
Nov 09 13:22:12 sn04.bi.uni-freiburg.de uwsgi[3191341]: tree = parse_xml(self._integrated_tool_panel_config)
Nov 09 13:22:12 sn04.bi.uni-freiburg.de uwsgi[3191341]: File "lib/galaxy/util/__init__.py", line 236, in parse_xml
Nov 09 13:22:12 sn04.bi.uni-freiburg.de uwsgi[3191341]: root = tree.parse(fname, parser=ElementTree.XMLParser(target=DoctypeSafeCallbackTarget()))
Nov 09 13:22:12 sn04.bi.uni-freiburg.de uwsgi[3191341]: File "/usr/lib64/python2.7/xml/etree/ElementTree.py", line 657, in parse
Nov 09 13:22:12 sn04.bi.uni-freiburg.de uwsgi[3191341]: self._root = parser.close()
Nov 09 13:22:12 sn04.bi.uni-freiburg.de uwsgi[3191341]: File "/usr/lib64/python2.7/xml/etree/ElementTree.py", line 1654, in close
Nov 09 13:22:12 sn04.bi.uni-freiburg.de uwsgi[3191341]: self._raiseerror(v)
Nov 09 13:22:12 sn04.bi.uni-freiburg.de uwsgi[3191341]: File "/usr/lib64/python2.7/xml/etree/ElementTree.py", line 1506, in _raiseerror
Nov 09 13:22:12 sn04.bi.uni-freiburg.de uwsgi[3191341]: raise err
Nov 09 13:22:12 sn04.bi.uni-freiburg.de uwsgi[3191341]: ParseError: unclosed token: line 10952, column 8

# Fixed code
def set_repository(
    self, repository, relative_install_dir=None, changeset_revision=None
):
    self.repository = repository
    # Shed related tool panel configs are only relevant to Galaxy.
    if self.app.name == "galaxy":
        if relative_install_dir is None and self.repository is not None:
            tool_path, relative_install_dir = self.repository.get_tool_relative_path(
                self.app
            )
        if changeset_revision is None and self.repository is not None:
            self.set_changeset_revision(self.repository.changeset_revision)
        else:
            self.set_changeset_revision(changeset_revision)
        self.shed_config_dict = repository.get_shed_config_dict(self.app)
        self.metadata_dict = {
            "shed_config_filename": self.shed_config_dict.get("config_filename", None)
        }
    else:
        if relative_install_dir is None and self.repository is not None:
            relative_install_dir = repository.repo_path(self.app)
        if changeset_revision is None and self.repository is not None:
            self.set_changeset_revision(self.repository.tip(self.app))
        else:
            self.set_changeset_revision(changeset_revision)
        self.shed_config_dict = {}
        self.metadata_dict = {}
    self.set_relative_install_dir(relative_install_dir)
    self.set_repository_files_dir()
    self.resetting_all_metadata_on_repository = False
    self.updating_installed_repository = False
    self.persist = False
    self.invalid_file_tups = []