Skip to content

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

Closed

Description

@kunom

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

Activity

  1. added
    needs repro
    on Nov 27, 2024
  2. rchiodo commented on Nov 27, 2024

    @rchiodo
    Contributor

    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.

  3. rchiodo commented on Nov 27, 2024

    @rchiodo
    Contributor

    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

  4. rchiodo commented on Nov 27, 2024

    @rchiodo
    Contributor

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

  5. kunom commented on Nov 28, 2024

    @kunom
    Author

    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

  6. rchiodo commented on Dec 2, 2024

    @rchiodo
    Contributor

    The raised exception error is expected when you have 'justMyCode' set to false. That's an internal error that is always thrown when running.

  7. rchiodo commented on Dec 2, 2024

    @rchiodo
    Contributor

    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.

  8. rchiodo commented on Dec 2, 2024

    @rchiodo
    Contributor

    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.

  9. bartvanandel commented on Dec 3, 2024

    @bartvanandel

    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

Metadata

Metadata

Labels

needs reprouser responded

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions