Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"The specified task cannot be tracked" when trying to start a server with a task before debugging

I have the following debug configuration in my launch.json:

{
    "type": "node",
    "request": "attach",
    "preLaunchTask": "npm: start",
    "name": "Attach",
    "port": 9090
}

This is task defined in tasks.json:

{
    "type": "npm",
    "script": "start",
    "isBackground": true
}

npm start does this: node --inspect=9090 ./src/server.js

If I remove the preLaunchTask of the debug config, start the task manually, then start the debug session, everything works fine (the debug session attaches the the node process).

However, with the preLaunchTask, I get this error ~10 seconds after launching the debugging: "The specified task cannot be tracked".

It seems like maybe the task needs a problem matcher when it is set to isBackground, so I have also tried this task config with no success:

{
    "type": "npm",
    "script": "start",
    "isBackground": true,
    "problemMatcher": {
        "background": {
            "activeOnStart": true,
            "beginsPattern": "^.*Using environment.*",
            "endsPattern": "^.*listening.*"
        }
    }
}

The output of the npm: start

5:13:12 PM web.1 |  Using environment: production
5:13:12 PM web.1 |  Already up to date
5:13:12 PM web.1 |  Debugger listening on ws://127.0.0.1:9090/22d582b8-eade-4b27-95f4-e36ad1718283
5:13:12 PM web.1 |  For help see https://nodejs.org/en/docs/inspector

Do I need a problem matcher? If so, why? When I start the task by itself it's working fine. I don't have any problem to report...

like image 844
Maxime Dupré Avatar asked Dec 22 '18 22:12

Maxime Dupré


2 Answers

Since the task is long running, Vscode will give warning popup after waiting for 10 seconds saying that the specified task cannot be tracked. You can still debug by pressing the "debug anyway" button. But to avoid this popup we define a begin/end pattern.

The problemMatcher’s background field defines when the task is considered to begin and end as is shown in the console output. You need to make sure that the beginsPattern and endsPattern matches what you actually see in the terminal output. If you copied an example from elsewhere, it probably does not match your actual terminal output.

I changed my pattern definitions to:

"background": {
   "activeOnStart": false,
   "beginsPattern": "^.*building.*",
   "endsPattern": "^.*Compiled successfully.*"
} 

I had the same problem as you until I found this blog post and fixed the patterns in tasks.json.

Also check the patterns used in this recipe.

PS: The sample that I had been using had "Live Development Server is listening" in the beginsPattern. But this text is not displayed till after the popup box is displayed.

like image 76
John Pankowicz Avatar answered Nov 17 '22 01:11

John Pankowicz


Do not use "isBackground": true property with preLaunchTask. Tested with .net 5 project.

The configuration below can be used for auto-debug. In launch.json you can specify "preLaunchTask": "watch".

tasks.json

{
            "label": "watch",
            "command": "dotnet",
            "type": "process",
            "args": ["watch", "run", "${workspaceFolder}/your project/your project.csproj", "/property:GenerateFullPaths=true", "/consoleloggerparameters:NoSummary"],
            "problemMatcher": "$msCompile",
            "options": {
                "cwd": "${workspaceFolder}/your project/"
            },
            "group": {
                "kind": "build",
                "isDefault": true
            },
}

launch.json

{
            "name": ".NET Core Attach",
            "type": "coreclr",
            "request": "attach",
            "preLaunchTask": "watch",
            "processName": "Your project.exe",
            "allowFastEvaluate": true
}
like image 1
kutaycan erdoğan Avatar answered Nov 17 '22 01:11

kutaycan erdoğan