VSCode make launch configuration fail if preLaunchTask fails
Asked Answered
C

2

6

I have a launch configuration that runs a bat script as a pre launch task. Sometimes, the bat script fails to build my project. However, the debugging task still runs, which is really annoying, and means I have to keep an eagle eye on the output of the terminal before it changes to the debug console.

How can I prevent the launch configuration from continuing if the pre launch task fails?

Caulfield answered 1/6, 2021 at 19:14 Comment(1)
Hey there, any news on this? I'm also struggling at the moment with a cmake taskMidas
M
2

I had the same problem with a cmake task.
I've solved it by changing task's type to shell and passing everything else in command field.

Now when the task fails with an error (exit code != 0), it stops and does not launch the application.


launch.json:

{
   ...
   "name": "(gdb) Launch",
   "type": "cppdbg",
   "request": "launch",
   "preLaunchTask": "CMake Build"     // <--- task name
   ...
}

tasks.json:

...
{
    "label": "CMake Build",
    "command": "/usr/bin/cmake --build /{project_directory}/build --config Debug --target all -j 14 -- ",
    "type": "shell",                // <--- changed this part
    "group": "build"
}
...

Cheers

Midas answered 22/9, 2021 at 14:11 Comment(2)
Does not work for me. I execute a script instead of command.Encapsulate
@Karthik, you should check what the script does in your case and ensure that It properly returns a non zero exit code in case of error.Midas
W
0

My problem was:

    "debug.onTaskErrors": "debugAnyway",

on my user settings as per: https://github.com/microsoft/vscode/issues/141654#issuecomment-1023481850 Much more reasonable is:

    "debug.onTaskErrors": "abort",

In some distant past I had done "debug anyway" and "remember" on the GUI popup for something completely unrelated and surprise, the setting stayed there waiting to hurt me.

Tested on vscode 1.91.1, Ubuntu 24.04 and this simple C++ make project: Setup: C++ in VS Code under Linux (tasks.json and launch.json)

Whirly answered 29/7 at 15:13 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.