vscode: errors in dependsOn background tasks do not prevent subsequent tasks from executing

  • VSCode Version: 1.32.1
  • OS Version: 18309

Steps to Reproduce:

create launch.json:

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [        
        {
            "type": "chrome",
            "request": "launch",
            "name": "Launch Chrome against localhost",
            "url": "http://localhost:8080",
            "webRoot": "${workspaceFolder}\\src\\FrontEnd\\build",
            "preLaunchTask": "core"
        }
    ]
}
  1. create task.json:
{
    // See https://go.microsoft.com/fwlink/?LinkId=733558 
    // for the documentation about the tasks.json format
    "version": "2.0.0",
    "tasks": [
        {
            "label": "core",            
            "type": "npm",
            "script": "start",
            "path": "src/FrontEnd/core/",
            "isBackground": true,
            "dependsOn":["loss"],
            "problemMatcher":{
                "owner": "custom",
                "pattern":[
                    {
                        "regexp": "something not exists",
                        "file": 1,
                        "location": 2,
                        "message": 3
                    }
                ],
                "background": {
                    "activeOnStart": true,
                    "beginsPattern": "core@1.0.0 start",
                    "endsPattern": "created ..\\\\build\\\\vendor.js"
                }
            }
        },
        {
            "label": "loss",            
            "type": "npm",
            "script": "watch",
            "path": "src/FrontEnd/loss/",
            "isBackground": true,            
            "problemMatcher":{
                "owner": "custom",
                "pattern":[
                    {
                        "regexp": "something not exists",
                        "file": 1,
                        "location": 2,
                        "message": 3
                    }
                ],
                "background": {
                    "activeOnStart": true,
                    "beginsPattern": "loss@1.0.0 start",
                    "endsPattern": "waiting for changes"
                }
            }
        }
    ]
}

I can use beginsPattern/endsPattern with no issue if I direct launched by preLaunchTask, but if I have DependsOn for same task, it will run the dependencies but can’t detect it’s status by using endsPattern, the task will hang there. it looks like a bug for me.

I tried to use the new Terminal: “terminal.integrated.windowsEnableConpty”: false/true, no difference. I tried to use presentation.panel:“dedicated”, no difference.

I think we have done a nice work on putting tasks running in background and launch, but not those tasks in DependsOn property.

Does this issue occur when all extensions are disabled?: Yes

About this issue

  • Original URL
  • State: open
  • Created 5 years ago
  • Reactions: 29
  • Comments: 24 (5 by maintainers)

Commits related to this issue

Most upvoted comments

@penx thanks for the simple repro repository.

Until now, you could have background tasks in dependsOn, but since those background tasks never “finish”, you couldn’t sequence anything off of them.

I have pushed a small change that does allow some sequencing. You can have background tasks in dependsOn and they can be sequenced. However any errors that those background tasks produce will not prevent subsequent tasks from executing. I will leave this issue open to track supporting that.

I created a basic repo that shows the issue of not being able to create a task that depends on a background/watch task:

https://github.com/penx/vscode-task-dependson

In this project:

  • the launch configuration depends on task ‘Two’ and works fine
  • the task ‘One’ depends on task ‘Two’ and ‘Three’ in sequence, but neither ‘One’ nor ‘Three’ execute

As per @linusbrolin’s comment above, the documentation says that this should work:

Any background/watch tasks used in dependsOn with “dependsOrder”: “sequence” must have a problem matcher that tracks when they are “done”

… so please can you either mark this ticket as a bug or else update the documentation to make it clear this is not supported?

launch.json

{
  "version": "0.2.0",
  "configurations": [
    {
      "name": "Node",
      "type": "node",
      "request": "launch",
      "program": "${file}",
      "preLaunchTask": "Two"
    }
  ]
}

tasks.json

{
  "version": "2.0.0",
  "tasks": [
    {
      "label": "One",
      "type": "shell",
      "command": "echo start1",
      "dependsOrder": "sequence",
      "dependsOn": ["Two", "Three"],
      "problemMatcher": []
    },
    {
      "label": "Two",
      "type": "shell",
      "isBackground": true,
      "command": "echo start2 && echo end2 && read varname",
      "problemMatcher": {
        "owner": "custom",
        "pattern": {
          "regexp": "^$"
        },
        "background": {
          "activeOnStart": true,
          "beginsPattern": "start2",
          "endsPattern": "end2"
        }
      }
    },
    {
      "label": "Three",
      "type": "shell",
      "command": "echo start3"
    }
  ]
}

@StephenWeatherford what is supported is having one main task that starts n other tasks that run in watch mode. Something like:

		{
			"label": "watch",
			"dependsOn": [
				"watch:types",
				"watch:jsonrpc",
				"watch:protocol",
				"watch:server",
				"watch:client"
			],
			"problemMatcher": []
		}

were watch:* tasks are all background tasks.

What doesn’t work right now is to serialize background tasks. They reason is that is it not clear to define when a background task is in a state that it depending task can start.

@mohsen1 I would expect that the task runner would detect the endsPattern of the first task, and then start the next one. https://code.visualstudio.com/docs/editor/tasks#_background-watching-tasks

I don’t think all that additional complexity is going to add anything if we can do what we want with the options we have now.

@mohsen1 @tetchel in my mind, I planned on having an endsPattern detect when a service is finished running through it’s initial setup. Like when the watcher is running, or files are being served and are ready to be accessed, that would be matched for my endsPattern. I don’t really care about exits on those tasks unless I’m killing my services.

Just chipping in here that I also found this problem and it would be super amazing if it was made to work.