UNPKG

@sussudio/platform

Version:

Internal APIs for VS Code's service injection the base services.

53 lines (52 loc) 1.69 kB
/*--------------------------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ import { ErrorNoTelemetry } from '@sussudio/base/common/errors.mjs'; import { toDisposable } from '@sussudio/base/common/lifecycle.mjs'; import { globals } from '@sussudio/base/common/platform.mjs'; import BaseErrorTelemetry from '../common/errorTelemetry.mjs'; export default class ErrorTelemetry extends BaseErrorTelemetry { installErrorListeners() { let oldOnError; const that = this; if (typeof globals.onerror === 'function') { oldOnError = globals.onerror; } globals.onerror = function (message, filename, line, column, e) { that._onUncaughtError(message, filename, line, column, e); oldOnError?.apply(this, arguments); }; this._disposables.add( toDisposable(() => { if (oldOnError) { globals.onerror = oldOnError; } }), ); } _onUncaughtError(msg, file, line, column, err) { const data = { callstack: msg, msg, file, line, column, }; if (err) { // If it's the no telemetry error it doesn't get logged if (ErrorNoTelemetry.isErrorNoTelemetry(err)) { return; } const { name, message, stack } = err; data.uncaught_error_name = name; if (message) { data.uncaught_error_msg = message; } if (stack) { data.callstack = Array.isArray(err.stack) ? (err.stack = err.stack.join('\n')) : err.stack; } } this._enqueue(data); } }