Skip to content

Commit 4a7ae0a

Browse files
committed
fix:
1 parent b796fef commit 4a7ae0a

File tree

1 file changed

+12
-13
lines changed

1 file changed

+12
-13
lines changed

src/utils/errorTraceHandler.ts

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -105,31 +105,30 @@ async function getSourceMapConsumer(sourceMapPath: string | null): Promise<Sourc
105105
if (sourceMapContent === null) {
106106
return null;
107107
}
108-
return new Promise<SourceMapHandler>((resolve) => {
109-
SourceMapConsumer.with(sourceMapContent, null, (consumer) => {
110-
resolve(consumer);
111-
});
112-
});
108+
return await new SourceMapConsumer(sourceMapContent, undefined);
113109
}
114110

115111
export async function handleWebAssemblyError(
116112
error: WebAssembly.RuntimeError,
117113
wasmPath: string
118114
): Promise<ExecutionError> {
119-
const wasmBuffer = await readFile(wasmPath);
120-
const sourceMapPath = parseSourceMapPath(wasmBuffer.buffer as ArrayBuffer);
121-
const sourceMapConsumer: SourceMapHandler | null = await getSourceMapConsumer(sourceMapPath);
122-
let stacks: NodeJS.CallSite[] = [];
115+
let stackTrace: NodeJS.CallSite[] = [];
123116
const originalPrepareStackTrace = Error.prepareStackTrace;
124117
Error.prepareStackTrace = (_: Error, structuredStackTrace: NodeJS.CallSite[]) => {
125-
stacks = structuredStackTrace;
118+
stackTrace = structuredStackTrace;
126119
};
127120
error.stack; // trigger prepareStackTrace
128121
Error.prepareStackTrace = originalPrepareStackTrace;
122+
123+
const wasmBuffer = await readFile(wasmPath);
124+
const sourceMapPath = parseSourceMapPath(wasmBuffer.buffer as ArrayBuffer);
125+
const sourceMapConsumer: SourceMapHandler | null = await getSourceMapConsumer(sourceMapPath);
126+
const stacks = stackTrace
127+
.map((callSite) => createWebAssemblyCallSite(callSite, { wasmPath, sourceMapConsumer }))
128+
.filter((callSite) => callSite !== null);
129+
sourceMapConsumer?.destroy(); // clean up the source map consumer
129130
return {
130131
message: error.message,
131-
stacks: stacks
132-
.map((callSite) => createWebAssemblyCallSite(callSite, { wasmPath, sourceMapConsumer }))
133-
.filter((callSite) => callSite !== null),
132+
stacks,
134133
};
135134
}

0 commit comments

Comments
 (0)