# Buggy code
def unhandled_error_observer(self, event):
    """
    This method is called when an unhandled error in Tribler is observed. Broadcasts the tribler_exception event.
    """
    if event["isError"]:
        text = ""
        if "log_legacy" in event and "log_text" in event:
            text = event["log_text"]
        elif "log_failure" in event:
            text = str(event["log_failure"])

        # There are some errors that we are ignoring.
        # No route to host: this issue is non-critical since Tribler can still function when a request fails.
        if "socket.error: [Errno 113]" in text:
            self._logger.error(
                "Observed no route to host error (but ignoring)."
                "This might indicate a problem with your firewall."
            )
            return

        # Socket block: this sometimes occurres on Windows and is non-critical.
        if "socket.error: [Errno %s]" % SOCKET_BLOCK_ERRORCODE in text:
            self._logger.error(
                "Unable to send data due to socket.error %s", SOCKET_BLOCK_ERRORCODE
            )
            return

        if "socket.error: [Errno 51]" in text:
            self._logger.error("Could not send data: network is unreachable.")
            return

        if "exceptions.ValueError: Invalid DNS-ID" in text:
            self._logger.error("Invalid DNS-ID")
            return

        if self.lm.api_manager and len(text) > 0:
            self.lm.api_manager.root_endpoint.events_endpoint.on_tribler_exception(text)
            self.lm.api_manager.root_endpoint.state_endpoint.on_tribler_exception(text)


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

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

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

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

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

File "Tribler\Core\Libtorrent\LibtorrentDownloadImpl.py", line 240, in schedule_create_engine

File "Tribler\Core\Libtorrent\LibtorrentDownloadImpl.py", line 341, in network_create_engine_wrapper

File "Tribler\Core\Libtorrent\LibtorrentMgr.py", line 304, in add_torrent

exceptions.RuntimeError: invalid info-hash

# Fixed code
def unhandled_error_observer(self, event):
    """
    This method is called when an unhandled error in Tribler is observed. Broadcasts the tribler_exception event.
    """
    if event["isError"]:
        text = ""
        if "log_legacy" in event and "log_text" in event:
            text = event["log_text"]
        elif "log_failure" in event:
            text = str(event["log_failure"])

        # There are some errors that we are ignoring.
        # No route to host: this issue is non-critical since Tribler can still function when a request fails.
        if "socket.error: [Errno 113]" in text:
            self._logger.error(
                "Observed no route to host error (but ignoring)."
                "This might indicate a problem with your firewall."
            )
            return

        # Socket block: this sometimes occurres on Windows and is non-critical.
        if "socket.error: [Errno %s]" % SOCKET_BLOCK_ERRORCODE in text:
            self._logger.error(
                "Unable to send data due to socket.error %s", SOCKET_BLOCK_ERRORCODE
            )
            return

        if "socket.error: [Errno 51]" in text:
            self._logger.error("Could not send data: network is unreachable.")
            return

        if "exceptions.ValueError: Invalid DNS-ID" in text:
            self._logger.error("Invalid DNS-ID")
            return

        # We already have a check for invalid infohash when adding a torrent, but if somehow we get this
        # error then we simply log and ignore it.
        if "exceptions.RuntimeError: invalid info-hash" in text:
            self._logger.error("Invalid info-hash found")
            return

        if self.lm.api_manager and len(text) > 0:
            self.lm.api_manager.root_endpoint.events_endpoint.on_tribler_exception(text)
            self.lm.api_manager.root_endpoint.state_endpoint.on_tribler_exception(text)