microsoft / vscode-python

Python extension for Visual Studio Code
https://aka.ms/pvsc-marketplace
MIT License
4.34k stars 1.19k forks source link

Unable to debug if script file path contains certain characters #23269

Open manjuu-eater opened 7 months ago

manjuu-eater commented 7 months ago

Type: Bug

Behaviour

If the Python file path contains certain Unicode characters, the characters disappear when passing the path to the terminal on debug.

This behavior only occurs when the terminal is PowerShell. With using cmd.exe as terminal, this behavior does not occur.

This behavior seems to be caused by a bug on the PowerShell side. If you drop a file into PowerShell window (or PoserShell in the terminal panel), you can see that certain Unicode characters disappear from the path. Characters don't disappear when pasting a string from clipboard. If module PSReadline is not loaded in PowerShell, this disappearance with dropping file does not occurs. (This bug is caused by module PSReadline.) 24/04/23 Added: Similarly, if PSReadline is not loaded in PowerShell on VS Code, characters all remain.

Output on the terminal is below:

PS C:\Users\User\Desktop\○_testing\vscode_test>  & 'c:\Program Files\Python310\python.exe' 'c:\Users\User\.vscode\extensions\ms-python.debugpy-2024.4.0-win32-x64\bundled\libs\debugpy\adapter/../..\debugpy\launcher' '51147' '--' 'C:\Users\User\Desktop\_testing\vscode_test\test.py'
Traceback (most recent call last):
  File "c:\Program Files\Python310\lib\runpy.py", line 196, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "c:\Program Files\Python310\lib\runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "c:\Users\User\.vscode\extensions\ms-python.debugpy-2024.4.0-win32-x64\bundled\libs\debugpy\__main__.py", line 39, in <module>
    cli.main()
  File "c:\Users\User\.vscode\extensions\ms-python.debugpy-2024.4.0-win32-x64\bundled\libs\debugpy/..\debugpy\server\cli.py", line 430, in main    
    run()
  File "c:\Users\User\.vscode\extensions\ms-python.debugpy-2024.4.0-win32-x64\bundled\libs\debugpy/..\debugpy\server\cli.py", line 284, in run_file
    runpy.run_path(target, run_name="__main__")
  File "c:\Users\User\.vscode\extensions\ms-python.debugpy-2024.4.0-win32-x64\bundled\libs\debugpy\_vendored\pydevd\_pydevd_bundle\pydevd_runpy.py", line 320, in run_path
    code, fname = _get_code_from_file(run_name, path_name)
  File "c:\Users\User\.vscode\extensions\ms-python.debugpy-2024.4.0-win32-x64\bundled\libs\debugpy\_vendored\pydevd\_pydevd_bundle\pydevd_runpy.py", line 289, in _get_code_from_file
    with io_open_code(decoded_path) as f:
FileNotFoundError: [Errno 2] No such file or directory: 'C:\\Users\\User\\Desktop\\_testing\\vscode_test\\test.py'
PS C:\Users\User\Desktop\○_testing\vscode_test> 

24/04/23 Edited: The terminal output example was incorrect, so I corrected it to the actual output. For more information: issuecomment-2071898101

You can see that the Unicode character "○" is missing from passed path. Directory name ○_testing in the path changed to _testing, but there is no such directory.

Steps to reproduce:

  1. Prepare a Python file which contains a character "○" in the path
  2. Try to debug the Python file
  3. Fails to debug because the path passed has changed.
Characters that disappear

。「」、・ヲァィゥェォャュョッ ・゛゜´¨―‐∥…‥‘’“”±×÷≠≦≧∞∴♂♀°′″℃§☆★○●◎◇◆□■△▲▽▼※→←↑↓∈∋⊆⊇⊂⊃∪∩∧∨⇒⇔∀∃・∠⊥⌒∂∇≡≒≪≫√∽∝∵∫∬‰♯♭♪†‡¶◯ ─│┌┐┘└├┬┤┴┼━┃┏┓┛┗┣┳┫┻╋┠┯┨┷┿┝┰┥┸╂ ①②③④⑤⑥⑦⑧⑨⑩⑪⑫⑬⑭⑮⑯⑰⑱⑲⑳・№℡≒≡∫∮∑√⊥∠∟⊿∵∩∪

Characters that don't disappear

ーアイウエオカキクケコサシスセソタチツテトナニヌネノハヒフヘホマミムメモヤユヨラリルレロワン゙゚  、。,.:;?!`^ ̄_ヽヾゝゞ〃仝々〆〇ー/\~|()〔〕[]{}〈〉《》「」『』【】+-=<>¥$¢£%#&*@〒〓¬Å 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz ぁあぃいぅうぇえぉおかがきぎくぐけげこごさざしじすずせぜそぞただちぢっつづてでとどなにぬねのはばぱひびぴふぶぷへべぺほぼぽまみむめもゃやゅゆょよらりるれろゎわゐゑをんァアィ イゥウェエォオカガキギクグケゲコゴサザシジスズセゼソゾタダチヂッツヅテデトドナニヌネノハバパヒビピフブプヘベペホボポマミムメモャヤュユョヨラリルレロヮワヰヱヲンヴヵヶ ΑΒΓΔΕΖΗΘΙΚΛΜΝΞΟΠΡΣΤΥΦΧΨΩαβγδεζηθικλμνξοπρστυφχψω АБВГДЕЁЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯабвгдеёжзийклмнопрстуфхцчшщъыьэюя ⅠⅡⅢⅣⅤⅥⅦⅧⅨⅩ㍉㌔㌢㍍㌘㌧㌃㌶㍑㍗㌍㌦㌣㌫㍊㌻㎜㎝㎞㎎㎏㏄㎡㍻〝〟㏍㊤㊥㊦㊧㊨㈱㈲㈹㍾㍽㍼

How to remove `PSReadline` from PowerShell

1. Start PowerShell with administrator privileges 2. Run `Install-Module PSReadLine -Force` to install the new version of `PSReadLine` 3. If the execution policy has not changed with `Set-ExecutionPolicy`, an attempt to read the installed `PSReadLine` is started will fail. 4. Since the `PSReadLine` is not loaded, any characters can be passed to PowerShell. 5. Maybe you can uninstall the `PSReadLine` with `Uninstall-Module PSReadLine` (not confirmed)

Diagnostic data

Output for Python in the Output panel (ViewOutput, change the drop-down the upper-right of the Output panel to Python)

``` 2024-04-20 21:22:55.122 [info] Experiment 'pythonRecommendTensorboardExt' is active 2024-04-20 21:22:55.122 [info] Experiment 'pythonREPLSmartSend' is active 2024-04-20 21:22:55.122 [info] Experiment 'pythonSurveyNotification' is active 2024-04-20 21:22:55.122 [info] Experiment 'pythonTerminalEnvVarActivation' is active 2024-04-20 21:22:55.122 [info] Experiment 'pythonTestAdapter' is active 2024-04-20 21:22:55.122 [info] Default formatter is set to null for workspace c:\Users\User\Desktop\○_testing\vscode_test 2024-04-20 21:22:55.122 [info] Test server listening. 2024-04-20 21:22:55.123 [info] Python interpreter path: C:\Program Files\Python310\python.exe 2024-04-20 21:22:55.137 [info] > pyenv which python 2024-04-20 21:22:55.137 [info] cwd: . 2024-04-20 21:22:55.188 [info] > conda info --json 2024-04-20 21:22:57.721 [info] Starting Pylance language server. 2024-04-20 21:23:00.202 [error] Active interpreter type is detected as Unknown {"id":"C:\\PROGRAM FILES\\PYTHON310\\PYTHON.EXE","sysPrefix":"C:\\Program Files\\Python310","envType":"Unknown","envName":"","envPath":"","path":"C:\\Program Files\\Python310\\python.exe","architecture":3,"sysVersion":"3.10.6 (tags/v3.10.6:9c7b4bd, Aug 1 2022, 21:53:49) [MSC v.1932 64 bit (AMD64)]","version":{"raw":"3.10.6","major":3,"minor":10,"patch":6,"build":[],"prerelease":["final","0"]},"displayName":"Python 3.10.6 64-bit","detailedDisplayName":"Python 3.10.6 64-bit"} 2024-04-20 21:23:02.136 [info] Send text to terminal: & 'c:\Program Files\Python310\python.exe' 'c:\Users\User\.vscode\extensions\ms-python.debugpy-2024.4.0-win32-x64\bundled\libs\debugpy\adapter/../..\debugpy\launcher' '56927' '--' 'C:\Users\User\Desktop\○_testing\vscode_test\test.py' ```

Extension version: 2024.4.1 VS Code version: Code 1.88.1 (e170252f762678dec6ca2cc69aba1570769a5d39, 2024-04-10T17:41:02.734Z) OS version: Windows_NT x64 10.0.19045 Modes:

User Settings

``` languageServer: "Pylance" ```

Installed Extensions |Extension Name|Extension Id|Version| |---|---|---| |autoDocstring - Python Docstring Generator|njpwerner.autodocstring|0.6.1| |Azure Repos|ms-vscode.azure-repos|0.38.0| |Bookmarks|alefragnani.Bookmarks|13.5.0| |Cursor Align|yo1dog.cursor-align|1.1.2| |Debugger for Firefox|firefox-devtools.vscode-firefox-debug|2.9.10| |Edit csv|janisdd.vscode-edit-csv|0.9.1| |ESLint|dbaeumer.vscode-eslint|2.4.4| |filesize|mkxml.vscode-filesize|3.1.0| |flexibleZenkaku|lowpolysnow.flexible-zenkaku|0.0.1| |Git Graph|mhutchie.git-graph|1.30.0| |Git History|donjayamanne.githistory|0.6.20| |GitHub Codespaces|GitHub.codespaces|1.16.19| |GitHub Repositories|GitHub.remotehub|0.62.0| |gitignore|codezombiech.gitignore|0.9.0| |GitLens — Git supercharged|eamodio.gitlens|14.9.0| |Import Cost|wix.vscode-import-cost|3.3.0| |isort|ms-python.isort|2023.10.1| |Japanese Language Pack for Visual Studio Code|MS-CEINTL.vscode-language-pack-ja|1.88.2024041009| |Japanese Word Handler|sgryjp.japanese-word-handler|1.4.1| |JavaScript Debugger|ms-vscode.js-debug|1.88.0| |JavaScript Debugger Companion Extension|ms-vscode.js-debug-companion|1.1.2| |Jupyter|ms-toolsai.jupyter|2024.3.1| |Jupyter Cell Tags|ms-toolsai.vscode-jupyter-cell-tags|0.1.9| |Jupyter Keymap|ms-toolsai.jupyter-keymap|1.1.2| |Jupyter Notebook Renderers|ms-toolsai.jupyter-renderers|1.0.17| |Jupyter Slide Show|ms-toolsai.vscode-jupyter-slideshow|0.1.6| |Live Preview|ms-vscode.live-server|0.4.13| |merge-n-paste|RAWSEQ.merge-n-paste|1.3.7| |Multiple cursor case preserve|Cardinal90.multi-cursor-case-preserve|1.0.5| |Path Intellisense|christian-kohler.path-intellisense|2.8.5| |Peacock|johnpapa.vscode-peacock|4.2.2| |PHP Debug|xdebug.php-debug|1.34.0| |PHP Intelephense|bmewburn.vscode-intelephense-client|1.10.4| |Prettier - Code formatter|esbenp.prettier-vscode|10.4.0| |Pylance|ms-python.vscode-pylance|2024.4.1| |Python|ms-python.python|2024.4.1| |Python Debugger|ms-python.debugpy|2024.4.0| |Python Indent|KevinRose.vsc-python-indent|1.18.0| |Rainbow CSV|mechatroner.rainbow-csv|3.11.0| |Remote Repositories|ms-vscode.remote-repositories|0.40.0| |Reopen Closed Tab|uyiosa-enabulele.reopenclosedtab|1.1.0| |SFTP|Natizyskunk.sftp|1.16.3| |Svg Preview|SimonSiefke.svg-preview|2.8.3| |Table Visualizer for JavaScript Profiles|ms-vscode.vscode-js-profile-table|1.0.8| |VS Code Counter|uctakeoff.vscode-counter|3.4.0| |vscode-input-sequence|tomoki1207.vscode-input-sequence|0.2.0| |vscode-pdf|tomoki1207.pdf|1.2.2| |Zoom Bar|wraith13.zoombar-vscode|1.4.4|
System Info |Item|Value| |---|---| |CPUs|Intel(R) Core(TM) i7-6700 CPU @ 3.40GHz (8 x 3408)| |GPU Status|2d_canvas: enabled
canvas_oop_rasterization: enabled_on
direct_rendering_display_compositor: disabled_off_ok
gpu_compositing: enabled
multiple_raster_threads: enabled_on
opengl: enabled_on
rasterization: enabled
raw_draw: disabled_off_ok
skia_graphite: disabled_off
video_decode: enabled
video_encode: enabled
vulkan: disabled_off
webgl: enabled
webgl2: enabled
webgpu: enabled| |Load (avg)|undefined| |Memory (System)|7.90GB (1.13GB free)| |Process Argv|--crash-reporter-id 9963c767-2656-4ecc-b62b-9405d4b964a1 --crash-reporter-id 9963c767-2656-4ecc-b62b-9405d4b964a1 --crash-reporter-id 9963c767-2656-4ecc-b62b-9405d4b964a1 --crash-reporter-id 9963c767-2656-4ecc-b62b-9405d4b964a1| |Screen Reader|no| |VM|0%|
A/B Experiments ``` vsliv368:30146709 vspor879:30202332 vspor708:30202333 vspor363:30204092 vstes627:30244334 vscoreces:30445986 vscod805:30301674 binariesv615:30325510 vsaa593cf:30376535 py29gd2263:31024239 c4g48928:30535728 azure-dev_surveyone:30548225 2i9eh265:30646982 962ge761:30959799 pythongtdpath:30769146 welcomedialog:30910333 pythonidxpt:30866567 pythonnoceb:30805159 asynctok:30898717 pythontestfixt:30902429 pythonregdiag2:30936856 pyreplss1:30897532 pythonmypyd1:30879173 pythoncet0:30885854 2e7ec940:31000449 pythontbext0:30879054 accentitlementst:30995554 dsvsc016:30899300 dsvsc017:30899301 dsvsc018:30899302 cppperfnew:31000557 d34g3935:30971562 fegfb526:30981948 bg6jg535:30979843 ccp1r6:30993540 dsvsc020:30976470 pythonait:31006305 gee8j676:31009558 showvideot:31016892 dsvsc021:30996838 01bff139:31013167 pythoncenvpt:31022790 ```
karthiknadig commented 7 months ago

These might be related(or have the same cause): https://github.com/microsoft/vscode/issues/210933

manjuu-eater commented 7 months ago

I fixed the incorrect terminal output example.

Wrong output: Some Unicode character "○" in the path is remaining. This is not real output. Correct output: Unicode character "○" in the path is all disappeared.

I prepared a different environment than usual to get example terminal output, but when I copied it, the output from the other environment was mixed in. Sorry for the confusion.

manjuu-eater commented 7 months ago

@karthiknadig I found that this issue occurs not only in Python but also in Java. So this is not a vscode-python issue, but a VS Code issue. Please move this issue to microsoft/vscode .

I installed JDK and debugged a Java file. Output is below:

PS C:\Users\User2\Desktop\○_testing\debug_test>  & 'C:\Program Files\Java\jdk-22\bin\java.exe' '-agentlib:jdwp=transport=dt_socket,server=n,suspend=y,address=localhost:52955' '--enable-preview' '-XX:+ShowCodeDetailsInExceptionMessages' '-cp' 'C:\Users\User2\AppData\Roaming\Code\User\workspaceStorage\79d9b6fc6f8d9b60cc936b7e2b1b13d9\redhat.java\jdt_ws\debug_test_f78b512b\bin' 'DebugTest'
this is DebugTest.java
PS C:\Users\User2\Desktop\○_testing\debug_test> ^C
PS C:\Users\User2\Desktop\○_testing\debug_test>   
PS C:\Users\User2\Desktop\○_testing\debug_test>  c:; cd 'c:\Users\User2\Desktop\_testing\debug_test'; & 'C:\Program Files\Java\jdk-22\bin\java.exe' '-agentlib:jdwp=transport=dt_socket,server=n,suspend=y,address=localhost:52963' '--enable-preview' '-XX:+ShowCodeDetailsInExceptionMessages' '-cp' 'C:\Users\User2\AppData\Roaming\Code\User\workspaceStorage\79d9b6fc6f8d9b60cc936b7e2b1b13d9\redhat.java\jdt_ws\debug_test_f78b512b\bin' 'DebugTest'
cd : パス 'C:\Users\User2\Desktop\_testing\debug_test' が存在しないため検出できません。
発生場所 行:1 文字:6
+  c:; cd 'c:\Users\User2\Desktop\_testing\debug_test'; & 'C:\Program F ...
+      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (C:\Users\User2\...ting\debug_test:String) [Set-Location], ItemNotFoundException
    + FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.SetLocationCommand

this is DebugTest.java
PS C:\Users\User2\Desktop\○_testing\debug_test> 

Unicode character "○" is missing from passed path. Debugging didn't fail on this test file, but failed to execute cd . I think that if current directory was changed in the program, debugging will fail.