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 = [];
|
changes = [];
|
||||||
const r = cache.get(path);
|
const r = cache.get(path);
|
||||||
if (!r) {
|
if (!r) {
|
||||||
const target: any = {};
|
let callstack: string | undefined;
|
||||||
Error.captureStackTrace(target);
|
try {
|
||||||
const callstack = target.stack.substring("Error\n".length);
|
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 });
|
log({ level: "trace", message: `FileSystemCache miss for ${path}`, detail: callstack });
|
||||||
}
|
}
|
||||||
return r;
|
return r;
|
||||||
|
|
Загрузка…
Ссылка в новой задаче