Handle errors in tracing for environments that don't support Error.captureStackTrace (i.e. firefox) (#3623)
Error.captureStackTrace is used to get stacktrace for tracing details, but it's not supported in some browser like firefox, so add handling for it. thanks. --------- Co-authored-by: Timothee Guerin <timothee.guerin@outlook.com>
This commit is contained in:
Родитель
aed8ebc215
Коммит
224e725e43
|
@ -0,0 +1,7 @@
|
|||
---
|
||||
changeKind: fix
|
||||
packages:
|
||||
- "@typespec/compiler"
|
||||
---
|
||||
|
||||
Fix crash of language server on firefox
|
|
@ -48,9 +48,17 @@ export function createFileSystemCache({
|
|||
changes = [];
|
||||
const r = cache.get(path);
|
||||
if (!r) {
|
||||
const target: any = {};
|
||||
Error.captureStackTrace(target);
|
||||
const callstack = target.stack.substring("Error\n".length);
|
||||
let callstack: string | undefined;
|
||||
try {
|
||||
const target: any = {};
|
||||
// some browser doesn't support Error.captureStackTrace (i.e. Firefox)
|
||||
if (typeof Error.captureStackTrace === "function") {
|
||||
Error.captureStackTrace(target);
|
||||
callstack = target.stack.substring("Error\n".length);
|
||||
}
|
||||
} catch {
|
||||
// just ignore the error, we don't want tracing error to impact normal functionality
|
||||
}
|
||||
log({ level: "trace", message: `FileSystemCache miss for ${path}`, detail: callstack });
|
||||
}
|
||||
return r;
|
||||
|
|
Загрузка…
Ссылка в новой задаче