Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved Exception Dialog with Copy Paste #1977

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 7 additions & 14 deletions src/vorta/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,36 +8,29 @@
# because we will be overriding the modules variables
from vorta import config
from vorta._version import __version__
from vorta.i18n import trans_late, translate
from vorta.log import init_logger, logger
from vorta.store.connection import init_db
from vorta.updater import get_updater
from vorta.utils import DEFAULT_DIR_FLAG, parse_args
from vorta.views.exception_dialog import ExceptionDialog


def main():
def exception_handler(type, value, tb):
from traceback import format_exception

from PyQt6.QtWidgets import QMessageBox

logger.critical(
"Uncaught exception, file a report at https://github.com/borgbase/vorta/issues/new/choose",
exc_info=(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:
QMessageBox.critical(
None,
translate('app', title),
translate('app', error_message) + full_exception,
)
exception_dialog = ExceptionDialog(full_exception)
exception_dialog.show()
exception_dialog.raise_()
exception_dialog.activateWindow()
exception_dialog.exec()
else:
# Crashed before app startup, cannot translate
sys.exit(1)
Expand Down
172 changes: 172 additions & 0 deletions src/vorta/assets/UI/exceptiondialog.ui
Original file line number Diff line number Diff line change
@@ -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>
4 changes: 4 additions & 0 deletions src/vorta/assets/icons/exclamation-triangle.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
57 changes: 57 additions & 0 deletions src/vorta/views/exception_dialog.py
Original file line number Diff line number Diff line change
@@ -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)
shivansh02 marked this conversation as resolved.
Show resolved Hide resolved

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)
Loading