Skip to content

Chained exception does not show cause message #1024

@parched

Description

@parched

I'm not really sure if this is a bug or a feature request or if this should be raised in vscode-python instead but it appears related to #391

Environment data

  • debugpy version: 1.6.3
  • OS and version: Windows 10
  • Python version (& distribution if applicable, e.g. Anaconda): Python 3.10
  • Using VS Code or Visual Studio: VS Code

Actual behavior

When a chained exception is caught it doesn't show the cause message, even though it shows the stack trace and says it was the cause.

image

Expected behavior

I think it should show:

  1. The cause message
  2. The cause stack trace
  3. The above exception was the direct cause of the following exception:

  4. The message
  5. The stack trace

Alternatively 1 and 2 could be swapped as well as 4 and 5 swapped which would match what I see in the output:

Traceback (most recent call last):
  File "c:\Users\james.duley\dev\design-library-2\py-lib\src\holmes_design\junk.py", line 3, in <module>
    print(empty_dict["key"])
KeyError: 'key'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "C:\Users\james.duley\AppData\Local\Programs\Python\Python310\lib\runpy.py", line 196, in _run_module_as_main    return _run_code(code, main_globals, None,
  File "C:\Users\james.duley\AppData\Local\Programs\Python\Python310\lib\runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "c:\Users\james.duley\.vscode\extensions\ms-python.python-2022.13.12301015\pythonFiles\lib\python\debugpy\__main__.py", line 39, in <module>
    cli.main()
  File "c:\Users\james.duley\.vscode\extensions\ms-python.python-2022.13.12301015\pythonFiles\lib\python\debugpy/..\debugpy\server\cli.py", line 430, in main
    run()
  File "c:\Users\james.duley\.vscode\extensions\ms-python.python-2022.13.12301015\pythonFiles\lib\python\debugpy/..\debugpy\server\cli.py", line 284, in run_file
    runpy.run_path(target, run_name="__main__")
  File "c:\Users\james.duley\.vscode\extensions\ms-python.python-2022.13.12301015\pythonFiles\lib\python\debugpy\_vendored\pydevd\_pydevd_bundle\pydevd_runpy.py", line 321, in run_path
    return _run_module_code(code, init_globals, run_name,
  File "c:\Users\james.duley\.vscode\extensions\ms-python.python-2022.13.12301015\pythonFiles\lib\python\debugpy\_vendored\pydevd\_pydevd_bundle\pydevd_runpy.py", line 135, in _run_module_code
    _run_code(code, mod_globals, init_globals,
  File "c:\Users\james.duley\.vscode\extensions\ms-python.python-2022.13.12301015\pythonFiles\lib\python\debugpy\_vendored\pydevd\_pydevd_bundle\pydevd_runpy.py", line 124, in _run_code
    exec(code, run_globals)
  File "c:\Users\james.duley\dev\design-library-2\py-lib\src\holmes_design\junk.py", line 5, in <module>
    raise Exception("Something went wrong") from e
Exception: Something went wrong

Steps to reproduce:

  1. Run this code in debug mode in VS Code with "Uncaught Exceptions" breakpoint enabled
empty_dict = {}
try:
    print(empty_dict["key"])
except KeyError as e:
    raise Exception("Something went wrong") from e

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions