Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"List index error out of range" when debugger breaks on uncaught exception #1745

Closed
kunom opened this issue Nov 27, 2024 · 8 comments
Closed
Assignees
Labels
needs repro Issue has not been reproduced yet user responded

Comments

@kunom
Copy link

kunom commented Nov 27, 2024

Environment data

  • debugpy version: 1.8.7
  • OS and version: Windows 11
  • 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

@github-actions github-actions bot added the needs repro Issue has not been reproduced yet label Nov 27, 2024
@rchiodo
Copy link
Contributor

rchiodo commented 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
Copy link
Contributor

rchiodo commented Nov 27, 2024

I can't reproduce the issue either.

This is the code I used to reproduce:

i = 0
while True:
    x = 1 / i # Exception thrown here

No output in debug console for me:

Image

@rchiodo
Copy link
Contributor

rchiodo commented Nov 27, 2024

Maybe the exception you're throwing has something to do with the issue. Can you provide a code sample?

@kunom
Copy link
Author

kunom commented Nov 28, 2024

Minimal reproduction see below. The issue is triggered by having the parameters to the query call distributed over multiple lines.

def query(url, params=None, json=True):
    raise Exception("foo")

query(
    "",
    params=None,
    json=False,  # distribute your parameters over multiple lines!
)

Results in:
Image


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:
Image

@rchiodo
Copy link
Contributor

rchiodo commented 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
Copy link
Contributor

rchiodo commented Dec 2, 2024

Thanks, I can reproduce the issue with your query exception. It looks like a bug here:

That code needs to make sure the line numbers are not none before adding it to the summary.

@rchiodo
Copy link
Contributor

rchiodo commented 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.

@rchiodo rchiodo closed this as completed in 3823aba Dec 2, 2024
@bartvanandel
Copy link

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! 🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs repro Issue has not been reproduced yet user responded
Projects
None yet
Development

No branches or pull requests

4 participants