Added major_exception()

This commit is contained in:
2Shirt 2019-07-25 21:34:22 -06:00
parent 1829c3b2f3
commit f1d53e698b
Signed by: 2Shirt
GPG key ID: 152FAC923B0E132C

View file

@ -7,8 +7,9 @@ import os
import re
import sys
import time
import traceback
from wk.cfg.main import CRASH_SERVER
from wk.cfg.main import CRASH_SERVER, ENABLED_UPLOAD_DATA, SUPPORT_MESSAGE
try:
from termios import tcflush, TCIOFLUSH
@ -172,6 +173,37 @@ def input_text(prompt='Enter text'):
return response
def major_exception():
"""Display traceback, optionally upload detailes, and exit."""
LOG.critical('Major exception encountered', exc_info=True)
print_error('Major exception')
print_warning(SUPPORT_MESSAGE)
print(traceback.format_exc())
# Build report
## TODO
report = 'TODO\n'
# Upload details
prompt = 'Upload details to {}?'.format(
CRASH_SERVER.get('Name', '?'),
)
if ENABLED_UPLOAD_DATA and ask(prompt):
print('Uploading... ', end='', flush=True)
try:
upload_debug_report(report, reason='CRASH')
except Exception: #pylint: disable=broad-except
print_colored(['FAILED'], ['RED'])
LOG.error('Upload failed')
else:
print_success('SUCCESS')
LOG.info('Upload successful')
# Done
pause('Press Enter to exit... ')
raise SystemExit(1)
def pause(prompt='Press Enter to continue... '):
"""Simple pause implementation."""
input_text(prompt)