add error submission prompt

This commit is contained in:
Shaun
2017-12-16 12:55:28 +11:00
parent 33b1e3f766
commit 03a2026732
8 changed files with 142 additions and 4 deletions

View File

@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<addon id="plugin.video.embycon"
name="EmbyCon"
version="1.4.2"
version="1.4.3"
provider-name="Team B">
<requires>
<import addon="xbmc.python" version="2.24.0"/>

View File

@@ -657,3 +657,11 @@ msgstr ""
msgctxt "#30310"
msgid "Enable Emby remote control"
msgstr ""
msgctxt "#30311"
msgid "EmbyCon encountered an error!"
msgstr ""
msgctxt "#30312"
msgid "Do you want to send this error to the devs?"
msgstr ""

121
resources/lib/error.py Normal file
View File

@@ -0,0 +1,121 @@
import traceback
import sys
import os
import httplib
import json
import xbmcgui
import xbmc
from simple_logging import SimpleLogging
from clientinfo import ClientInformation
from translation import i18n
log = SimpleLogging(__name__)
def catch_except(errors=(Exception, ), default_value=False):
# Will wrap method with try/except and print parameters for easier debugging
def decorator(func):
def wrapper(*args, **kwargs):
try:
return func(*args, **kwargs)
except errors as error:
if not (hasattr(error, 'quiet') and error.quiet):
return_value = xbmcgui.Dialog().yesno(i18n('error'), i18n('embycon_error'), i18n('embycon_error_submit'))
if return_value:
log.debug("Sending Error Data")
try:
submit_error_data()
except Exception as error:
log.debug("Sending Error Data Failed: " + str(error))
return default_value
return wrapper
return decorator
def submit_error_data():
error_type, error_short, error_stack = format_exception()
data = {}
data["event"] = "ErrorReport"
data["error_stack"] = error_stack
data["error_type"] = error_type
data["error_short"] = error_short
data["sys.argv"] = sys.argv
data["kodi_version"] = xbmc.getInfoLabel("System.BuildVersion")
data["addon_version"] = ClientInformation().getVersion()
post_data = json.dumps(data)
log.debug("ERROR_DATA: " + post_data)
server = "allthedata.pythonanywhere.com"
url_path = "/submit"
conn = httplib.HTTPConnection(server, timeout=40)
head = {}
head["Content-Type"] = "application/json"
conn.request(method="POST", url=url_path, body=post_data, headers=head)
data = conn.getresponse()
log.debug("Submit Responce Code: " + str(data.status))
def format_exception():
stack = traceback.extract_stack()
exc_type, exc_obj, exc_tb = sys.exc_info()
stack_trace_data = traceback.format_tb(exc_tb)
tb = traceback.extract_tb(exc_tb)
full_tb = stack[:-1] + tb
# log.error(str(full_tb))
# get last stack frame
latestStackFrame = None
if (len(tb) > 0):
latestStackFrame = tb[-1]
# log.error(str(tb))
fileStackTrace = ""
try:
# get files from stack
stackFileList = []
for frame in full_tb:
# log.error(str(frame))
frameFile = (os.path.split(frame[0])[1])[:-3]
frameLine = frame[1]
if (len(stackFileList) == 0 or stackFileList[-1][0] != frameFile):
stackFileList.append([frameFile, [str(frameLine)]])
else:
file = stackFileList[-1][0]
lines = stackFileList[-1][1]
lines.append(str(frameLine))
stackFileList[-1] = [file, lines]
# log.error(str(stackFileList))
for item in stackFileList:
lines = ",".join(item[1])
fileStackTrace += item[0] + "," + lines + ":"
# log.error(str(fileStackTrace))
except Exception as e:
fileStackTrace = None
log.error(e)
errorType = "NA"
errorFile = "NA"
if latestStackFrame is not None:
if fileStackTrace is None:
fileStackTrace = os.path.split(latestStackFrame[0])[1] + ":" + str(latestStackFrame[1])
codeLine = "NA"
if (len(latestStackFrame) > 3 and latestStackFrame[3] != None):
codeLine = latestStackFrame[3].strip()
errorFile = "%s(%s)(%s)" % (fileStackTrace, exc_obj.message, codeLine)
errorFile = errorFile[0:499]
errorType = "%s" % (exc_type.__name__)
# log.error(errorType + " - " + errorFile)
del (exc_type, exc_obj, exc_tb)
return errorType, errorFile, stack_trace_data

View File

@@ -15,6 +15,7 @@ import xbmcgui
import xbmcaddon
import xbmc
from resources.lib.error import catch_except
from downloadutils import DownloadUtils
from utils import getDetailsString, getArt, cache_artwork
from kodi_utils import HomeWindow
@@ -43,6 +44,7 @@ downloadUtils = DownloadUtils()
dataManager = DataManager()
@catch_except()
def mainEntryPoint():
log.debug("===== EmbyCon START =====")

View File

@@ -9,6 +9,7 @@ import time
import json
import hashlib
from resources.lib.error import catch_except
from simple_logging import SimpleLogging
from downloadutils import DownloadUtils
from resume_dialog import ResumeDialog
@@ -20,7 +21,7 @@ from json_rpc import json_rpc
log = SimpleLogging(__name__)
downloadUtils = DownloadUtils()
@catch_except()
def playFile(play_info):
id = play_info.get("item_id")

View File

@@ -117,5 +117,7 @@ STRINGS = {
'playback_starting_': 30306,
'play_trailer': 30307,
'select_trailer': 30308,
'select_source': 30309
'select_source': 30309,
'embycon_error': 30311,
'embycon_error_submit': 30312
}

View File

@@ -12,12 +12,14 @@ from utils import getArt
from datamanager import DataManager
from simple_logging import SimpleLogging
from kodi_utils import HomeWindow
from resources.lib.error import catch_except
log = SimpleLogging(__name__)
downloadUtils = DownloadUtils()
dataManager = DataManager()
kodi_version = int(xbmc.getInfoLabel('System.BuildVersion')[:2])
@catch_except()
def checkForNewContent():
log.debug("checkForNewContent Called")

View File

@@ -8,6 +8,7 @@ import time
import json
import traceback
from resources.lib.error import catch_except
from resources.lib.downloadutils import DownloadUtils
from resources.lib.simple_logging import SimpleLogging
from resources.lib.play_utils import playFile
@@ -77,6 +78,7 @@ def sendProgress():
url = "{server}/emby/Sessions/Playing/Progress"
download_utils.downloadUrl(url, postBody=postdata, method="POST")
@catch_except()
def promptForStopActions(item_id, current_possition):
settings = xbmcaddon.Addon(id='plugin.video.embycon')
@@ -181,7 +183,7 @@ def promptForStopActions(item_id, current_possition):
break
@catch_except()
def stopAll(played_information):
if len(played_information) == 0:
return