Skip to content

Commit

Permalink
Protect show_add_torrent_to_channel_dialog_from_uri from `UnicodeDe…
Browse files Browse the repository at this point in the history
…codeError`
  • Loading branch information
drew2a committed Sep 8, 2022
1 parent c0870df commit 120642a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/tribler/gui/tribler_request_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ def on_finished(self, request):
and not TriblerRequestManager.window.core_manager.shutting_down
):
# TODO: Report REST API errors to Sentry
logging.error(f'REST API error: {json_result}')
request_manager.show_error(TriblerRequestManager.get_message_from_error(json_result))
else:
self.received_json.emit(json_result)
Expand Down
13 changes: 9 additions & 4 deletions src/tribler/gui/tribler_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
QSystemTrayIcon,
QTreeWidget,
)

from psutil import LINUX

from tribler.core.upgrade.version_manager import VersionHistory
Expand Down Expand Up @@ -84,8 +83,8 @@
from tribler.gui.dialogs.new_channel_dialog import NewChannelDialog
from tribler.gui.dialogs.startdownloaddialog import StartDownloadDialog
from tribler.gui.error_handler import ErrorHandler
from tribler.gui.exceptions import TriblerGuiTestException
from tribler.gui.event_request_manager import EventRequestManager
from tribler.gui.exceptions import TriblerGuiTestException
from tribler.gui.tribler_action_menu import TriblerActionMenu
from tribler.gui.tribler_request_manager import (
TriblerNetworkRequest,
Expand Down Expand Up @@ -681,8 +680,14 @@ def on_add_button_pressed(channel_id):
scheme = scheme_from_url(uri)
if scheme == FILE_SCHEME:
file_path = url_to_path(uri)
with open(file_path) as torrent_file:
post_data['torrent'] = b64encode(torrent_file.read()).decode('utf8')
content = Path(file_path).read_bytes()
try:
post_data['torrent'] = b64encode(content).decode('utf8')
except UnicodeDecodeError as e:
self._logger.error(f'{e.__class__.__name__}: {e}')
error_message = f'Can not add the torrent to the personal channel: {e}'
ConfirmationDialog.show_message(self.window(), tr('Error'), tr(error_message), "OK")

elif scheme == MAGNET_SCHEME:
post_data['uri'] = uri

Expand Down

0 comments on commit 120642a

Please sign in to comment.