1
0
Fork 0
mirror of https://github.com/borgbase/vorta synced 2024-12-22 07:43:09 +00:00

Improved Exception Dialog. By @shivansh02 (#1977)

This commit is contained in:
Shivansh Singh 2024-07-19 18:38:08 +05:30 committed by GitHub
parent 6b440ba6d2
commit 513e8e2cbd
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 240 additions and 14 deletions

View file

@ -8,36 +8,29 @@
# because we will be overriding the modules variables # because we will be overriding the modules variables
from vorta import config from vorta import config
from vorta._version import __version__ from vorta._version import __version__
from vorta.i18n import trans_late, translate
from vorta.log import init_logger, logger from vorta.log import init_logger, logger
from vorta.store.connection import init_db from vorta.store.connection import init_db
from vorta.updater import get_updater from vorta.updater import get_updater
from vorta.utils import DEFAULT_DIR_FLAG, parse_args from vorta.utils import DEFAULT_DIR_FLAG, parse_args
from vorta.views.exception_dialog import ExceptionDialog
def main(): def main():
def exception_handler(type, value, tb): def exception_handler(type, value, tb):
from traceback import format_exception from traceback import format_exception
from PyQt6.QtWidgets import QMessageBox
logger.critical( logger.critical(
"Uncaught exception, file a report at https://github.com/borgbase/vorta/issues/new/choose", "Uncaught exception, file a report at https://github.com/borgbase/vorta/issues/new/choose",
exc_info=(type, value, tb), exc_info=(type, value, tb),
) )
full_exception = ''.join(format_exception(type, value, tb)) full_exception = ''.join(format_exception(type, value, tb))
title = trans_late('app', 'Fatal Error')
error_message = trans_late(
'app',
'Uncaught exception, please file a report with this text at\n'
'https://github.com/borgbase/vorta/issues/new\n',
)
if app: if app:
QMessageBox.critical( exception_dialog = ExceptionDialog(full_exception)
None, exception_dialog.show()
translate('app', title), exception_dialog.raise_()
translate('app', error_message) + full_exception, exception_dialog.activateWindow()
) exception_dialog.exec()
else: else:
# Crashed before app startup, cannot translate # Crashed before app startup, cannot translate
sys.exit(1) sys.exit(1)

View file

@ -0,0 +1,172 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Dialog</class>
<widget class="QDialog" name="Dialog">
<property name="windowModality">
<enum>Qt::NonModal</enum>
</property>
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>674</width>
<height>296</height>
</rect>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
<property name="windowTitle">
<string>Fatal Error</string>
</property>
<property name="modal">
<bool>true</bool>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<layout class="QVBoxLayout" name="verticalLayout">
<property name="leftMargin">
<number>10</number>
</property>
<property name="topMargin">
<number>10</number>
</property>
<property name="rightMargin">
<number>10</number>
</property>
<property name="bottomMargin">
<number>10</number>
</property>
<item>
<layout class="QHBoxLayout" name="horizontalLayout" stretch="1,0,7">
<property name="spacing">
<number>0</number>
</property>
<item>
<widget class="QLabel" name="alertImage">
<property name="text">
<string/>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>10</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout_3">
<property name="spacing">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<item>
<widget class="QLabel" name="title_label">
<property name="font">
<font>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>Vorta quit unexpectedly. </string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="report_to_github_label">
<property name="text">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;You can report this issue on &lt;a href=&quot;https://github.com/borgbase/vorta/issues&quot;&gt;&lt;span style=&quot; text-decoration: underline; color:#0984e3;&quot;&gt;Github&lt;/span&gt;&lt;/a&gt;. Please search for similar issues before reporting.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>5</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="report_label">
<property name="text">
<string>Crash Report:</string>
</property>
</widget>
</item>
<item>
<widget class="QPlainTextEdit" name="crashDetails">
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QDialogButtonBox" name="ignoreButton">
<property name="standardButtons">
<set>QDialogButtonBox::Close</set>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="copyButton">
<property name="text">
<string>Copy to Clipboard</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>

View file

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<svg fill="#000000" width="1792" height="1792" viewBox="0 0 1792 1792" xmlns="http://www.w3.org/2000/svg">
<path d="M1024 1375v-190c0-18-14-33-32-33H800c-18 0-32 15-32 33v190c0 18 14 33 32 33h192c18 0 32-15 32-33zm-2-374l18-459c0-6-3-14-10-19-6-5-15-11-24-11H786c-9 0-18 6-24 11-7 5-10 15-10 21l17 457c0 13 15 23 34 23h185c18 0 33-10 34-23zm-14-934l768 1408c22 39 21 87-2 126s-65 63-110 63H128c-45 0-87-24-110-63s-24-87-2-126L784 67c22-41 65-67 112-67s90 26 112 67z"/>
</svg>

After

Width:  |  Height:  |  Size: 520 B

View file

@ -0,0 +1,57 @@
import datetime
import platform
from PyQt6 import uic
from PyQt6.QtWidgets import QApplication
from vorta._version import __version__
from vorta.utils import borg_compat
from vorta.views.utils import get_colored_icon
from ..utils import get_asset
# Load UI file
uifile = get_asset('UI/exceptiondialog.ui')
ExceptionDialogUI, ExceptionDialogBase = uic.loadUiType(uifile)
class ExceptionDetails:
@staticmethod
def get_os_details():
uname_result = platform.uname()
os_details = f"OS: {uname_result.system}\n"
os_details += f"Release: {uname_result.release}\n"
os_details += f"Version: {uname_result.version}"
return os_details
@staticmethod
def get_exception_details(exception):
details = ExceptionDetails.get_os_details()
details += "\nDate and Time: " + datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
details += "\nBorg Version: " + borg_compat.version
details += "\nVorta Version: " + __version__
details += "\n" + exception
return details
class ExceptionDialog(ExceptionDialogBase, ExceptionDialogUI):
def __init__(self, exception: str):
super().__init__()
self.setupUi(self)
self.report_to_github_label.setOpenExternalLinks(True)
self.ignoreButton.clicked.connect(self.close)
self.copyButton.clicked.connect(self.copy_report_to_clipboard)
self.copyButton.setIcon(get_colored_icon('copy'))
# Set crash details
details = ExceptionDetails.get_exception_details(exception)
self.crashDetails.setPlainText(details)
# Set alert image
self.alertImage.setPixmap(get_colored_icon('exclamation-triangle', scaled_height=75, return_qpixmap=True))
def copy_report_to_clipboard(self):
cb = QApplication.clipboard()
cb.setText(self.crashDetails.toPlainText(), mode=cb.Mode.Clipboard)