Skip to content

VS Code 1.56 breaks nested variable substitution in tasks #5007

Closed

Description

@sleiner
  • VSCode Version: 1.56.0, 1.56.1, 1.56.2

  • Local OS Version: confirmed on Windows and macOS

  • Remote OS Version: confirmed for Ubuntu 18.04 and 20.10

  • Remote Extension/Connection Type: SSH

  • Logs:

    Remote - SSH (probably not very interesting) [11:44:56.191] Log Level: 2 [11:44:56.193] [email protected] [11:44:56.193] darwin x64 [11:44:56.195] SSH Resolver called for "ssh-remote+ubuntu-2010", attempt 1 [11:44:56.196] "remote.SSH.useLocalServer": true [11:44:56.197] "remote.SSH.path": undefined [11:44:56.197] "remote.SSH.configFile": undefined [11:44:56.197] "remote.SSH.useFlock": true [11:44:56.198] "remote.SSH.lockfilesInTmp": false [11:44:56.198] "remote.SSH.localServerDownload": auto [11:44:56.198] "remote.SSH.remoteServerListenOnSocket": false [11:44:56.198] "remote.SSH.showLoginTerminal": false [11:44:56.199] "remote.SSH.defaultExtensions": [] [11:44:56.199] "remote.SSH.loglevel": 2 [11:44:56.199] SSH Resolver called for host: ubuntu-2010 [11:44:56.199] Setting up SSH remote "ubuntu-2010" [11:44:56.204] Acquiring local install lock: /var/folders/vx/hn90mz9j7x1bw6j_msm723h80000gn/T/vscode-remote-ssh-ubuntu-2010-install.lock [11:44:56.208] Looking for existing server data file at /Users/simon/Library/Application Support/Code/User/globalStorage/ms-vscode-remote.remote-ssh/vscode-ssh-host-ubuntu-2010-cfa2e218100323074ac1948c885448fdf4de2a7f-0.65.4/data.json [11:44:56.210] Found local server running: {"remoteListeningOn":{"port":37313},"osReleaseId":"ubuntu","arch":"aarch64","webUiAccessToken":"","sshAuthSock":"","display":"","tmpDir":"/run/user/1001","platform":"linux","connectionToken":"111a1a11-1111-111a-11a1-aaa1a111a111","pid":13415,"ipcHandlePath":"/var/folders/vx/hn90mz9j7x1bw6j_msm723h80000gn/T/vscode-ssh-askpass-eb0a9280e25337a77881329b4dbcab26f2148d64.sock","socksPort":57479,"startupTime":1620293406903} [11:44:56.220] Found running server - short-circuiting install [11:44:56.222] Starting forwarding server. localPort 59100 -> socksPort 57479 -> remotePort 37313 [11:44:56.223] Forwarding server listening on 59100 [11:44:56.223] Waiting for ssh tunnel to be ready [11:44:56.225] [Forwarding server 59100] Got connection 0 [11:44:56.226] Tunneled 37313 to local port 59100 [11:44:56.226] Resolved "ssh-remote+ubuntu-2010" to "127.0.0.1:59100" [11:44:56.232] ------

    [11:44:56.262] [Forwarding server 59100] Got connection 1
    [11:44:56.290] [Forwarding server 59100] Got connection 2
    [11:44:57.698] [Forwarding server 59100] Got connection 3

Steps to Reproduce:

  1. Open the following workspace configuration:
    {
        "folders": [
            {
                "path": ".."
            }
        ],
        "settings": {
            "someSetting": "${workspaceFolder}/qux"
        },
        "tasks": {
            "version": "2.0.0",
            "tasks": [
                {
                    "label": "echo",
                    "type": "shell",
                    "command": "echo",
                    "args": [
                        "This should be an absolute path: ",
                        "${config:someSetting}"
                    ],
                    "problemMatcher": []
                }
            ]
        }
    }
  2. Run the task echo.
  • Expected behavior (as well as the behavior of VS Code 1.55.x): The task output contains the absolute path to the workspace folder, e.g. This should be an absolute path: /home/foo/workspace/qux
  • Encountered behavior with VS Code 1.56: The place where the path to the workspace folder should be is empty, e.g. This should be an absolute path: /qux

