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.
This commit is contained in:
@@ -115,21 +115,35 @@ async function extractSourceMap() {
|
||||
}
|
||||
|
||||
if (stacktrace.includes("at")) {
|
||||
const rawSourceMaps = new Map<string, RawSourceMap>();
|
||||
const rawSourceMaps = new Map<string, RawSourceMap | null>();
|
||||
|
||||
const mappedStacktrace = await replaceAsync(
|
||||
stacktrace,
|
||||
stackLineRegex,
|
||||
async (match, name, file, line, column) => {
|
||||
if (!rawSourceMaps.has(file)) {
|
||||
const rawSourceMap: RawSourceMap = await readJSON(
|
||||
resolve(sourceMapsDirectory, `${basename(file)}.map`),
|
||||
);
|
||||
rawSourceMaps.set(file, rawSourceMap);
|
||||
try {
|
||||
const rawSourceMap: RawSourceMap = await readJSON(
|
||||
resolve(sourceMapsDirectory, `${basename(file)}.map`),
|
||||
);
|
||||
rawSourceMaps.set(file, rawSourceMap);
|
||||
} catch (e: unknown) {
|
||||
// If the file is not found, we will not decode it and not try reading this source map again
|
||||
if (e instanceof Error && "code" in e && e.code === "ENOENT") {
|
||||
rawSourceMaps.set(file, null);
|
||||
} else {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const sourceMap = rawSourceMaps.get(file) as RawSourceMap | null;
|
||||
if (!sourceMap) {
|
||||
return match;
|
||||
}
|
||||
|
||||
const originalPosition = await SourceMapConsumer.with(
|
||||
rawSourceMaps.get(file) as RawSourceMap,
|
||||
sourceMap,
|
||||
null,
|
||||
async function (consumer) {
|
||||
return consumer.originalPositionFor({
|
||||
|
||||
Reference in New Issue
Block a user