Skip to content

Commit 7379a39

Browse files
committed
Validate target objects before accessing properties in get_file_coverage
Filter out null/non-object elements in the targets array before accessing properties, preventing TypeError on malformed xccov output. Consistent with the isValidCoverageTarget guard in get_coverage_report.
1 parent 97e7241 commit 7379a39

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

src/mcp/tools/coverage/get_file_coverage.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,10 +130,12 @@ export async function get_file_coverageLogic(
130130
'targets' in data &&
131131
Array.isArray((data as { targets: unknown }).targets)
132132
) {
133-
const targets = (data as { targets: { files?: RawFileEntry[] }[] }).targets;
133+
const targets = (data as { targets: unknown[] }).targets;
134134
for (const t of targets) {
135-
if (t.files) {
136-
fileEntries.push(...t.files.map(normalizeFileEntry));
135+
if (typeof t !== 'object' || t === null) continue;
136+
const target = t as { files?: RawFileEntry[] };
137+
if (target.files) {
138+
fileEntries.push(...target.files.map(normalizeFileEntry));
137139
}
138140
}
139141
}

0 commit comments

Comments
 (0)