Skip to content
Snippets Groups Projects
Commit c949ffe6 authored by inso's avatar inso
Browse files

Silence unworrying exceptions

parent aed52c33
No related branches found
No related tags found
No related merge requests found
......@@ -113,10 +113,10 @@ class NodeConnector(QObject):
else:
raise
except (ClientError, gaierror, TimeoutError, ConnectionRefusedError, ValueError) as e:
self._logger.debug("{0}".format(str(e)))
self._logger.debug("{:}:{:}".format(str(e.__class__.__name__), str(e)))
self.change_state_and_emit(Node.OFFLINE)
except jsonschema.ValidationError as e:
self._logger.debug(str(e))
self._logger.debug("{:}:{:}".format(str(e.__class__.__name__), str(e)))
self.change_state_and_emit(Node.CORRUPTED)
except RuntimeError:
if self.session.closed:
......@@ -187,8 +187,7 @@ class NodeConnector(QObject):
self._logger.debug("{0} : {1}".format(str(e), self.node.pubkey[:5]))
self.change_state_and_emit(Node.OFFLINE)
except jsonschema.ValidationError as e:
self._logger.debug(str(e))
self._logger.debug("Validation error")
self._logger.debug("{:}:{:}".format(str(e.__class__.__name__), str(e)))
self.change_state_and_emit(Node.CORRUPTED)
except RuntimeError:
if self.session.closed:
......@@ -219,6 +218,9 @@ class NodeConnector(QObject):
else:
self.change_state_and_emit(Node.CORRUPTED)
self._logger.debug("Error in block reply : {0}".format(str(e)))
else:
if self.session.closed:
pass
else:
self._logger.debug("Could not connect to any BMA endpoint")
self.change_state_and_emit(Node.OFFLINE)
......@@ -257,6 +259,9 @@ class NodeConnector(QObject):
self._logger.debug("Changed block {0} -> {1}".format(self.node.current_buid.number,
block_data['number']))
self.changed.emit()
else:
if self.session.closed:
pass
else:
self._logger.debug("Could not connect to any BMA endpoint")
self.change_state_and_emit(Node.OFFLINE)
......@@ -282,6 +287,9 @@ class NodeConnector(QObject):
except errors.DuniterError as e:
self._logger.debug("Error in summary : {:}".format(str(e)))
self.change_state_and_emit(Node.OFFLINE)
else:
if self.session.closed:
pass
else:
self._logger.debug("Could not connect to any BMA endpoint")
self.change_state_and_emit(Node.OFFLINE)
......@@ -314,10 +322,10 @@ class NodeConnector(QObject):
.format(type(e).__name__, str(e)))
await self.request_peers()
except (ClientError, gaierror, TimeoutError) as e:
self._logger.debug("{0}".format(str(e)))
self._logger.debug("{:}:{:}".format(str(e.__class__.__name__), str(e)))
self.change_state_and_emit(Node.OFFLINE)
except jsonschema.ValidationError as e:
self._logger.debug(str(e))
self._logger.debug("{:}:{:}".format(str(e.__class__.__name__), str(e)))
self.change_state_and_emit(Node.CORRUPTED)
except RuntimeError:
if self.session.closed:
......@@ -359,7 +367,7 @@ class NodeConnector(QObject):
if e.ucode == 2012:
# Since with multinodes, peers or not the same on all nodes, sometimes this request results
# in peer not found error
self._logger.debug(str(e))
self._logger.debug("{:}:{:}".format(str(e.__class__.__name__), str(e)))
else:
self.change_state_and_emit(Node.OFFLINE)
self._logger.debug("Incorrect peer data in {leaf} : {err}".format(leaf=leaf_hash, err=str(e)))
......@@ -370,6 +378,9 @@ class NodeConnector(QObject):
except errors.DuniterError as e:
self._logger.debug("Error in peers reply : {0}".format(str(e)))
self.change_state_and_emit(Node.OFFLINE)
else:
if self.session.closed:
pass
else:
self._logger.debug("Could not connect to any BMA endpoint")
self.change_state_and_emit(Node.OFFLINE)
......@@ -382,7 +393,7 @@ class NodeConnector(QObject):
peer_doc = Peer.from_signed_raw(str_doc)
self.neighbour_found.emit(peer_doc)
except MalformedDocumentError as e:
self._logger.debug(str(e))
self._logger.debug("{:}:{:}".format(str(e.__class__.__name__), str(e)))
else:
self._logger.debug("Incorrect leaf reply")
......
......@@ -18,6 +18,30 @@ from sakia.gui.preferences import PreferencesDialog
from sakia.gui.widgets import QAsyncMessageBox
def exit_exception_handler(loop, context):
"""
An exception handler which prints only on debug (used when exiting)
:param loop: the asyncio loop
:param context: the exception context
"""
logging.debug('Exception handler executing')
message = context.get('message')
if not message:
message = 'Unhandled exception in event loop'
try:
exception = context['exception']
except KeyError:
exc_info = False
else:
exc_info = (type(exception), exception, exception.__traceback__)
logging.debug("An unhandled exception occured : {0}".format(message),
exc_info=exc_info)
def async_exception_handler(loop, context):
"""
An exception handler which exits the program if the exception
......@@ -85,7 +109,7 @@ def main():
sys.excepthook = exception_handler
sakia.setStyle('Fusion')
#sakia.setStyle('Fusion')
loop = QSelectorEventLoop(sakia)
loop.set_exception_handler(async_exception_handler)
#loop.set_debug(True)
......@@ -131,7 +155,7 @@ def main():
window = MainWindowController.startup(app)
loop.run_forever()
try:
loop.set_exception_handler(None)
loop.set_exception_handler(exit_exception_handler)
loop.run_until_complete(app.stop_current_profile())
logging.debug("Application stopped")
except asyncio.CancelledError:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment