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

New error handling

parent b988a348
No related branches found
No related tags found
No related merge requests found
...@@ -5,8 +5,10 @@ Created on 1 févr. 2014 ...@@ -5,8 +5,10 @@ Created on 1 févr. 2014
""" """
import aiohttp import aiohttp
import logging import logging
import traceback
from PyQt5.QtWidgets import QMainWindow, QAction, QFileDialog, QMessageBox, QLabel, QComboBox, QDialog, QApplication from PyQt5.QtWidgets import QMainWindow, QAction, QFileDialog, \
QMessageBox, QLabel, QComboBox, QDialog, QApplication, QErrorMessage
from PyQt5.QtCore import QLocale, QEvent, \ from PyQt5.QtCore import QLocale, QEvent, \
pyqtSlot, QDateTime, QTimer, Qt, QObject, QUrl pyqtSlot, QDateTime, QTimer, Qt, QObject, QUrl
from PyQt5.QtGui import QIcon from PyQt5.QtGui import QIcon
...@@ -29,6 +31,7 @@ from ..core.community import Community ...@@ -29,6 +31,7 @@ from ..core.community import Community
from ..tools.decorators import asyncify from ..tools.decorators import asyncify
from ..__init__ import __version__ from ..__init__ import __version__
from .widgets import toast from .widgets import toast
from .widgets.dialogs import QAsyncMessageBox
class MainWindow(QObject): class MainWindow(QObject):
......
...@@ -180,6 +180,7 @@ class TransferMoneyDialog(QObject): ...@@ -180,6 +180,7 @@ class TransferMoneyDialog(QObject):
@asyncify @asyncify
async def relative_amount_changed(self, value): async def relative_amount_changed(self, value):
raise Exception("Test")
ud_block = await self.community.get_ud_block() ud_block = await self.community.get_ud_block()
dividend = ud_block['dividend'] dividend = ud_block['dividend']
base = ud_block['unitbase'] base = ud_block['unitbase']
......
...@@ -12,12 +12,14 @@ import traceback ...@@ -12,12 +12,14 @@ import traceback
# To debug missing spec # To debug missing spec
import jsonschema import jsonschema
import traceback
# To force cx_freeze import # To force cx_freeze import
import PyQt5.QtSvg import PyQt5.QtSvg
from quamash import QSelectorEventLoop from quamash import QSelectorEventLoop
from PyQt5.QtWidgets import QApplication from PyQt5.QtWidgets import QApplication, QMessageBox
from PyQt5.QtCore import Qt
from sakia.gui.mainwindow import MainWindow from sakia.gui.mainwindow import MainWindow
from sakia.core.app import Application from sakia.core.app import Application
...@@ -55,13 +57,38 @@ def async_exception_handler(loop, context): ...@@ -55,13 +57,38 @@ def async_exception_handler(loop, context):
for ignored in ("Unclosed", "socket.gaierror"): for ignored in ("Unclosed", "socket.gaierror"):
if ignored in line: if ignored in line:
return return
os._exit(1) exception_message(log_lines, exc_info)
def exception_handler(*exc_info):
logging.error("An unhandled exception occured",
exc_info=exc_info)
exception_message(["An unhandled exception occured"], exc_info)
def exception_message(log_lines, exc_info):
stacktrace = traceback.format_exception(*exc_info) if exc_info else ""
message = """
{log_lines}
----
{stacktrace}
""".format(log_lines='\n'.join(log_lines), stacktrace='\n'.join(stacktrace))
mb = QMessageBox(QMessageBox.Critical, "Critical error",
"""A critical error occured. Select the details to display it.
Please report it to <a href=\"https://github.com/duniter/sakia/issues/new\">the developers github</a>""",
QMessageBox.Ok, QApplication.activeWindow())
mb.setDetailedText(message)
mb.setTextFormat(Qt.RichText)
mb.setTextInteractionFlags(Qt.TextSelectableByMouse)
mb.exec()
if __name__ == '__main__': if __name__ == '__main__':
# activate ctrl-c interrupt # activate ctrl-c interrupt
signal.signal(signal.SIGINT, signal.SIG_DFL) signal.signal(signal.SIGINT, signal.SIG_DFL)
sakia = QApplication(sys.argv) sakia = QApplication(sys.argv)
sys.excepthook = exception_handler
sakia.setStyle('Fusion') sakia.setStyle('Fusion')
loop = QSelectorEventLoop(sakia) loop = QSelectorEventLoop(sakia)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment