Skip to content

Commit 67f6f8f

Browse files
committed
Fix decoding source map with VS Code internal files
This makes it possible to decode source maps containing references to code that is not part of the extension. If it finds any such references, it will simply not decode the source map and use the original stack trace instead.
1 parent 8d5574e commit 67f6f8f

File tree

1 file changed

+20
-6
lines changed

1 file changed

+20
-6
lines changed

extensions/ql-vscode/scripts/source-map.ts

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -115,21 +115,35 @@ async function extractSourceMap() {
115115
}
116116

117117
if (stacktrace.includes("at")) {
118-
const rawSourceMaps = new Map<string, RawSourceMap>();
118+
const rawSourceMaps = new Map<string, RawSourceMap | null>();
119119

120120
const mappedStacktrace = await replaceAsync(
121121
stacktrace,
122122
stackLineRegex,
123123
async (match, name, file, line, column) => {
124124
if (!rawSourceMaps.has(file)) {
125-
const rawSourceMap: RawSourceMap = await readJSON(
126-
resolve(sourceMapsDirectory, `${basename(file)}.map`),
127-
);
128-
rawSourceMaps.set(file, rawSourceMap);
125+
try {
126+
const rawSourceMap: RawSourceMap = await readJSON(
127+
resolve(sourceMapsDirectory, `${basename(file)}.map`),
128+
);
129+
rawSourceMaps.set(file, rawSourceMap);
130+
} catch (e: unknown) {
131+
// If the file is not found, we will not decode it and not try reading this source map again
132+
if (e instanceof Error && "code" in e && e.code === "ENOENT") {
133+
rawSourceMaps.set(file, null);
134+
} else {
135+
throw e;
136+
}
137+
}
138+
}
139+
140+
const sourceMap = rawSourceMaps.get(file) as RawSourceMap | null;
141+
if (!sourceMap) {
142+
return match;
129143
}
130144

131145
const originalPosition = await SourceMapConsumer.with(
132-
rawSourceMaps.get(file) as RawSourceMap,
146+
sourceMap,
133147
null,
134148
async function (consumer) {
135149
return consumer.originalPositionFor({

0 commit comments

Comments
 (0)