mirror of
https://github.com/bellingcat/snscrape.git
synced 2026-06-12 20:38:29 +03:00
Fix crash in locals dumping on module-less frames
This commit is contained in:
@@ -133,12 +133,22 @@ def _dump_stack_and_locals(trace, exc = None):
|
|||||||
fp.write('Stack:\n')
|
fp.write('Stack:\n')
|
||||||
for frameRecord in trace:
|
for frameRecord in trace:
|
||||||
fp.write(f' File "{frameRecord.filename}", line {frameRecord.lineno}, in {frameRecord.function}\n')
|
fp.write(f' File "{frameRecord.filename}", line {frameRecord.lineno}, in {frameRecord.function}\n')
|
||||||
for line in frameRecord.code_context:
|
if frameRecord.code_context is not None:
|
||||||
fp.write(f' {line.strip()}\n')
|
for line in frameRecord.code_context:
|
||||||
|
fp.write(f' {line.strip()}\n')
|
||||||
fp.write('\n')
|
fp.write('\n')
|
||||||
|
|
||||||
for frameRecord in trace:
|
modules = [inspect.getmodule(frameRecord[0]) for frameRecord in trace]
|
||||||
module = inspect.getmodule(frameRecord[0])
|
for i, (module, frameRecord) in enumerate(zip(modules, trace)):
|
||||||
|
if module is None:
|
||||||
|
# Module-less frame, e.g. dataclass.__init__
|
||||||
|
for j in reversed(range(i)):
|
||||||
|
if modules[j] is not None:
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
# No previous module scope
|
||||||
|
continue
|
||||||
|
module = modules[j]
|
||||||
if not module.__name__.startswith('snscrape.') and module.__name__ != 'snscrape':
|
if not module.__name__.startswith('snscrape.') and module.__name__ != 'snscrape':
|
||||||
continue
|
continue
|
||||||
locals_ = frameRecord[0].f_locals
|
locals_ = frameRecord[0].f_locals
|
||||||
|
|||||||
Reference in New Issue
Block a user