1
0
mirror of https://github.com/ciromattia/kcc synced 2025-12-12 17:26:23 +00:00

Replaced own error reporting mechanism with Sentry

This commit is contained in:
Paweł Jastrzębski
2016-02-18 18:11:48 +01:00
parent c9cf635229
commit 189c03529a
5 changed files with 23 additions and 30 deletions

1
.gitignore vendored
View File

@@ -13,3 +13,4 @@ kindlegen*
*.spec *.spec
setup.bat setup.bat
setup.sh setup.sh
kcc/sentry.py

View File

@@ -33,15 +33,16 @@ You can find the latest released binary at the following links:
Following software is required to run Linux version of **KCC** and/or bare sources: Following software is required to run Linux version of **KCC** and/or bare sources:
- Python 3.3+ - Python 3.3+
- [PyQt](http://www.riverbankcomputing.co.uk/software/pyqt/download5) 5.2.1+ _(5.5+ is recommended)_ - [PyQt](http://www.riverbankcomputing.co.uk/software/pyqt/download5) 5.2.1+ _(5.5+ is recommended)_
- [Pillow](http://pypi.python.org/pypi/Pillow/) 3.0.0+ - [Pillow](https://pypi.python.org/pypi/Pillow/) 3.0.0+
- [psutil](https://pypi.python.org/pypi/psutil) 3.2.1+ - [psutil](https://pypi.python.org/pypi/psutil) 3.2.1+
- [python-slugify](http://pypi.python.org/pypi/python-slugify) 1.1.4+ - [python-slugify](https://pypi.python.org/pypi/python-slugify) 1.1.4+
- [raven](https://pypi.python.org/pypi/raven) 5.10+
- [scandir](https://pypi.python.org/pypi/scandir) 1.1.0+ _(needed only when using Python 3.3 or 3.4)_ - [scandir](https://pypi.python.org/pypi/scandir) 1.1.0+ _(needed only when using Python 3.3 or 3.4)_
On Debian based distributions these two commands should install all needed dependencies: On Debian based distributions these two commands should install all needed dependencies:
``` ```
sudo apt-get install python3 python3-dev python3-pip python3-pyqt5 libpng-dev libjpeg-dev p7zip-full unrar sudo apt-get install python3 python3-dev python3-pip python3-pyqt5 libpng-dev libjpeg-dev p7zip-full unrar
sudo pip3 install --upgrade pillow python-slugify psutil scandir sudo pip3 install --upgrade pillow python-slugify psutil scandir raven
``` ```
### Optional dependencies ### Optional dependencies
@@ -454,8 +455,6 @@ The app relies and includes the following scripts:
* When MCD metadata are used - Cover download * When MCD metadata are used - Cover download
* When error occurs - Automatic reporting * When error occurs - Automatic reporting
Error report include **KCC** version, OS version and content of error message.
## KNOWN ISSUES ## KNOWN ISSUES
Please check [wiki page](https://github.com/ciromattia/kcc/wiki/Known-issues). Please check [wiki page](https://github.com/ciromattia/kcc/wiki/Known-issues).

6
kcc.py
View File

@@ -56,6 +56,12 @@ elif sys.platform.startswith('win'):
else: else:
os.environ['PATH'] = os.path.dirname(os.path.abspath(__file__)) + '/other/windows/;' + os.environ['PATH'] os.environ['PATH'] = os.path.dirname(os.path.abspath(__file__)) + '/other/windows/;' + os.environ['PATH']
os.chdir(os.path.dirname(os.path.abspath(__file__))) os.chdir(os.path.dirname(os.path.abspath(__file__)))
# Load additional Sentry configuration
if getattr(sys, 'frozen', False):
try:
import kcc.sentry
except:
pass
from kcc.shared import dependencyCheck from kcc.shared import dependencyCheck
dependencyCheck(3) dependencyCheck(3)

View File

@@ -32,6 +32,7 @@ from copy import copy
from distutils.version import StrictVersion from distutils.version import StrictVersion
from xml.sax.saxutils import escape from xml.sax.saxutils import escape
from platform import platform from platform import platform
from raven import Client
from .shared import md5Checksum, HTMLStripper, sanitizeTrace from .shared import md5Checksum, HTMLStripper, sanitizeTrace
from . import __version__ from . import __version__
from . import comic2ebook from . import comic2ebook
@@ -328,6 +329,8 @@ class WorkerThread(QtCore.QThread):
GUI.progress.content = '' GUI.progress.content = ''
self.errors = True self.errors = True
_, _, traceback = sys.exc_info() _, _, traceback = sys.exc_info()
if ' is corrupted.' not in str(err):
GUI.sentry.captureException()
MW.showDialog.emit("Error during conversion %s:\n\n%s\n\nTraceback:\n%s" MW.showDialog.emit("Error during conversion %s:\n\n%s\n\nTraceback:\n%s"
% (jobargv[-1], str(err), sanitizeTrace(traceback)), 'error') % (jobargv[-1], str(err), sanitizeTrace(traceback)), 'error')
MW.addMessage.emit('Error during conversion! Please consult ' MW.addMessage.emit('Error during conversion! Please consult '
@@ -525,6 +528,7 @@ class KCCGUI(KCC_ui.Ui_KCC):
self.editor.loadData(fname) self.editor.loadData(fname)
except Exception as err: except Exception as err:
_, _, traceback = sys.exc_info() _, _, traceback = sys.exc_info()
GUI.sentry.captureException()
self.showDialog("Failed to parse metadata!\n\n%s\n\nTraceback:\n%s" self.showDialog("Failed to parse metadata!\n\n%s\n\nTraceback:\n%s"
% (str(err), sanitizeTrace(traceback)), 'error') % (str(err), sanitizeTrace(traceback)), 'error')
else: else:
@@ -688,31 +692,6 @@ class KCCGUI(KCC_ui.Ui_KCC):
def showDialog(self, message, kind): def showDialog(self, message, kind):
if kind == 'error': if kind == 'error':
QtWidgets.QMessageBox.critical(MW, 'KCC - Error', message, QtWidgets.QMessageBox.Ok) QtWidgets.QMessageBox.critical(MW, 'KCC - Error', message, QtWidgets.QMessageBox.Ok)
try:
doc = Document()
root = doc.createElement('KCCErrorReport')
doc.appendChild(root)
main = doc.createElement('Timestamp')
root.appendChild(main)
text = doc.createTextNode(datetime.fromtimestamp(time()).strftime('%Y-%m-%d %H:%M:%S'))
main.appendChild(text)
main = doc.createElement('OS')
root.appendChild(main)
text = doc.createTextNode(platform())
main.appendChild(text)
main = doc.createElement('Version')
root.appendChild(main)
text = doc.createTextNode(__version__)
main.appendChild(text)
main = doc.createElement('Error')
root.appendChild(main)
text = doc.createTextNode(message)
main.appendChild(text)
urlopen(Request(url='https://kcc.iosphe.re/ErrorHandle/', data=doc.toxml(encoding='utf-8'),
headers={'Content-Type': 'application/xml',
'User-Agent': 'KindleComicConverter/' + __version__}))
except:
pass
elif kind == 'question': elif kind == 'question':
GUI.versionCheck.setAnswer(QtWidgets.QMessageBox.question(MW, 'KCC - Question', message, GUI.versionCheck.setAnswer(QtWidgets.QMessageBox.question(MW, 'KCC - Question', message,
QtWidgets.QMessageBox.Yes, QtWidgets.QMessageBox.Yes,
@@ -915,6 +894,7 @@ class KCCGUI(KCC_ui.Ui_KCC):
self.GammaValue = 1.0 self.GammaValue = 1.0
self.currentMode = 1 self.currentMode = 1
self.targetDirectory = '' self.targetDirectory = ''
self.sentry = Client(release=__version__)
if sys.platform.startswith('darwin'): if sys.platform.startswith('darwin'):
self.listFontSize = 11 self.listFontSize = 11
self.statusBarFontSize = 10 self.statusBarFontSize = 10
@@ -1136,6 +1116,7 @@ class KCCGUI_MetaEditor(KCC_MetaEditor_ui.Ui_MetaEditorDialog):
self.parser.saveXML() self.parser.saveXML()
except Exception as err: except Exception as err:
_, _, traceback = sys.exc_info() _, _, traceback = sys.exc_info()
GUI.sentry.captureException()
GUI.showDialog("Failed to save metadata!\n\n%s\n\nTraceback:\n%s" GUI.showDialog("Failed to save metadata!\n\n%s\n\nTraceback:\n%s"
% (str(err), sanitizeTrace(traceback)), 'error') % (str(err), sanitizeTrace(traceback)), 'error')
self.ui.close() self.ui.close()

View File

@@ -158,6 +158,12 @@ def dependencyCheck(level):
missing.append('PyQt 5.2.1+') missing.append('PyQt 5.2.1+')
except ImportError: except ImportError:
missing.append('PyQt 5.2.1+') missing.append('PyQt 5.2.1+')
try:
from raven import VERSION as ravenVersion
if StrictVersion('5.10') > StrictVersion(ravenVersion):
missing.append('raven 5.10+')
except ImportError:
missing.append('raven 5.10+')
if level > 1: if level > 1:
try: try:
from psutil import __version__ as psutilVersion from psutil import __version__ as psutilVersion