Dump also the deeper frames, not just the get_items one

This commit is contained in:
JustAnotherArchivist
2019-05-16 22:48:35 +00:00
parent 9c8bbf051c
commit 9e6538556a

View File

@@ -18,15 +18,17 @@ def _dump_locals_on_exception():
except Exception as e:
trace = inspect.trace()
if len(trace) >= 3:
frameRecord = inspect.trace()[2]
locals_ = frameRecord[0].f_locals
with tempfile.NamedTemporaryFile('w', prefix = 'snscrape_locals_', delete = False) as fp:
fp.write(f'Locals from file "{frameRecord.filename}", line {frameRecord.lineno}, in {frameRecord.function}:\n')
fp.write(repr(locals_))
fp.write('\n')
if 'self' in locals_ and hasattr(locals_['self'], '__dict__'):
fp.write(f'Object dict:\n')
fp.write(repr(locals_['self'].__dict__))
for i in range(2, len(trace)):
frameRecord = trace[i]
locals_ = frameRecord[0].f_locals
fp.write(f'Locals from file "{frameRecord.filename}", line {frameRecord.lineno}, in {frameRecord.function}:\n')
fp.write(repr(locals_))
fp.write('\n')
if 'self' in locals_ and hasattr(locals_['self'], '__dict__'):
fp.write(f'Object dict:\n')
fp.write(repr(locals_['self'].__dict__))
fp.write('\n\n')
logger.fatal(f'Local variables logged to {fp.name}')
raise