From c1f06d99d75506dfdfdbd88f4cde4169b5176224 Mon Sep 17 00:00:00 2001 From: Miguel Jacq Date: Tue, 18 Feb 2025 16:35:47 +1100 Subject: [PATCH] Catch general Exception in the UI when trying to connect or start a share, and raise as Alert --- desktop/onionshare/resources/locale/en.json | 1 + desktop/onionshare/threads.py | 5 +++++ desktop/onionshare/tor_connection.py | 6 ++++++ 3 files changed, 12 insertions(+) diff --git a/desktop/onionshare/resources/locale/en.json b/desktop/onionshare/resources/locale/en.json index 79c9a14c..165995a6 100644 --- a/desktop/onionshare/resources/locale/en.json +++ b/desktop/onionshare/resources/locale/en.json @@ -247,6 +247,7 @@ "error_port_not_available": "OnionShare port not available", "history_receive_read_message_button": "Read Message", "error_tor_protocol_error": "There was an error with Tor: {}", + "error_generic": "There was an unexpected error with OnionShare:\n{}", "moat_contact_label": "Contacting BridgeDB…", "moat_captcha_label": "Solve the CAPTCHA to request a bridge.", "moat_captcha_placeholder": "Enter the characters from the image", diff --git a/desktop/onionshare/threads.py b/desktop/onionshare/threads.py index 6eeeb97f..227ec923 100644 --- a/desktop/onionshare/threads.py +++ b/desktop/onionshare/threads.py @@ -106,6 +106,11 @@ class OnionThread(QtCore.QThread): message = self.mode.common.gui.get_translated_tor_error(e) self.error.emit(message) return + except Exception as e: + # Handle any other error that wasn't in the list above + message = strings._("error_generic").format(e.args[0]) + self.error.emit(message) + return class WebThread(QtCore.QThread): diff --git a/desktop/onionshare/tor_connection.py b/desktop/onionshare/tor_connection.py index f87967ef..ceb8eace 100644 --- a/desktop/onionshare/tor_connection.py +++ b/desktop/onionshare/tor_connection.py @@ -210,6 +210,12 @@ class TorConnectionThread(QtCore.QThread): ) self.error_connecting_to_tor.emit(message) + except Exception as e: + # Handle any other error that wasn't in the list above + message = strings._("error_generic").format(e.args[0]) + self.error_connecting_to_tor.emit(message) + return + def _tor_status_update(self, progress, summary): self.tor_status_update.emit(progress, summary)