Skip to content

Commit ef4b069

Browse files
committed
Fix unsafe non-null assertions in Map operations
- deduplication.ts: Replace signatureMap.get(signature)! with safe optional chaining - supersede-writes.ts: Replace writesByFile.get() and readsByFile.get() with safe optional chaining Prevents potential runtime errors from Map state inconsistencies.
1 parent 9aa2692 commit ef4b069

2 files changed

Lines changed: 12 additions & 3 deletions

File tree

lib/strategies/deduplication.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,10 @@ export const deduplicate = (
5757
if (!signatureMap.has(signature)) {
5858
signatureMap.set(signature, [])
5959
}
60-
signatureMap.get(signature)!.push(id)
60+
const ids = signatureMap.get(signature)
61+
if (ids) {
62+
ids.push(id)
63+
}
6164
}
6265

6366
// Find duplicates - keep only the most recent (last) in each group

lib/strategies/supersede-writes.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,18 @@ export const supersedeWrites = (
6161
if (!writesByFile.has(filePath)) {
6262
writesByFile.set(filePath, [])
6363
}
64-
writesByFile.get(filePath)!.push({ id, index: i })
64+
const writes = writesByFile.get(filePath)
65+
if (writes) {
66+
writes.push({ id, index: i })
67+
}
6568
} else if (metadata.tool === "read") {
6669
if (!readsByFile.has(filePath)) {
6770
readsByFile.set(filePath, [])
6871
}
69-
readsByFile.get(filePath)!.push(i)
72+
const reads = readsByFile.get(filePath)
73+
if (reads) {
74+
reads.push(i)
75+
}
7076
}
7177
}
7278

0 commit comments

Comments
 (0)