cknd/stackprinter

Picked an invalid source context

Opened this issue · 4 comments

Ran into a "Picked an invalid source context".

I've only seen this once thus far. On python 3.12.0 with StackPrinter 0.2.12.

Stackprinter failed while formatting <FrameInfo xyz.py, line 2249, scope main>:
  File "venv312/lib/python3.12/site-packages/stackprinter/frame_formatting.py", line 225, in select_scope
    raise Exception("Picked an invalid source context: %s" % info)
Exception: Picked an invalid source context: [2249], [2233], dict_keys([2233, 2234, 2235, 2236, 2237, 2238, 2239])

So here is your original traceback at least:

Traceback (most recent call last):
...
KeyError: 0
cknd commented

you're once again finding the best edge cases!
could you insert a pdb.set_trace() in site-packages/stackprinter/frame_formatting.py line 225 to check on which kind of inputs / source file it happens? (happy to use a private channel too)

The next time, everything worked as intended. This seems likely a lot harder to reproduce...

(I'll add the pdb hook, hoping to see this again)

cknd commented

thanks!
could you place this extended piece of debug code in frame_formatting.py line 222? just to grab as much info as possible in the event it happens again

            if not set(source_lines).issubset(fi.source_map.keys()):
                debug_vals = [self.lines, lineno, source_lines, fi.head_lns, fi.source_map.keys(), fi]
                info = ', '.join(str(p) for p in debug_vals)
                raise Exception("Picked an invalid source context. Debug info: %r" % info)