Incorrect Command Variable Resolution in tasks.json if task type is 'process'
#160,891 创建于 2022年9月14日
描述
Does this issue occur when all extensions are disabled?: I suspect so, can't figure out how to test. I would need an in-built vscode command that returns a string and for some reason am struggling to find one. I first noticed the issue using vscode-python and it has already been raised there: https://github.com/microsoft/vscode-python/issues/19265. They suggested that it's an upstream problem and to raise here.
- VS Code Version:
Version: 1.71.0 (system setup)
Commit: 784b0177c56c607789f9638da7b6bf3230d47a8c
Date: 2022-09-01T07:36:10.600Z
Electron: 19.0.12
Chromium: 102.0.5005.167
Node.js: 16.14.2
V8: 10.2.154.15-electron.0
OS: Windows_NT x64 10.0.19044
Sandboxed: No
- OS Version: Windows_NT x64 10.0.19044
Steps to Reproduce:
- Either: install python extension or find a vscode command that returns a string and can be used as a command variable, as per these docs.
- Create a tasks.json file something like:
{
"version": "2.0.0",
"tasks": [
{
"label": "python: run",
// I think the issue only arises for type 'process'
"type": "process",
// This command could potentially be an in-built vscode one but I can't find one
"command": "${command:python.interpreterPath}"
}
]
}
- Run the task
- Observe the output in the terminal, I get the following:
The terminal process failed to launch: Path to shell executable "C:\projects\ots\testVscodeWorkspace\C:\Python310\python.exe" does not exist.
Suspected Cause
I've been looking into this a bit and I think I might know why it's happening. Apologies if this is hard to follow:
- There is a call in
ExtHostTask.$resolveVariablestowin32.findExecutable. The executable it is trying to find is the string"${command:python.interpreterPath}". - It doesn't think this looks like an absolute path, so it prepends it with the current working directory (see the very end of the
win32.findExecutable) function. It doesn't check if this exists or not. - Later on, there is further variable resolution done by the
VariableResolverclass interminalTaskSystem.ts. This resolver has the details needed to expand the interpreter path correctly, but it has already been prepended with the cwd.
Proposed Solutions
-
Perhaps the
win32.findExecutablefunction could check if the executable exists at the location, and if it doesn't, simple return the unaltered process name (in this case"${command:python.interpreterPath}")? -
Alternatively, perhaps this call could be somehow removed from the setup done in
ExtHostTask? -
Perhaps the path could be resolved before running it - if there are two absolute paths then the right-most one could be used.