Skip to content

Commit

Permalink
Replaced own error reporting mechanism with Sentry
Browse files Browse the repository at this point in the history
  • Loading branch information
AcidWeb committed Feb 18, 2016
1 parent c9cf635 commit 189c035
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 30 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ kindlegen*
*.spec
setup.bat
setup.sh
kcc/sentry.py
9 changes: 4 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
- Python 3.3+
- [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+
- [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)_

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 pip3 install --upgrade pillow python-slugify psutil scandir
sudo pip3 install --upgrade pillow python-slugify psutil scandir raven
```

### Optional dependencies
Expand Down Expand Up @@ -454,8 +455,6 @@ The app relies and includes the following scripts:
* When MCD metadata are used - Cover download
* When error occurs - Automatic reporting

Error report include **KCC** version, OS version and content of error message.

## KNOWN ISSUES
Please check [wiki page](https://github.com/ciromattia/kcc/wiki/Known-issues).

Expand Down
6 changes: 6 additions & 0 deletions kcc.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@ def __init__(self, *args, **kw):
else:
os.environ['PATH'] = os.path.dirname(os.path.abspath(__file__)) + '/other/windows/;' + os.environ['PATH']
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
dependencyCheck(3)
Expand Down
31 changes: 6 additions & 25 deletions kcc/KCC_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
from distutils.version import StrictVersion
from xml.sax.saxutils import escape
from platform import platform
from raven import Client
from .shared import md5Checksum, HTMLStripper, sanitizeTrace
from . import __version__
from . import comic2ebook
Expand Down Expand Up @@ -328,6 +329,8 @@ def run(self):
GUI.progress.content = ''
self.errors = True
_, _, 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"
% (jobargv[-1], str(err), sanitizeTrace(traceback)), 'error')
MW.addMessage.emit('Error during conversion! Please consult '
Expand Down Expand Up @@ -525,6 +528,7 @@ def selectFileMetaEditor(self):
self.editor.loadData(fname)
except Exception as err:
_, _, traceback = sys.exc_info()
GUI.sentry.captureException()
self.showDialog("Failed to parse metadata!\n\n%s\n\nTraceback:\n%s"
% (str(err), sanitizeTrace(traceback)), 'error')
else:
Expand Down Expand Up @@ -688,31 +692,6 @@ def addMessage(self, message, icon, replace=False):
def showDialog(self, message, kind):
if kind == 'error':
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':
GUI.versionCheck.setAnswer(QtWidgets.QMessageBox.question(MW, 'KCC - Question', message,
QtWidgets.QMessageBox.Yes,
Expand Down Expand Up @@ -915,6 +894,7 @@ def __init__(self, KCCAplication, KCCWindow):
self.GammaValue = 1.0
self.currentMode = 1
self.targetDirectory = ''
self.sentry = Client(release=__version__)
if sys.platform.startswith('darwin'):
self.listFontSize = 11
self.statusBarFontSize = 10
Expand Down Expand Up @@ -1136,6 +1116,7 @@ def saveData(self):
self.parser.saveXML()
except Exception as err:
_, _, traceback = sys.exc_info()
GUI.sentry.captureException()
GUI.showDialog("Failed to save metadata!\n\n%s\n\nTraceback:\n%s"
% (str(err), sanitizeTrace(traceback)), 'error')
self.ui.close()
Expand Down
6 changes: 6 additions & 0 deletions kcc/shared.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,12 @@ def dependencyCheck(level):
missing.append('PyQt 5.2.1+')
except ImportError:
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:
try:
from psutil import __version__ as psutilVersion
Expand Down

0 comments on commit 189c035

Please sign in to comment.