From 15f5178f8f8007ff9089f2acf96f393dab5be6de Mon Sep 17 00:00:00 2001 From: Inso Date: Sat, 30 Jan 2016 09:39:23 +0100 Subject: [PATCH] Fix crash #357 --- src/sakia/core/net/node.py | 19 ++++++++++--------- src/sakia/gui/process_cfg_community.py | 11 ++++++----- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/src/sakia/core/net/node.py b/src/sakia/core/net/node.py index 15ba775f..f1f2d4b5 100644 --- a/src/sakia/core/net/node.py +++ b/src/sakia/core/net/node.py @@ -5,15 +5,13 @@ """ from ucoinpy.documents.peer import Peer, Endpoint, BMAEndpoint -from ucoinpy.documents import Block, BlockId +from ucoinpy.documents import Block, BlockId, MalformedDocumentError from ...tools.exceptions import InvalidNodeCurrency from ...tools.decorators import asyncify from ucoinpy.api import bma as bma from ucoinpy.api.bma import ConnectionHandler -import json -from aiohttp.errors import ClientError, DisconnectedError, TimeoutError, \ - WSClientDisconnectedError, WSServerHandshakeError, ClientResponseError +from aiohttp.errors import WSClientDisconnectedError, WSServerHandshakeError, ClientResponseError from aiohttp.errors import ClientError, DisconnectedError from asyncio import TimeoutError import logging @@ -588,11 +586,14 @@ async def request_peers(self): def refresh_peer_data(self, peer_data): if "raw" in peer_data: - str_doc = "{0}{1}\n".format(peer_data['raw'], - peer_data['signature']) - peer_doc = Peer.from_signed_raw(str_doc) - pubkey = peer_data['pubkey'] - self.neighbour_found.emit(peer_doc, pubkey) + try: + str_doc = "{0}{1}\n".format(peer_data['raw'], + peer_data['signature']) + peer_doc = Peer.from_signed_raw(str_doc) + pubkey = peer_data['pubkey'] + self.neighbour_found.emit(peer_doc, pubkey) + except MalformedDocumentError as e: + logging.debug(str(e)) else: logging.debug("Incorrect leaf reply") diff --git a/src/sakia/gui/process_cfg_community.py b/src/sakia/gui/process_cfg_community.py index be0e5355..a29e0d77 100644 --- a/src/sakia/gui/process_cfg_community.py +++ b/src/sakia/gui/process_cfg_community.py @@ -8,9 +8,10 @@ import asyncio import aiohttp -from PyQt5.QtWidgets import QDialog, QMenu, QMessageBox, QApplication +from ucoinpy.documents import MalformedDocumentError +from PyQt5.QtWidgets import QDialog, QMenu, QApplication from PyQt5.QtGui import QCursor -from PyQt5.QtCore import pyqtSlot, pyqtSignal, QObject +from PyQt5.QtCore import pyqtSignal, QObject from ..gen_resources.community_cfg_uic import Ui_CommunityConfigurationDialog from ..models.peering import PeeringTreeModel @@ -73,7 +74,7 @@ async def check_guest(self, checked=False): self.config_dialog.label_error.setText(str(e)) except aiohttp.errors.ClientError as e: self.config_dialog.label_error.setText(str(e)) - except ValueError as e: + except (MalformedDocumentError, ValueError) as e: self.config_dialog.label_error.setText(str(e)) @asyncify @@ -101,7 +102,7 @@ async def check_connect(self, checked=False): self.config_dialog.label_error.setText(str(e)) except aiohttp.errors.ClientError as e: self.config_dialog.label_error.setText(str(e)) - except ValueError as e: + except (MalformedDocumentError, ValueError) as e: self.config_dialog.label_error.setText(str(e)) @asyncify @@ -144,7 +145,7 @@ async def check_register(self, checked=False): self.config_dialog.label_error.setText(str(e)) except aiohttp.errors.ClientError as e: self.config_dialog.label_error.setText(str(e)) - except ValueError as e: + except (MalformedDocumentError, ValueError) as e: self.config_dialog.label_error.setText(str(e)) def is_valid(self):