Files
picard/tagger.py.in
Philipp Wolfer 0c5d908a4c PICARD-1718: Show more details in crash dialog
Also set stack trace into the detailedText. Nicer display and ensures eventual HTML inside this string does not get rendered.
2021-05-04 16:12:49 +02:00

59 lines
2.1 KiB
Python

#!/usr/bin/env python3
import os
import sys
sys.path.insert(0, '.')
# This is needed to find resources when using pyinstaller
if getattr(sys, 'frozen', False):
basedir = getattr(sys, '_MEIPASS', '')
else:
basedir = os.path.dirname(os.path.abspath(__file__))
if sys.platform == 'win32':
os.environ['PATH'] = basedir + ';' + os.environ['PATH']
try:
from picard.tagger import main
main(os.path.join(basedir, 'locale'), %(autoupdate)s)
except SystemExit:
raise # Just continue with a normal application exit
except: # noqa: F722
# First try to get traceback information and write it to a log file
# with minimum chance to fail.
from tempfile import NamedTemporaryFile
import traceback
trace = traceback.format_exc()
try:
with NamedTemporaryFile(suffix='.log', prefix='picard-crash-', delete=False) as f:
f.write(trace.encode(errors="replace"))
logfile = f.name
except: # noqa: F722
print("Failed writing log file {0}".format(logfile), file=sys.stderr)
logfile = None
# Display the crash information to the user as a dialog. This requires#
# importing Qt5 and has some potential to fail if things are broken.
from PyQt5.QtCore import Qt, QUrl
from PyQt5.QtWidgets import QApplication, QMessageBox
_unused = QApplication(sys.argv)
msgbox = QMessageBox()
msgbox.setIcon(QMessageBox.Critical)
msgbox.setWindowTitle("Picard terminated unexpectedly")
msgbox.setTextFormat(Qt.RichText)
msgbox.setText(
'An unexpected error has caused Picard to crash. '
'Please report this issue on the <a href="https://tickets.metabrainz.org/projects/PICARD">MusicBrainz bug tracker</a>.')
if logfile:
logfile_url = QUrl.fromLocalFile(logfile)
msgbox.setInformativeText(
'A logfile has been written to <a href="{0}">{1}</a>.'
.format(logfile_url.url(), logfile))
msgbox.setDetailedText(trace)
msgbox.setStandardButtons(QMessageBox.Close)
msgbox.setDefaultButton(QMessageBox.Close)
msgbox.exec_()
raise