electrum

Electrum Bitcoin wallet
git clone https://git.parazyd.org/electrum
Log | Files | Refs | Submodules

commit 53893be4c9224b6914df40248c94d065c2512643
parent 1d0f67996e7875091fec253ed68d240403a11a0d
Author: SomberNight <somber.night@protonmail.com>
Date:   Tue,  2 Jul 2019 19:27:36 +0200

crash reporter: in Qt subclass, do network request using WaitingDialog

so it does not block the GUI

Diffstat:
Melectrum/base_crash_reporter.py | 9+++++----
Melectrum/gui/kivy/uix/dialogs/crash_reporter.py | 5++++-
Melectrum/gui/qt/exception_window.py | 30++++++++++++++++++------------
3 files changed, 27 insertions(+), 17 deletions(-)

diff --git a/electrum/base_crash_reporter.py b/electrum/base_crash_reporter.py @@ -31,10 +31,10 @@ from .version import ELECTRUM_VERSION from . import constants from .i18n import _ from .util import make_aiohttp_session -from .logging import describe_os_version +from .logging import describe_os_version, Logger -class BaseCrashReporter: +class BaseCrashReporter(Logger): report_server = "https://crashhub.electrum.org" config_key = "show_crash_reporter" issue_template = """<h2>Traceback</h2> @@ -59,9 +59,10 @@ class BaseCrashReporter: ASK_CONFIRM_SEND = _("Do you want to send this report?") def __init__(self, exctype, value, tb): + Logger.__init__(self) self.exc_args = (exctype, value, tb) - def send_report(self, asyncio_loop, proxy, endpoint="/crash"): + def send_report(self, asyncio_loop, proxy, endpoint="/crash", *, timeout=None): if constants.net.GENESIS[-4:] not in ["4943", "e26f"] and ".electrum.org" in BaseCrashReporter.report_server: # Gah! Some kind of altcoin wants to send us crash reports. raise Exception(_("Missing report URL.")) @@ -69,7 +70,7 @@ class BaseCrashReporter: report.update(self.get_additional_info()) report = json.dumps(report) coro = self.do_post(proxy, BaseCrashReporter.report_server + endpoint, data=report) - response = asyncio.run_coroutine_threadsafe(coro, asyncio_loop).result(5) + response = asyncio.run_coroutine_threadsafe(coro, asyncio_loop).result(timeout) return response async def do_post(self, proxy, url, data): diff --git a/electrum/gui/kivy/uix/dialogs/crash_reporter.py b/electrum/gui/kivy/uix/dialogs/crash_reporter.py @@ -119,8 +119,11 @@ class CrashReporter(BaseCrashReporter, Factory.Popup): try: loop = self.main_window.network.asyncio_loop proxy = self.main_window.network.proxy - response = json.loads(BaseCrashReporter.send_report(self, loop, proxy, "/crash.json")) + # FIXME network request in GUI thread... + response = json.loads(BaseCrashReporter.send_report(self, loop, proxy, + "/crash.json", timeout=10)) except (ValueError, ClientError): + #self.logger.debug("", exc_info=True) self.show_popup(_('Unable to send report'), _("Please check your network connection.")) else: self.show_popup(_('Report sent'), response["text"]) diff --git a/electrum/gui/qt/exception_window.py b/electrum/gui/qt/exception_window.py @@ -33,7 +33,7 @@ from PyQt5.QtWidgets import (QWidget, QLabel, QPushButton, QTextEdit, from electrum.i18n import _ from electrum.base_crash_reporter import BaseCrashReporter from electrum.logging import Logger -from .util import MessageBoxMixin, read_QIcon +from .util import MessageBoxMixin, read_QIcon, WaitingDialog class Exception_Window(BaseCrashReporter, QWidget, MessageBoxMixin, Logger): @@ -96,17 +96,23 @@ class Exception_Window(BaseCrashReporter, QWidget, MessageBoxMixin, Logger): self.show() def send_report(self): - try: - proxy = self.main_window.network.proxy - response = BaseCrashReporter.send_report(self, self.main_window.network.asyncio_loop, proxy) - except BaseException as e: - self.logger.exception('There was a problem with the automatic reporting') - self.main_window.show_critical(_('There was a problem with the automatic reporting:') + '\n' + - str(e) + '\n' + - _("Please report this issue manually.")) - return - QMessageBox.about(self, _("Crash report"), response) - self.close() + def on_success(response): + self.show_message(parent=self, + title=_("Crash report"), + msg=response) + self.close() + def on_failure(exc_info): + e = exc_info[1] + self.logger.error('There was a problem with the automatic reporting', exc_info=exc_info) + self.show_critical(parent=self, + msg=(_('There was a problem with the automatic reporting:') + '\n' + + str(e) + '\n' + + _("Please report this issue manually."))) + + proxy = self.main_window.network.proxy + task = lambda: BaseCrashReporter.send_report(self, self.main_window.network.asyncio_loop, proxy) + msg = _('Sending crash report...') + WaitingDialog(self, msg, task, on_success, on_failure) def on_close(self): Exception_Window._active_window = None