microsoft / PTVS

Python Tools for Visual Studio
https://aka.ms/PTVS
Apache License 2.0
2.53k stars 674 forks source link

Visual Studio 2022 keeps breaking on exception which seems to be handled in Python internally #7520

Closed anjav-isystem closed 2 months ago

anjav-isystem commented 1 year ago

This issue is still present, it was closed since it got no response in 30 days :(

@int19h I already tried disabling all exceptions in the Debug -> Windows -> Exception Settings, but this exception still breaks the debug session. So at the moment we don't have any functional workaround for this (apart from hitting run many times each session).

I'm attaching a screenshot as proof: Screenshot

Originally posted by @anjav-isystem in https://github.com/microsoft/PTVS/issues/7442#issuecomment-1467977490

int19h commented 1 year ago

So the problem is that the checkboxes in the Exceptions tool window correspond to "on throw" exception filters (i.e. raise as soon as exception happens), but the debugger actually has two other categories: "on unhandled" (when it escapes out of the top-level code) and "on user-unhandled" (when it escapes from library code to your code). And by default, VS enables the latter for all Python exceptions, hence why it's breaking.

It used to be that the Exceptions window had a mode that showed multiple checkboxes allowing to tweak this stuff, but it doesn't look like that's there anymore. We need to investigate and figure out how the filters work with the new UX.

dzenanz commented 1 year ago

I am running in the same issue. Except, in my case, I have to hit run hundreds if not thousands of times. The library I am using has lazy loading, and for each symbol that needs to be loaded I get an exception, with stack trace looking something like this:

module 'itk' has no attribute '_itkImageToImageFilterAPython'
Stack trace:
 >  File "C:\Dev\ITK-py11\Wrapping\Generators\Python\itk\support\lazy.py", line 131, in __getattribute__
 >    value = types.ModuleType.__getattribute__(self, attr)
 >            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 >  File "C:\Dev\ITK-py11\Wrapping\Generators\Python\itk\itkImageToImageFilterAPython.py", line 27, in <module>
 >    from . import _itkImageToImageFilterAPython
 >  File "C:\Dev\ITK-py11\Wrapping\Generators\Python\itk\itkStreamingImageFilterPython.py", line 82, in <module>
 >    import itk.itkImageToImageFilterAPython
 >  File "C:\Dev\ITK-py11\Wrapping\Generators\Python\itk\ITKCommonPython.py", line 70, in <module>
 >    from itk.itkStreamingImageFilterPython import *
 >  File "C:\Dev\ITK-py11\Wrapping\Generators\Python\itk\support\base.py", line 291, in load
 >    l_spec.loader.exec_module(l_module)  # pytype: disable=attribute-error
 >  File "C:\Dev\ITK-py11\Wrapping\Generators\Python\itk\support\base.py", line 132, in itk_load_swig_module
 >    l_module = loader.load(swig_module_name)
 >  File "C:\Dev\ITK-py11\Wrapping\Generators\Python\itk\support\base.py", line 96, in itk_load_swig_module
 >    itk_load_swig_module(dep, namespace)
 >  File "C:\Dev\ITK-py11\Wrapping\Generators\Python\itk\support\base.py", line 96, in itk_load_swig_module
 >    itk_load_swig_module(dep, namespace)
 >  File "C:\Dev\ITK-py11\Wrapping\Generators\Python\itk\support\base.py", line 96, in itk_load_swig_module
 >    itk_load_swig_module(dep, namespace)
 >  File "C:\Dev\ITK-py11\Wrapping\Generators\Python\itk\support\lazy.py", line 138, in __getattribute__
 >    base.itk_load_swig_module(module, namespace)
 >  File "C:\Dev\ITKUltrasound\wrapping\test\PythonPhasedArray3DResample.py", line 39, in <module>
 >    image_type = itk.PhasedArray3DSpecialCoordinatesImage[pixel_type]
 >AttributeError: module 'itk' has no attribute '_itkImageToImageFilterAPython'
Loaded 'itk.itkImageToImageFilterAPython'

If I detach the debugger, the script finishes without exceptions.

dzenanz commented 1 year ago

I am quite convinced this was not a problem until recently. I also remember the existence of the option to "not break for this exception", which I can't find now.

flexorx commented 1 year ago

I am experiencing same issues. I raise an exception which is handleded in the same file. Though, debugger always breaks on its "raise". Tampering with this type of exception in "Exception Settings" leads to pretty much nothing, as if this window has nothing to do with the actual runtime environment at all. It is very annoying and so far I have to just not debug at all.

flexorx commented 1 year ago

It used to be that the Exceptions window had a mode that showed multiple checkboxes allowing to tweak this stuff, but it doesn't look like that's there anymore. We need to investigate and figure out how the filters work with the new UX.

Is it possible to escalate it to VS team? I find the absence of this selection annoying. I don't see any good reason for it to be ditched.

fredlllll commented 8 months ago

So the problem is that the checkboxes in the Exceptions tool window correspond to "on throw" exception filters (i.e. raise as soon as exception happens), but the debugger actually has two other categories: "on unhandled" (when it escapes out of the top-level code) and "on user-unhandled" (when it escapes from library code to your code). And by default, VS enables the latter for all Python exceptions, hence why it's breaking.

It used to be that the Exceptions window had a mode that showed multiple checkboxes allowing to tweak this stuff, but it doesn't look like that's there anymore. We need to investigate and figure out how the filters work with the new UX.

please if you can, throw a book at whoever decided to remove these checkboxes. im facing a similar issue that would be fixed by adding checkboxes for all 3 options back. i had threads just silently exit till i forced it to break on all exceptions, but now it breaks on every exception, even when i handle it in my code. so there seems to be no satisfactory setting that i can keep, and i will have to switch back and forth every time i run into issues

cunnane commented 5 months ago

This seems to have a resolution: in the Visual Studio exception settings window, you can right click and choose "Continue when unhandled in user code"

cwebster-99 commented 2 months ago

Thanks for the report - it seems that there is a suitable workaround added back into the UI. I am going to close this in favor of that workaround posted above. Please let me know if an issue still persists and the team can readdress from there.

davidair commented 1 week ago

I do not see the "Continue when unhandled in user code" option in Version 17.11.2. The only right-click options in the Exception Settings window are "Add", "Delete", "Edit Conditions" and "Restore Defaults".

Image