Add system information to traceback, add a new --debug-info command
This commit is contained in:
@@ -112,23 +112,6 @@ def main():
|
|||||||
level=logging.DEBUG,
|
level=logging.DEBUG,
|
||||||
filename=config['log'],
|
filename=config['log'],
|
||||||
format='%(asctime)s:%(levelname)s:%(filename)s:%(lineno)d:%(message)s')
|
format='%(asctime)s:%(levelname)s:%(filename)s:%(lineno)d:%(message)s')
|
||||||
_logger.info('Starting new session, RTV v%s', __version__)
|
|
||||||
_logger.info('%s, %s', sys.executable, sys.version)
|
|
||||||
env = [
|
|
||||||
('$DISPLAY', os.getenv('DISPLAY')),
|
|
||||||
('$TERM', os.getenv('TERM')),
|
|
||||||
('$LANG', os.getenv('LANG')),
|
|
||||||
('$XDG_CONFIG_HOME', os.getenv('XDG_CONFIG_HOME')),
|
|
||||||
('$XDG_DATA_HOME', os.getenv('$XDG_DATA_HOME')),
|
|
||||||
('$RTV_EDITOR', os.getenv('RTV_EDITOR')),
|
|
||||||
('$RTV_URLVIEWER', os.getenv('RTV_URLVIEWER')),
|
|
||||||
('$RTV_BROWSER', RTV_BROWSER),
|
|
||||||
('$BROWSER', BROWSER),
|
|
||||||
('$RTV_PAGER', os.getenv('RTV_PAGER')),
|
|
||||||
('$PAGER', os.getenv('PAGER')),
|
|
||||||
('$VISUAL', os.getenv('VISUAL')),
|
|
||||||
('$EDITOR', os.getenv('EDITOR'))]
|
|
||||||
_logger.info('Environment: %s', env)
|
|
||||||
else:
|
else:
|
||||||
# Add an empty handler so the logger doesn't complain
|
# Add an empty handler so the logger doesn't complain
|
||||||
logging.root.addHandler(logging.NullHandler())
|
logging.root.addHandler(logging.NullHandler())
|
||||||
@@ -152,15 +135,10 @@ def main():
|
|||||||
warnings.warn(text)
|
warnings.warn(text)
|
||||||
config['ascii'] = True
|
config['ascii'] = True
|
||||||
|
|
||||||
_logger.info('RTV module path: %s', os.path.abspath(__file__))
|
|
||||||
|
|
||||||
# Check the praw version
|
|
||||||
if packages.__praw_bundled__:
|
if packages.__praw_bundled__:
|
||||||
_logger.info('Using packaged PRAW distribution, '
|
praw_info = 'packaged, commit {}'.format(packages.__praw_hash__[:12])
|
||||||
'commit %s', packages.__praw_hash__)
|
|
||||||
else:
|
else:
|
||||||
_logger.info('Packaged PRAW not found, falling back to system '
|
praw_info = 'system installed v{}'.format(praw.__version__)
|
||||||
'installed version %s', praw.__version__)
|
|
||||||
|
|
||||||
# Update the webbrowser module's default behavior
|
# Update the webbrowser module's default behavior
|
||||||
patch_webbrowser()
|
patch_webbrowser()
|
||||||
@@ -171,6 +149,38 @@ def main():
|
|||||||
# Construct the reddit user agent
|
# Construct the reddit user agent
|
||||||
user_agent = docs.AGENT.format(version=__version__)
|
user_agent = docs.AGENT.format(version=__version__)
|
||||||
|
|
||||||
|
debug_info = [
|
||||||
|
'rtv version: rtv {}'.format(__version__),
|
||||||
|
'rtv module path: {}'.format(os.path.abspath(__file__)),
|
||||||
|
'python version: {}'.format(sys.version.replace('\n', ' ')),
|
||||||
|
'python executable: {}'.format(sys.executable),
|
||||||
|
'praw version: {}'.format(praw_info),
|
||||||
|
'locale, encoding: {}, {}'.format(default_locale, encoding),
|
||||||
|
'Environment Variables']
|
||||||
|
for name, value in [
|
||||||
|
('BROWSER', BROWSER),
|
||||||
|
('DISPLAY', os.getenv('DISPLAY')),
|
||||||
|
('EDITOR', os.getenv('EDITOR')),
|
||||||
|
('LANG', os.getenv('LANG')),
|
||||||
|
('PAGER', os.getenv('PAGER')),
|
||||||
|
('RTV_BROWSER', RTV_BROWSER),
|
||||||
|
('RTV_EDITOR', os.getenv('RTV_EDITOR')),
|
||||||
|
('RTV_PAGER', os.getenv('RTV_PAGER')),
|
||||||
|
('RTV_URLVIEWER', os.getenv('RTV_URLVIEWER')),
|
||||||
|
('TERM', os.getenv('TERM')),
|
||||||
|
('VISUAL', os.getenv('VISUAL')),
|
||||||
|
('XDG_CONFIG_HOME', os.getenv('XDG_CONFIG_HOME')),
|
||||||
|
('XDG_DATA_HOME', os.getenv('XDG_DATA_HOME')),
|
||||||
|
]:
|
||||||
|
debug_info.append(' {:<16}: {}'.format(name, value or ''))
|
||||||
|
debug_info.append('')
|
||||||
|
debug_text = '\n'.join(debug_info)
|
||||||
|
|
||||||
|
_logger.info(debug_text)
|
||||||
|
if config['debug_info']:
|
||||||
|
print(debug_text)
|
||||||
|
return
|
||||||
|
|
||||||
try:
|
try:
|
||||||
with curses_session() as stdscr:
|
with curses_session() as stdscr:
|
||||||
|
|
||||||
@@ -249,7 +259,14 @@ def main():
|
|||||||
print(e)
|
print(e)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
_logger.exception(e)
|
_logger.exception(e)
|
||||||
raise
|
import traceback
|
||||||
|
exit_message = '\n'.join([
|
||||||
|
debug_text,
|
||||||
|
traceback.format_exc(),
|
||||||
|
'rtv has crashed. Please report this traceback at:',
|
||||||
|
'https://github.com/michael-lazar/rtv/issues\n'])
|
||||||
|
sys.stderr.write(exit_message)
|
||||||
|
return 1 # General error exception code
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
pass
|
pass
|
||||||
finally:
|
finally:
|
||||||
|
|||||||
@@ -84,6 +84,9 @@ def build_parser():
|
|||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'--no-flash', dest='flash', action='store_const', const=False,
|
'--no-flash', dest='flash', action='store_const', const=False,
|
||||||
help='Disable screen flashing')
|
help='Disable screen flashing')
|
||||||
|
parser.add_argument(
|
||||||
|
'--debug-info', dest='debug_info', action='store_const', const=True,
|
||||||
|
help='Show system and environment information and exit')
|
||||||
return parser
|
return parser
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user