refactor: setup errorTelemetry from electron-main (#244020)

This commit is contained in:
Robo
2025-03-20 12:10:07 +09:00
committed by GitHub
parent 2b7ffdea69
commit 8dd2ad65d4
3 changed files with 42 additions and 37 deletions

View File

@@ -9,7 +9,6 @@ import { validatedIpcMain } from '../../base/parts/ipc/electron-main/ipcMain.js'
import { hostname, release } from 'os';
import { VSBuffer } from '../../base/common/buffer.js';
import { toErrorMessage } from '../../base/common/errorMessage.js';
import { isSigPipeError, onUnexpectedError, setUnexpectedErrorHandler } from '../../base/common/errors.js';
import { Event } from '../../base/common/event.js';
import { parse } from '../../base/common/jsonc.js';
import { getPathLabel } from '../../base/common/labels.js';
@@ -122,6 +121,7 @@ import { INativeMcpDiscoveryHelperService, NativeMcpDiscoveryHelperChannelName }
import { NativeMcpDiscoveryHelperService } from '../../platform/mcp/node/nativeMcpDiscoveryHelperService.js';
import { IWebContentExtractorService } from '../../platform/webContentExtractor/common/webContentExtractor.js';
import { NativeWebContentExtractorService } from '../../platform/webContentExtractor/electron-main/webContentExtractorService.js';
import ErrorTelemetry from '../../platform/telemetry/electron-main/errorTelemetry.js';
/**
* The main VS Code application. There will only ever be one instance,
@@ -373,15 +373,6 @@ export class CodeApplication extends Disposable {
private registerListeners(): void {
// We handle uncaught exceptions here to prevent electron from opening a dialog to the user
setUnexpectedErrorHandler(error => this.onUnexpectedError(error));
process.on('uncaughtException', error => {
if (!isSigPipeError(error)) {
onUnexpectedError(error);
}
});
process.on('unhandledRejection', (reason: unknown) => onUnexpectedError(reason));
// Dispose on shutdown
Event.once(this.lifecycleMainService.onWillShutdown)(() => this.dispose());
@@ -528,25 +519,6 @@ export class CodeApplication extends Disposable {
//#endregion
}
private onUnexpectedError(error: Error): void {
if (error) {
// take only the message and stack property
const friendlyError = {
message: `[uncaught exception in main]: ${error.message}`,
stack: error.stack
};
// handle on client side
this.windowsMainService?.sendToFocused('vscode:reportError', JSON.stringify(friendlyError));
}
this.logService.error(`[uncaught exception in main]: ${error}`);
if (error.stack) {
this.logService.error(error.stack);
}
}
async startup(): Promise<void> {
this.logService.debug('Starting VS Code');
this.logService.debug(`from: ${this.environmentMainService.appRoot}`);
@@ -603,6 +575,9 @@ export class CodeApplication extends Disposable {
// Services
const appInstantiationService = await this.initServices(machineId, sqmId, devDeviceId, sharedProcessReady);
// Error telemetry
appInstantiationService.invokeFunction(accessor => this._register(new ErrorTelemetry(accessor.get(ILogService), accessor.get(ITelemetryService))));
// Auth Handler
appInstantiationService.invokeFunction(accessor => accessor.get(IProxyAuthService));