Does this issue occur when you try this locally?: No

Activity

  1. added
    ssh
    on May 10, 2021
  2. sleiner commented on May 12, 2021

    @sleiner
    Author

    One of the patches in 1.56.1 seems related to this problem. In any case, I am seeing the bug in 1.56.1 also.

  3. sleiner commented on May 14, 2021

    @sleiner
    Author

    I just drilled down a bit harder and found that nested variable substitution is not generally broken. Rather it seems that the nested substitution of ${workspaceFolder} is broken (again, only in remote development). To illustrate, here is an extend version of the workspace configuration above, showing that:

    • nested substitution with ${config:variable} works
    • simple substitution of ${workspaceFolder} works
    • nested substitution of ${workspaceFolder} is broken
    {
        "folders": [
            {
                "path": "."
            }
        ],
        "settings": {
            "someSetting": "${workspaceFolder}/qux",
            "someOtherSetting": "${config:dependentSetting}/foo",
            "dependentSetting": "/substitution/works/here"
        },
        "tasks": {
            "version": "2.0.0",
            "tasks": [
                {
                    "label": "Nested substitution with another config variable (does not trigger bug)",
                    "type": "shell",
                    "command": "echo",
                    "args": [
                        "This should begin with \"/substitution/works/here\": ",
                        "${config:someOtherSetting}"
                    ],
                    "problemMatcher": []
                },
                {
                    "label": "Simple substitution with workspaceFolder (does not trigger bug)",
                    "type": "shell",
                    "command": "echo",
                    "args": [
                        "This should be the absolute path to the current workspace: ",
                        "${workspaceFolder}"
                    ],
                    "problemMatcher": []
                },
                {
                    "label": "Nested substitution with workspaceFolder (DOES TRIGGER BUG)",
                    "type": "shell",
                    "command": "echo",
                    "args": [
                        "This should contain the absolute path to the current workspace: ",
                        "${config:someSetting}"
                    ],
                    "problemMatcher": []
                }
            ]
        }
    }
  4. sleiner commented on May 18, 2021

    @sleiner
    Author

    I spent some more time with this issue and think I might have found the root cause of the bug. I found the following:

    • The bug is also present with the Container remote. I have not tried WSL.

    • When opening the developer tools while triggering the bug, this error message is shown:

        ERR Could not resolve shell Error: Variable ${workspaceFolder} can not be resolved. Please open a folder.
          at n (variableResolver.ts:216)
          at m.evaluateSingleVariable (variableResolver.ts:260)
          at variableResolver.ts:149
          at String.replace (<anonymous>)
          at m.resolveString (variableResolver.ts:143)
          at m.recursiveResolve (variableResolver.ts:126)
          at m.resolveWithEnvironment (variableResolver.ts:66)
          at C._resolveVariables (terminalProfileResolverService.ts:232)
          at C._resolveProfile (terminalProfileResolverService.ts:222)
          at async C.resolveShellLaunchConfig (terminalProfileResolverService.ts:57)
          at async D.createProcess (terminalProcessManager.ts:236)
      

      Of course, I have a folder open. So I put a breakpoint in the closure that throws the error (getFolderUri) and found the following:
      For running the task one time, the function is called three times:

      • Two times out of the resolveAny context. Here, the correct folder URI is returned successfully:
        remote-resolveanybase-noerror

      • One time out of the _resolveProfile context. Here, the error message is generated.
        remote-resolveprofile-error
        I traced the fact that folderUri is undefined back to _resolveProfile, where lastActiveWorkspace (which is passed as a parameter to _resolveVariables) is undefined:
        remote-resolveprofile-low-error

        When executing the same task locally (which works fine, as written in the original bug report), lastActiveWorkspace actually contains the right path:
        local-resolveprofile-noerror

    • So, we established that lastActiveWorkspace is undefined when it should not be, so I tried to trace the origin of this.
      As far as I see, activeWorkspaceRootUri needs to be defined in order for lastActiveWorkspace to be defined.
      Locally, activeWorkspaceRootUri is actually defined. When working remotely, it is not. So I looked into getLastActiveWorkspaceRoot.

      So, the reason that undefined is returned here is that _resolveProfile sets schemeFilter to "file" but the actual scheme is "vscode-remote" (at least when working remotely, locally it actually is "file"):
      remote-getlastactiveworkspaceroot

      So I guess, this bug can be resolved by either removing the schemeFilter or changing it to vscode-remote when working remotely. But I have no idea what makes sense here, this was my first look at the internals of VS Code itself 🤷🏼‍♂️
      Furthermore, I cannot change and test this easily as the remote extensions do not work with the OSS build 😕

    • FWIW: All of the above was tested using 1.56.2, but I confirmed additionally that the bug still exists with the current insider build (Commit: 45aafeb326d0d3d56cbc9e2932f87e368dbf652d, Date: 2021-05-18T05:12:52.309Z).

    So, Christof Marti (@chrmarti): Is there anything I can do to get this fixed? 😊

  5. chrmarti commented on May 20, 2021

    @chrmarti
    Contributor

    Simon Leiner (@sleiner) Thanks for the analysis! Have you checked if this is still a problem with VS Code Insiders? (https://code.visualstudio.com/insiders/)

  6. sleiner commented on May 20, 2021

    @sleiner
    Author

    Yes, I have 👍 Still a problem on the latest insiders build as of now:

    Commit: 29c61570a5b9a669f777bb28b5acd5c37d99edbe
    Date: 2021-05-20T05:11:47.260Z (1 hr ago)

  7. added
    bug
    and removed
    ssh
    on May 28, 2021
  8. added this to the May 2021 milestone on May 28, 2021
  9. alexr00 commented on May 31, 2021

    @alexr00
    Member

    Interesting. I thought only the tasks system was resolving variables on this execution path, but it seems that terminal is also resolving variables.
    What's happening:

    1. Tasks resolves the variables once.
    2. Terminal resolves the variables once.

    So, at most you'd get 1 level of nesting.

    Here, the problem is that step 2 is not happening correctly. Daniel Imms (@Tyriar), this is caused by what appears to be an unsafe usage of Schemas.file. I think here you should instead use the remote schema when remote:

    https://github.com/microsoft/vscode/blob/7ce379e3f2bd184ace37d365d012ce00e6b74ca3/src/vs/workbench/contrib/terminal/browser/terminalProfileResolverService.ts#L320-L321

    Daniel Imms (@Tyriar) I think that change is needed regardless of other changes that I will make to help this issue.

  10. alexr00 commented on May 31, 2021

    @alexr00
    Member

    Simon Leiner (@sleiner) I've added limited support for variables that resolve to other variables, which should solve your issue.

    Daniel Imms (@Tyriar) I think you might still want to change the Schemas.file mentioned above.

  11. added
    author-verification-requested
    on May 31, 2021
  12. sleiner commented on Jun 1, 2021

    @sleiner
    Author

    Thanks so much, Alex Ross (@alexr00)! That solves my concrete problem indeed 🚀

    You say that there is "limited support" now. Could you elaborate on what the limits are?Nevertheless, during first tests today I did not hit the limits 😃 But I will put it through more thorough tests during the next days.

    Also, during my tests today I ran into a problem that is possibly connected :/ #5128

  13. alexr00 commented on Jun 2, 2021

    @alexr00
    Member

    By limited support I mean that command and input variables won't get this treatment. Predefined, env, and config variables should all work this way now.

  14. added
    verified
    on Jun 2, 2021
  15. sleiner commented on Jun 4, 2021

    @sleiner
    Author

    Thanks for the explanation 👍🏻

  16. added a commit that references this issue on Jun 4, 2021
    bb14cfe
  17. added a commit that references this issue on Jul 13, 2021
    ddee4f7
  18. locked and limited conversation to collaborators on Jul 15, 2021
  19. added a commit that references this issue on May 6, 2026
    0fde806
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

author-verification-requestedbugtasksvariable-resolvingverified

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions