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

Can't debug if project resides in folder whose name contains special characters #1288

Open
sba923 opened this issue May 10, 2023 · 9 comments
Labels
bug Something isn't working

Comments

@sba923
Copy link

sba923 commented May 10, 2023

Due to some SharePoint configuration weirdness, my project resides on a OneDrive-for-Business sync'ed folder whose path is:

C:\Users\...\...\... – Projects - Documents\...\test\tools

where the character before Projects is U+2013.

When attempting to debug a Python script in this context, I get:

image

@karthiknadig karthiknadig transferred this issue from microsoft/vscode-python May 10, 2023
@int19h
Copy link
Collaborator

int19h commented May 10, 2023

Note that there is an error from Powershell first before debugger even gets a chance to run. This seems to indicate that Windows is not happy about this path in general. I wonder if the folder is lazily synced? That's the default behavior for OneDrive, if I remember correctly... perhaps the auto-sync logic simply doesn't kick in for this, and so the file isn't actually physically there?

Another possibility that I can think of is that the terminal is not running in UTF-8 mode, and thus the character gets mapped lossily, breaking the path in the command line when it is submitted. However, this really shouldn't be affecting Powershell...

@sba923
Copy link
Author

sba923 commented May 11, 2023

Windows and PowerShell have no problems with this path, and the VScode terminal does happen to be configured for UTF-8:

image

I'm routinely debugging PowerShell code in VScode off that very same folder.

The PowerShell error is caused by the execution of the command line built by the Python extension, where the character is replaced by a space.

@gramster
Copy link
Member

@karthiknadig, is this an issue with debugger invocation in PVSC?

@karthiknadig
Copy link
Member

The command that is sent to the terminal with the launcher is generated by debugpy it gets sent as runInTerminal request back to the VS Code. The DAP client in VS Code handles writing the command to the terminal. If the issue is with how the command is getting altered when it is sent to the terminal then this is like an issue with VS Code terminal support.

PVSC does not handle the runInTerminal request, it is handled by VS Code DAP client.

@int19h
Copy link
Collaborator

int19h commented Sep 12, 2023

@sba923 Could you share the logs from running with "logToFile": true? If there's too much private information there, the thing I'm most interested in is the actual JSON values for "cwd" in various requests - this is what ends up sent by debugpy to VSCode for the latter to build the actual command line for the terminal.

@int19h int19h added the bug Something isn't working label Sep 12, 2023
@sba923
Copy link
Author

sba923 commented Sep 13, 2023

Does this help?

ms-python.python-2023.17.12551009.zip

@int19h
Copy link
Collaborator

int19h commented Sep 13, 2023

Yes, thank you!

@karthiknadig This appears to be a VSCode issue. What the adapter does:

D+00000.078: /handling #2 request "launch" from Client[1]/
             Client[1] <-- {
                 "seq": 4,
                 "type": "request",
                 "command": "runInTerminal",
                 "arguments": {
                     "kind": "integrated",
                     "title": "Python Debug Console",
                     "args": [
                         "C:\\Users\\<REDACTED>\\AppData\\Local\\Programs\\Python\\Python310\\python.exe",
                         "c:\\Users\\<REDACTED>\\.vscode\\extensions\\ms-python.python-2023.17.12551009\\pythonFiles\\lib\\python\\debugpy\\adapter/../..\\debugpy\\launcher",
                         "57820",
                         "--",
                         "C:\\Users\\<REDACTED>\\<REDACTED> Group\\<REDACTED> \u2013 Projects - Documents\\<REDACTED> Payment\\test\\tools\\helloworld.py"
                     ],
                     "env": {
                         "DEBUGPY_LOG_DIR": "c:\\Users\\<REDACTED>\\.vscode\\extensions\\ms-python.python-2023.17.12551009"
                     },
                     "cwd": "c:\\Users\\<REDACTED>\\<REDACTED> Group\\<REDACTED> \u2013 Projects - Documents\\<REDACTED> Payment\\test\\tools"
                 }
             }

So U+2013 is still there in "cwd" and "args" as it should be. What VSCode does:

279 Client <-- Adapter:
{
    "seq": 4,
    "type": "request",
    "command": "runInTerminal",
    "arguments": {
        "kind": "integrated",
        "title": "Python Debug Console",
        "args": [
            "C:\\Users\\<REDACTED>\\AppData\\Local\\Programs\\Python\\Python310\\python.exe",
            "c:\\Users\\<REDACTED>\\.vscode\\extensions\\ms-python.python-2023.17.12551009\\pythonFiles\\lib\\python\\debugpy\\adapter/../..\\debugpy\\launcher",
            "57820",
            "--",
            "C:\\Users\\<REDACTED>\\<REDACTED> Group\\<REDACTED> – Projects - Documents\\<REDACTED> Payment\\test\\tools\\helloworld.py"
        ],
        "env": {
            "DEBUGPY_LOG_DIR": "c:\\Users\\<REDACTED>\\.vscode\\extensions\\ms-python.python-2023.17.12551009"
        },
        "cwd": "c:\\Users\\<REDACTED>\\<REDACTED> Group\\<REDACTED> – Projects - Documents\\<REDACTED> Payment\\test\\tools"
    }
}

This is harder to see because it's not escaped here, but the "–" before Projects is indeed U+2013. But, as seen on the screenshots, it gets stripped right after, when VSCode generates the command line in response to this request (or possibly when it gets "typed" into the terminal?). Our launcher conveniently logs its own sys.argv very early on where this is also visible:

I+00000.078: sys.argv before parsing: ['c:\\Users\\<REDACTED>\\.vscode\\extensions\\ms-python.python-2023.17.12551009\\pythonFiles\\lib\\python\\debugpy\\adapter/../..\\debugpy\\launcher', '57820', '--', 'C:\\Users\\<REDACTED>\\<REDACTED> Group\\<REDACTED>  Projects - Documents\\<REDACTED> Payment\\test\\tools\\helloworld.py']

Could you transfer the bug accordingly?

@sba923
Copy link
Author

sba923 commented Sep 13, 2023

Just curious: how come this doesn't affect other extensions e.g., PowerShell?

@int19h
Copy link
Collaborator

int19h commented Sep 13, 2023

I would expect it to affect Node.js if using "console":"integratedTerminal". I'm not familiar with the Powershell extension, but my guess would be that they don't use "runInTerminal" to implement Start Debugging.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants