microsoft / microsoft/vscode-cmake-tools

[Bug] testCodeLensProvider floods log: "Cannot read properties of undefined (reading '0')" when a test's target isn't built (e.g. cross-compiled preset)

Open
#5,096 2 comments 2 reactions 0 assignees View on GitHub
bug
Dominant language
TypeScript
Stars
1.7k
Forks
546
Avg merge
2d 16h
Merged PRs (30d)
32

Description

### Brief Issue Summary

### Brief Issue Summary

After configuring a project, the CMake/Output log is flooded — one line per `provideCodeLenses` call — with:

[testCodeLensProvider] Error in provideCodeLenses: TypeError: Cannot read properties of undefined (reading '0')

Nothing is broken functionally (build, Test Explorer, and running tests still work), but the log is spammed continuously as the editor requests code lenses.

### CMake Tools Diagnostics

```shell
{
"os": "linux",
"vscodeVersion": "1.137.0",
"cmtVersion": "1.24.42",
"configurations": [
{
"folder": "/home/source/MyProject.wt/ACTIVE",
"cmakeVersion": "3.28.3",
"configured": true,
"generator": "Ninja",
"usesPresets": true,
"compilers": {}
}
],
"cpptoolsIntegration": {
"isReady": true,
"hasCodeModel": true,
"activeBuildType": "Debug",
"buildTypesSeen": [
"Debug"
],
"requests": [
"file:///home/source/MyProject.wt/ACTIVE/controller/lib/iABCDb/src/iABCdb/iABCDbSchema.cpp"
],
"responses": [
{
"uri": "file:///home/source/MyProject.wt/ACTIVE/controller/lib/iABCDb/src/iABCdb/iABCDbSchema.cpp",
"configuration": {
"includePath": [
"/home/source/MyProject.wt/ACTIVE/controller/lib/iABCDb/include",
"/home/source/MyProject.wt/ACTIVE/controller/lib/CommonUtils/3rdparty/sqlpp11/include",
"/home/source/MyProject.wt/ACTIVE/controller/lib/iABCCommon/include",
"/home/source/MyProject.wt/ACTIVE/build/cm4-debug",
"/home/source/MyProject.wt/ACTIVE/controller/lib/CommonUtils/include",
"/home/source/MyProject.wt/ACTIVE/controller/lib/CommonUtils/3rdparty/ArduinoJson/src",
"/home/source/MyProject.wt/ACTIVE/build/cm4-debug/controller/proto",
"/home/source/MyProject.wt/ACTIVE/build/cm4-debug/controller/proto/generated"
],
"defines": [
"ARDUINOJSON_DEBUG=1",
"DEVELOPMENT_RELEASE=1",
"ONLY_C_LOCALE=0",
"PROTOBUF_USE_DLLS",
"REAL_TIME_HARDWARE",
"USE_DEBUG_MEM=0"
],
"compilerPath": "/opt/iABC_sdk/5.0/sysroots/x86_64-pokysdk-linux/usr/bin/aarch64-poky-linux/aarch64-poky-linux-g++",
"compilerArgs": [
"--sysroot=/opt/iABC_sdk/5.0/sysroots/x86_64-pokysdk-linux/usr/share/cmake/../../../../../sysroots/cortexa72-poky-linux"
],
"compilerFragments": [
" -mcpu=cortex-a72+crc -mbranch-protection=standard -ffp-contract=off -Wall -Wextra -Wno-psabi -g -std=c++23 -fdiagnostics-color=always",
"-isystem/opt/iABC_sdk/5.0/sysroots/cortexa72-poky-linux/usr/include/c++/13.4.0",
"-isystem/opt/iABC_sdk/5.0/sysroots/cortexa72-poky-linux/usr/include/c++/13.4.0/aarch64-poky-linux",
"-isystem/opt/iABC_sdk/5.0/sysroots/cortexa72-poky-linux/usr/include/c++/13.4.0/backward",
"-isystem/opt/iABC_sdk/5.0/sysroots/x86_64-pokysdk-linux/usr/lib/aarch64-poky-linux/gcc/aarch64-poky-linux/13.4.0/include",
"-isystem/opt/iABC_sdk/5.0/sysroots/x86_64-pokysdk-linux/usr/lib/aarch64-poky-linux/gcc/aarch64-poky-linux/13.4.0/include-fixed",
"-isystem/opt/iABC_sdk/5.0/sysroots/cortexa72-poky-linux/usr/include"
]
}
}
],
"partialMatches": [],
"targetCount": 124,
"executablesCount": 76,
"librariesCount": 19,
"targets": []
},
"settings": [
{
"communicationMode": "automatic",
"useCMakePresets": "auto",
"configureOnOpen": true
}
]
}
```

### Debug Log

```shell
N/A
```

### Additional Information

### Root cause

`CTestDriver#getTestsForOutline` maps every ctest test to `executablePath: test.command[0]`. CTest only guarantees a test has a `name`; `command`, `backtrace`, and `properties` may be absent — e.g. when a test's target has not been built yet, or the CTest metadata for a cross-compiled configuration doesn't carry them. `test.command` is then `undefined` and `test.command[0]` throws. `resolveTestSourceLocation` has the same problem with `test.properties.filter(...)`.

This is a regression introduced by the new inline Run/Debug test CodeLens feature (CHANGELOG 1.24.x, "Add inline 'Run' and 'Debug' CodeLens buttons ...", #4451). Earlier versions had no `provideCodeLenses` path and did not crash.

PR #5095 appears to already address this (making `backtrace`/`command`/ `properties` optional and skipping such entries); filing this so there's a tracking issue for the user-facing symptom.

### Expected behavior

Tests missing `command`/`properties`/`backtrace` are skipped (no code lens for them) instead of throwing on every `provideCodeLenses` invocation.

### Steps to reproduce

1. Use a preset whose test targets are configured but not yet built (readily reproduced with a cross-compile preset, e.g. aarch64, on an x86_64 host).
2. Open a C/C++ source file with `cmake.ctest.testExplorerIntegrationEnabled` at its default (`true`).
3. Observe the log flooded with the error above.

Contributor guide

Open the contributing guide

Research direction

Start at CTestDriver#getTestsForOutline and resolveTestSourceLocation, then review PR #5095, which the issue identifies as addressing the problem. Done means tests without command, properties, or backtrace are skipped without throwing during provideCodeLenses or flooding the log.

Written by the indexing model from the issue text.

Assessment

Tech stack
cmake, typescript
Domain
devtools, testing-qa
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.