tlabels: don't dump trace if failed to connect to server - electrum - Electrum Bitcoin wallet HTML git clone https://git.parazyd.org/electrum DIR Log DIR Files DIR Refs DIR Submodules --- DIR commit 8c3ab63504a1b6b5846abc273e5a187ae9737fd7 DIR parent c23e94984836f0df4ebef8ec7688b71975de00b5 HTML Author: SomberNight <somber.night@protonmail.com> Date: Fri, 22 Mar 2019 17:24:52 +0100 labels: don't dump trace if failed to connect to server Diffstat: M electrum/plugins/labels/labels.py | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) --- DIR diff --git a/electrum/plugins/labels/labels.py b/electrum/plugins/labels/labels.py t@@ -3,6 +3,7 @@ import hashlib import json import sys import traceback +from typing import Union import base64 t@@ -13,6 +14,18 @@ from electrum.util import log_exceptions, ignore_exceptions, make_aiohttp_sessio from electrum.network import Network +class ErrorConnectingServer(Exception): + def __init__(self, reason: Union[str, Exception] = None): + self.reason = reason + + def __str__(self): + header = _("Error connecting to {} server").format('Labels') + reason = self.reason + if isinstance(reason, BaseException): + reason = repr(reason) + return f"{header}: {reason}" if reason else header + + class LabelsPlugin(BasePlugin): def __init__(self, parent, config, name): t@@ -109,7 +122,10 @@ class LabelsPlugin(BasePlugin): wallet_id = wallet_data[2] nonce = 1 if force else self.get_nonce(wallet) - 1 self.print_error("asking for labels since nonce", nonce) - response = await self.do_get("/labels/since/%d/for/%s" % (nonce, wallet_id)) + try: + response = await self.do_get("/labels/since/%d/for/%s" % (nonce, wallet_id)) + except Exception as e: + raise ErrorConnectingServer(e) from e if response["labels"] is None: self.print_error('no new labels') return t@@ -141,7 +157,10 @@ class LabelsPlugin(BasePlugin): @ignore_exceptions @log_exceptions async def pull_safe_thread(self, wallet, force): - await self.pull_thread(wallet, force) + try: + await self.pull_thread(wallet, force) + except ErrorConnectingServer as e: + self.print_error(str(e)) def pull(self, wallet, force): if not wallet.network: raise Exception(_('You are offline.'))