(client: TelemetryClient)
| 17 | } |
| 18 | |
| 19 | export function installCrashHandlersForClient(client: TelemetryClient): () => void { |
| 20 | if (installed && installedUncaughtHandler !== null) { |
| 21 | return () => { |
| 22 | uninstallCrashHandlers(); |
| 23 | }; |
| 24 | } |
| 25 | const trackCrash = (errorType: string, source: string) => { |
| 26 | try { |
| 27 | client.track('crash', { |
| 28 | error_type: errorType, |
| 29 | where: phase, |
| 30 | source, |
| 31 | }); |
| 32 | client.flushSync(); |
| 33 | } catch { |
| 34 | // Crash telemetry must never mask the original exception. |
| 35 | } |
| 36 | }; |
| 37 | installedUncaughtHandler = (error, origin) => { |
| 38 | if (isAbortError(error)) return; |
| 39 | trackCrash(error.name || error.constructor.name, origin); |
| 40 | }; |
| 41 | process.on('uncaughtExceptionMonitor', installedUncaughtHandler); |
| 42 | installed = true; |
| 43 | return () => { |
| 44 | uninstallCrashHandlers(); |
| 45 | }; |
| 46 | } |
| 47 | |
| 48 | export function uninstallCrashHandlers(): void { |
| 49 | if (!installed) return; |
no test coverage detected