Skip to content

Commit

Permalink
Fixes Tribler#7406 UnicodeDecodeError in on_tracker_error_alert
Browse files Browse the repository at this point in the history
  • Loading branch information
kozlovsky committed Jun 8, 2023
1 parent 035b623 commit 842827c
Showing 1 changed file with 5 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -312,12 +312,12 @@ def on_tracker_reply_alert(self, alert: lt.tracker_reply_alert):
self.tracker_status[alert.url] = [alert.num_peers, 'Working']

def on_tracker_error_alert(self, alert: lt.tracker_error_alert):
self._logger.error(f'On tracker error alert: {alert}')

# try-except block here is a workaround and has been added to solve
# the issue: "UnicodeDecodeError: invalid continuation byte"
# The try-except block is added as a workaround to suppress UnicodeDecodeError in `repr(alert)`,
# `alert.url` and `alert.msg`. See https://github.com/arvidn/libtorrent/issues/143
try:
self._logger.error(f'On tracker error alert: {alert}')
url = alert.url

peers = self.tracker_status[url][0] if url in self.tracker_status else 0
if alert.msg:
status = 'Error: ' + alert.msg
Expand All @@ -330,8 +330,7 @@ def on_tracker_error_alert(self, alert: lt.tracker_error_alert):

self.tracker_status[url] = [peers, status]
except UnicodeDecodeError as e:
self._logger.exception(e)
return
self._logger.warning(f'UnicodeDecodeError in on_tracker_error_alert: {e}')

def on_tracker_warning_alert(self, alert: lt.tracker_warning_alert):
self._logger.warning(f'On tracker warning alert: {alert}')
Expand Down

0 comments on commit 842827c

Please sign in to comment.