Skip to content

Commit a7f8019

Browse files
authored
Merge pull request #2987 from github/koesie10/source-map-fix
Fix decoding source map with VS Code internal files
2 parents abde8f3 + 2d5caa7 commit a7f8019

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);
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)