Skip to content

Commit 86cd1ca

Browse files
glennguyandybotting
authored andcommitted
Ensure debug mode is enabled for user reports. (#8)
This should hopefully stop the stream of unhelpful reports. There is now a dialog yes/no to confirm creating the issue/uploading log. Plently of issues have undoubtedly come from curious users checking any setting they can. Some issues have also been failing to submit due to the unicode error that caused the issue also causing the issue reporter to fail. It seems to always be from unicode contained in large JSON or XML files which is included in the exception args. When the issue formatter tries to split the exception data on newlines there is then a list hundreds of items long that is passed to the xbmcgui Dialog object which only takes a max of 3, causing failure. We now omit the data which caused the exception which is ok because ther is enough information in the log to get to the source which caused it including the position of the offending unicode character.
1 parent 7246d74 commit 86cd1ca

File tree

2 files changed

+35
-6
lines changed

2 files changed

+35
-6
lines changed

lib/aussieaddonscommon/issue_reporter.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,9 @@ def is_reportable(exc_type, exc_value, exc_traceback):
157157
"""
158158

159159
# AttributeError: global name 'foo' is not defined
160-
error = '%s: %s' % (exc_type.__name__, ', '.join(exc_value.args))
160+
error = '%s: %s' % (
161+
exc_type.__name__, ', '.join(
162+
utils.ensure_ascii(x) for x in exc_value.args))
161163

162164
# Don't show any dialogs when user cancels
163165
if exc_type.__name__ == 'SystemExit':

lib/aussieaddonscommon/utils.py

+32-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import htmlentitydefs
2+
import json
23
import os
34
import re
45
import sys
@@ -116,10 +117,14 @@ def format_error_summary():
116117
error message.
117118
"""
118119
exc_type, exc_value, exc_traceback = sys.exc_info()
120+
121+
args = list(exc_value)
122+
if exc_type == UnicodeEncodeError:
123+
args.pop(1) # remove error data, likely to be very long xml
119124
return "%s (%d) - %s: %s" % (
120125
os.path.basename(exc_traceback.tb_frame.f_code.co_filename),
121126
exc_traceback.tb_lineno, exc_type.__name__,
122-
', '.join(exc_value.args))
127+
', '.join([ensure_ascii(x) for x in args]))
123128

124129

125130
def log_error(message=None):
@@ -246,8 +251,24 @@ def is_valid_country(connection_info, message=None):
246251
return True
247252

248253

254+
def is_debug():
255+
try:
256+
json_query = ('{"jsonrpc":"2.0","id":1,"method":'
257+
'"Settings.GetSettingValue","params":'
258+
'{"setting":"debug.showloginfo"}}')
259+
result = json.loads(xbmc.executeJSONRPC(json_query))
260+
return result['result']['value']
261+
except RuntimeError:
262+
return True
263+
264+
249265
def user_report():
250-
send_report('User initiated report', user_initiated=True)
266+
if is_debug():
267+
send_report('User initiated report', user_initiated=True)
268+
else:
269+
dialog_message(['Debug logging not enabled. '
270+
'Please enable debug logging, restart Kodi, '
271+
'recreate the issue and try again.'])
251272

252273

253274
def send_report(title, trace=None, connection_info=None, user_initiated=False):
@@ -261,14 +282,20 @@ def send_report(title, trace=None, connection_info=None, user_initiated=False):
261282
if user_initiated:
262283
if not is_valid_country(connection_info):
263284
return
264-
285+
if not xbmcgui.Dialog().yesno('{0} v{1}'.format(
286+
get_addon_name(), get_addon_version()),
287+
'Please confirm you would like to submit an issue report '
288+
'and upload your logfile to Github. '):
289+
return
265290
# Show dialog spinner, and close afterwards
266291
xbmc.executebuiltin("ActivateWindow(busydialog)")
267292
report_url = issue_reporter.report_issue(title, trace, connection_info)
268293

269294
split_url = report_url.replace('/issue-reports', ' /issue-reports')
270295
dialog_message(['Thanks! Your issue has been reported to: ',
271-
split_url])
296+
split_url,
297+
'Please visit and describe the issue in order for '
298+
'us to assist.'])
272299
return report_url
273300
except Exception:
274301
traceback.print_exc()
@@ -298,7 +325,7 @@ def handle_error(message):
298325

299326
# AttributeError: global name 'foo' is not defined
300327
error = '%s: %s' % (exc_type.__name__,
301-
', '.join(str(e) for e in exc_value.args))
328+
', '.join(ensure_ascii(e) for e in exc_value.args))
302329

303330
message = format_dialog_error(message)
304331

0 commit comments

Comments
 (0)