# Buggy code
def parse_tracker_url(tracker_url):
    # get tracker type
    if tracker_url.startswith("http"):
        tracker_type = "HTTP"
    elif tracker_url.startswith("udp"):
        tracker_type = "UDP"
    else:
        raise RuntimeError("Unexpected tracker type.")

    # get URL information
    url_fields = tracker_url.split("://")[1]
    # some UDP trackers may not have 'announce' at the end.
    if url_fields.find("/") == -1:
        if tracker_type == "UDP":
            hostname_part = url_fields
            announce_page = None
        else:
            raise RuntimeError("Invalid tracker URL (%s)." % tracker_url)
    else:
        hostname_part, announce_page = url_fields.split("/", 1)

    # get port number if exists, otherwise, use HTTP default 80
    if hostname_part.find(":") != -1:
        hostname, port = hostname_part.split(":", 1)
        port = int(port)
    elif tracker_type == "HTTP":
        hostname = hostname_part
        port = 80
    else:
        raise RuntimeError("No port number for UDP tracker URL.")

    return tracker_type, (hostname, port), announce_page


# Traceback (RuntimeError)
Traceback (most recent call last):
File "TriblerGUI\core_manager.py", line 128, in on_received_state
RuntimeError: Unhandled Error
Traceback (most recent call last):
File "lib\multiprocessing\process.py", line 114, in run

File "TriblerGUI\core_manager.py", line 61, in start_tribler_core

File "lib\site-packages\twisted\internet\base.py", line 1195, in run

File "lib\site-packages\twisted\internet\base.py", line 1204, in mainLoop

--- <exception caught here> ---
File "lib\site-packages\twisted\internet\base.py", line 825, in runUntilCurrent

File "Tribler\Core\TorrentChecker\torrent_checker.py", line 119, in _task_select_tracker

File "Tribler\Core\TorrentChecker\torrent_checker.py", line 225, in _create_session_for_request

File "Tribler\Core\TorrentChecker\session.py", line 47, in create_tracker_session

File "Tribler\Core\Utilities\tracker_utils.py", line 110, in parse_tracker_url

exceptions.RuntimeError: No port number for UDP tracker URL.

# Fixed code
def parse_tracker_url(tracker_url):
    # get tracker type
    if tracker_url.startswith("http"):
        tracker_type = "HTTP"
    elif tracker_url.startswith("udp"):
        tracker_type = "UDP"
    else:
        raise MalformedTrackerURLException(
            "Unexpected tracker type (%s)." % tracker_url
        )

    # get URL information
    url_fields = tracker_url.split("://")[1]
    # some UDP trackers may not have 'announce' at the end.
    if url_fields.find("/") == -1:
        if tracker_type == "UDP":
            hostname_part = url_fields
            announce_page = None
        else:
            raise MalformedTrackerURLException(
                "Invalid tracker URL (%s)." % tracker_url
            )
    else:
        hostname_part, announce_page = url_fields.split("/", 1)

    # get port number if exists, otherwise, use HTTP default 80
    if hostname_part.find(":") != -1:
        hostname, port = hostname_part.split(":", 1)
        port = int(port)
    elif tracker_type == "HTTP":
        hostname = hostname_part
        port = 80
    else:
        raise MalformedTrackerURLException(
            "No port number for UDP tracker URL (%s)." % tracker_url
        )

    return tracker_type, (hostname, port), announce_page