UNPKG

@sussudio/platform

Version:

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

46 lines (45 loc) 1.82 kB
/*--------------------------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ import { isCancellationError, onUnexpectedError, setUnexpectedErrorHandler } from '@sussudio/base/common/errors.mjs'; import BaseErrorTelemetry from '../common/errorTelemetry.mjs'; export default class ErrorTelemetry extends BaseErrorTelemetry { installErrorListeners() { setUnexpectedErrorHandler((err) => console.error(err)); // Print a console message when rejection isn't handled within N seconds. For details: // see https://nodejs.org/api/process.html#process_event_unhandledrejection // and https://nodejs.org/api/process.html#process_event_rejectionhandled const unhandledPromises = []; process.on('unhandledRejection', (reason, promise) => { unhandledPromises.push(promise); setTimeout(() => { const idx = unhandledPromises.indexOf(promise); if (idx >= 0) { promise.catch((e) => { unhandledPromises.splice(idx, 1); if (!isCancellationError(e)) { console.warn(`rejected promise not handled within 1 second: ${e}`); if (e.stack) { console.warn(`stack trace: ${e.stack}`); } if (reason) { onUnexpectedError(reason); } } }); } }, 1000); }); process.on('rejectionHandled', (promise) => { const idx = unhandledPromises.indexOf(promise); if (idx >= 0) { unhandledPromises.splice(idx, 1); } }); // Print a console message when an exception isn't handled. process.on('uncaughtException', (err) => { onUnexpectedError(err); }); } }