Skip to content

Fix debugger launch failure with spaces in interpreter path (regression from #964)#1015

Open
ZA139 wants to merge 1 commit intomicrosoft:mainfrom
ZA139:quote_fix
Open

Fix debugger launch failure with spaces in interpreter path (regression from #964)#1015
ZA139 wants to merge 1 commit intomicrosoft:mainfrom
ZA139:quote_fix

Conversation

@ZA139
Copy link
Copy Markdown
Contributor

@ZA139 ZA139 commented Apr 29, 2026

Problem

The debugger fails to start (ENOENT error) when the Python interpreter path contains spaces, such as C:\Program Files\Python312\python.exe. This is a regression introduced in version 2026.4.0.

Root Cause

PR #964 unconditionally applied shell-style quoting via fileToCommandArgumentForPythonExt() to wrap the interpreter executable path before passing it to DebugAdapterExecutable.

However, DebugAdapterExecutable internally uses child_process.spawn() in a non-shell environment. In this mode:

  • Literal quote characters are treated as part of the filename rather than delimiters
  • This causes the OS to look for a file literally named "C:\...\python.exe" (including the quotes)
  • Result: ENOENT: file not found

Solution

Remove the shell-style quoting step for the executable path. child_process.spawn() correctly handles spaces in paths via array-based argument passing and does not require manual quoting.

Changes

  1. factory.ts: Remove fileToCommandArgumentForPythonExt(executable) call and replace with explanatory comment
  2. factory.unit.test.ts: Update two test cases to expect unquoted paths instead of quoted paths

Testing

  • Both "interpreter path with spaces" test cases now verify that paths are passed without quotes
  • The tests cover both default adapter path and custom debugAdapterPath scenarios

Related Issues

Remove shell-style quoting of the interpreter executable when constructing DebugAdapterExecutable and add a comment explaining why (child_process.spawn is invoked without a shell and manual quotes become part of the filename causing ENOENT). Drop the fileToCommandArgumentForPythonExt import and update unit tests to expect unquoted interpreter paths for both default and custom debug adapter paths. References regressions reported in microsoft#1013 and analysis of microsoft#964.
@ZA139 ZA139 marked this pull request as draft April 29, 2026 15:23
executable = fileToCommandArgumentForPythonExt(executable);
// DO NOT apply shell-style quoting here.
// The 'executable' path is passed to 'DebugAdapterExecutable', which internally
// uses 'child_process.spawn' in a non-shell environment.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this breaking the original fix in a shell environment? Seems like fileToCommandArgumentForPythonExt should have some way of checking how the launch is going to happen.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this breaking the original fix in a shell environment? Seems like fileToCommandArgumentForPythonExt should have some way of checking how the launch is going to happen.

Yep, totally agreed — simply removing fileToCommandArgumentForPythonExt is not sufficient.
The correct fix should depend on whether spawn is running in a shell environment:

  • If options.shell === true, we need quotes to handle spaces correctly.
  • If options.shell === false (default), we must avoid quotes to prevent ENOENT.

So instead of removing the helper entirely, we should update fileToCommandArgumentForPythonExt to accept a isShell flag and return the path accordingly.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if it's a shell environment. It's just whether or not this command is a bat/cmd file.
https://github.com/microsoft/vscode/blob/main/src/vs/workbench/contrib/debug/node/debugAdapter.ts#L173-L180

So maybe this is the correct fix.

@rchiodo rchiodo marked this pull request as ready for review April 29, 2026 19:00
@rchiodo rchiodo added the bug Issue identified by VS Code Team member as probable bug label Apr 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Issue identified by VS Code Team member as probable bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Latest release version of the debugger will not start the debugging process

2 participants