Example #1
0
 def _report_exception(self, exc, tb):
     try:
         _logger().critical('unhandled exception:\n%s', tb)
         _tb = tb
         if isinstance(exc, UnicodeDecodeError):
             # This might be the same exception in the same file but at
             # another position in the stream
             _tb = tb.splitlines()[-4]
         if _tb in self._reported_tracebacks:
             return
         self._reported_tracebacks.append(_tb)
         title = '[Unhandled exception] %s' % exc.__class__.__name__
         description = 'An unhandled exception has occured:\n\n'\
                       '%s\n\nWould like to send a bug report to the ' \
                       'development team?' % tb
         answer = QtWidgets.QMessageBox.critical(
             self.win, title, description,
             QtWidgets.QMessageBox.Yes | QtWidgets.QMessageBox.No,
             QtWidgets.QMessageBox.Yes)
         if answer == QtWidgets.QMessageBox.Yes:
             qcrash.show_report_dialog(
                 parent=self.win, window_icon=self.win.windowIcon(),
                 window_title="Report unhandled exception",
                 issue_title=title, traceback=tb)
     except Exception:
         _logger().exception('exception in excepthook')
Example #2
0
def report_bug(window, title='', traceback=None, issue_description=''):
    qcrash.show_report_dialog(
        issue_title=title, traceback=traceback, parent=window,
        include_log=traceback is not None,
        include_sys_info=traceback is not None,
        issue_description=issue_description)
    return True
Example #3
0
def except_hook(exc, tb):
    res = QtWidgets.QMessageBox.question(
        win, "Unhandled exception", "An unhandled exception has occured. Do "
        "you want to report")
    if res == QtWidgets.QMessageBox.Yes:
        qcrash.show_report_dialog(
            window_title='Report unhandled exception',
            issue_title=str(exc), traceback=tb)
Example #4
0
def test_show_report_dialog(qtbot):
    api._backends[:] = []
    assert len(api.get_backends()) == 0
    b1 = api.backends.GithubBackend('ColinDuquesnoy', 'TestQCrash')
    b2 = api.backends.EmailBackend('*****@*****.**', 'TestQCrash')
    api.install_backend(b1, b2)
    assert len(api.get_backends()) == 2

    dlg = api.show_report_dialog(modal=True)

    assert len(dlg.buttons) == 2

    # force email backend to return True to close the dialog
    b2.old_send_report = b2.send_report

    qtbot.wait(1000)

    def send_report(*args, **kwargs):
        b2.old_send_report(*args, **kwargs)
        return True

    b2.send_report = send_report
    dlg.buttons[1].clicked.emit(True)

    dlg.reject()
Example #5
0
def except_hook(exc, tb):
    from qcrash.api import show_report_dialog
    title = '[Unhandled exception]  %s: %s' % (
        exc.__class__.__name__, str(exc))
    msg_box = QtWidgets.QMessageBox()
    msg_box.setWindowTitle('Unhandled exception')
    msg_box.setText('An unhandled exception has occured...')
    msg_box.setInformativeText(
        'Would you like to report the bug to the developers?')
    msg_box.setIcon(msg_box.Critical)
    msg_box.setDetailedText(tb)
    msg_box.setStandardButtons(QtWidgets.QMessageBox.Ok |
                               QtWidgets.QMessageBox.Cancel)
    msg_box.button(msg_box.Ok).setText('Report')
    msg_box.button(msg_box.Cancel).setText('Close')
    if msg_box.exec_() == msg_box.Ok:
        show_report_dialog(window_title='Report unhandled exception',
                           issue_title=title, traceback=tb)
Example #6
0
def test_value_errors():
    api._backends[:] = []
    with pytest.raises(ValueError):
        api.install_except_hook()
    with pytest.raises(ValueError):
        api.show_report_dialog()
Example #7
0
qcrash.set_qsettings(my_settings)


# configure backends
qcrash.install_backend(qcrash.backends.GithubBackend(
    GITHUB_OWNER, GITHUB_REPO))
qcrash.install_backend(qcrash.backends.EmailBackend(EMAIL, 'TestApp'))


# setup our own function to collect system info and application log
qcrash.get_application_log = get_application_log
qcrash.get_system_information = get_system_info


# show report dialog manually
qcrash.show_report_dialog()


# create a window
win = QtWidgets.QMainWindow()
label = QtWidgets.QLabel()
label.setText('Wait a few seconds for an unhandled exception to occur...')
label.setAlignment(QtCore.Qt.AlignHCenter | QtCore.Qt.AlignVCenter)
win.setCentralWidget(label)
win.showMaximized()


# install our own except hook.
def except_hook(exc, tb):
    res = QtWidgets.QMessageBox.question(
        win, "Unhandled exception", "An unhandled exception has occured. Do "
Example #8
0
 def report_bug(self):
     qcrash.show_report_dialog(
         window_icon=self.main_window.windowIcon(),
         parent=self.main_window, include_log=False, include_sys_info=False)