You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
"List index error out of range" when debugger breaks on uncaught exception #1745
Python version (& distribution if applicable, e.g. Anaconda): 3.13.0, downloaded from python.org
Using VS Code or Visual Studio: VS Code
Actual behavior
When the debugger breaks on an exception, the following output appears in the terminal:
2.79s - Error on build_exception_info_response.
Traceback (most recent call last):
File "c:\Users\mek\.vscode\extensions\ms-python.debugpy-2024.12.0-win32-x64\bundled\libs\debugpy\_vendored\pydevd\_pydevd_bundle\pydevd_comm.py", line 1533, in build_exception_info_response
stack_str = "".join(stack_summary.format())
~~~~~~~~~~~~~~~~~~~~^^
File "c:\Program Files\Python313\Lib\traceback.py", line 749, in format
formatted_frame = self.format_frame_summary(frame_summary, colorize=colorize)
File "c:\Program Files\Python313\Lib\traceback.py", line 553, in format_frame_summary
last_line = all_lines_original[frame_summary.end_lineno - frame_summary.lineno]
~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
IndexError: list index out of range
Expected behavior
The output distracts. Also, there might be functional degradation.
Steps to reproduce:
In Visual Studio Code, enable "halt on exception", F5-debug a file that throws an exception
Minimal reproduction see below. The issue is triggered by having the parameters to the query call distributed over multiple lines.
defquery(url, params=None, json=True):
raiseException("foo")
query(
"",
params=None,
json=False, # distribute your parameters over multiple lines!
)
Results in:
By the way, but maybe not related, if you select "break on raised exception", it tries to load a packed variant of the standard library, which does not exist:
Actually, it was slightly more complicated. Not sure how this worked in 3.11 and 3.12 but the frame summaries we were generating didn't have the correct line text.
Thanks for this fix! Just yesterday I ran into this as well when debugging some python code suffering from a circular import chain. I just monkey-patched the installed ms-python.debugpy extension with this fix, and it resolved the issue (after cleaning any __pycache__ dirs and restarting the extension host). I'm hoping for a quick release of that extension, thanks! 🚀
Activity
rchiodo commentedon Nov 27, 2024
That error looks like a bug in Python itself, not the debugger. The traceback module shouldn't throw an exception when asking for a format.
rchiodo commentedon Nov 27, 2024
I can't reproduce the issue either.
This is the code I used to reproduce:
No output in debug console for me:
rchiodo commentedon Nov 27, 2024
Maybe the exception you're throwing has something to do with the issue. Can you provide a code sample?
kunom commentedon Nov 28, 2024
Minimal reproduction see below. The issue is triggered by having the parameters to the
querycall distributed over multiple lines.Results in:

By the way, but maybe not related, if you select "break on raised exception", it tries to load a packed variant of the standard library, which does not exist:

rchiodo commentedon Dec 2, 2024
The raised exception error is expected when you have 'justMyCode' set to false. That's an internal error that is always thrown when running.
rchiodo commentedon Dec 2, 2024
Thanks, I can reproduce the issue with your query exception. It looks like a bug here:
debugpy/src/debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_comm.py
Line 1527 in f4ba976
That code needs to make sure the line numbers are not none before adding it to the summary.
Fix problem with lineno being none when generating traceback
rchiodo commentedon Dec 2, 2024
Actually, it was slightly more complicated. Not sure how this worked in 3.11 and 3.12 but the frame summaries we were generating didn't have the correct line text.
bartvanandel commentedon Dec 3, 2024
Thanks for this fix! Just yesterday I ran into this as well when debugging some python code suffering from a circular import chain. I just monkey-patched the installed
ms-python.debugpyextension with this fix, and it resolved the issue (after cleaning any__pycache__dirs and restarting the extension host). I'm hoping for a quick release of that extension, thanks! 🚀Fix problem with lineno being none when generating traceback (microso…