diag - introduce crash-reporter-directory to enable crash reporter for local folder

This commit is contained in:
Benjamin Pasero 2020-05-07 07:59:29 +02:00
parent dbb786567f
commit 3fab5de0b1
5 changed files with 47 additions and 10 deletions

View file

@ -32,6 +32,22 @@ const args = parseCLIArgs();
const userDataPath = getUserDataPath(args);
app.setPath('userData', userDataPath);
// Set temp directory based on crash-reporter-directory CLI argument
// The crash reporter will store crashes in temp folder so we need
// to change that location accordingly.
const crashReporterDirectory = args['crash-reporter-directory'];
if (crashReporterDirectory) {
if (!fs.existsSync(crashReporterDirectory)) {
try {
fs.mkdirSync(crashReporterDirectory);
} catch (error) {
console.error(`The path '${crashReporterDirectory}' specified for --crash-reporter-directory does not seem to exist or cannot be created.`);
app.exit(1);
}
}
app.setPath('temp', crashReporterDirectory);
}
// Set logs path before app 'ready' event if running portable
// to ensure that no 'logs' folder is created on disk at a
// location outside of the portable directory
@ -329,7 +345,8 @@ function parseCLIArgs() {
'user-data-dir',
'locale',
'js-flags',
'max-memory'
'max-memory',
'crash-reporter-directory'
]
});
}

View file

@ -62,6 +62,7 @@ export interface ParsedArgs {
'install-source'?: string;
'disable-updates'?: boolean;
'disable-crash-reporter'?: boolean;
'crash-reporter-directory'?: string;
'skip-add-to-recently-opened'?: boolean;
'max-memory'?: string;
'file-write'?: boolean;
@ -177,6 +178,7 @@ export const OPTIONS: OptionDescriptions<Required<ParsedArgs>> = {
'disable-telemetry': { type: 'boolean' },
'disable-updates': { type: 'boolean' },
'disable-crash-reporter': { type: 'boolean' },
'crash-reporter-directory': { type: 'string' },
'disable-user-env-probe': { type: 'boolean' },
'skip-add-to-recently-opened': { type: 'boolean' },
'unity-launch': { type: 'boolean' },

View file

@ -253,6 +253,7 @@ export class EnvironmentService implements INativeEnvironmentService {
get disableUpdates(): boolean { return !!this._args['disable-updates']; }
get disableCrashReporter(): boolean { return !!this._args['disable-crash-reporter']; }
get crashReporterDirectory(): string | undefined { return this._args['crash-reporter-directory']; }
get driverHandle(): string | undefined { return this._args['driver']; }
get driverVerbose(): boolean { return !!this._args['driver-verbose']; }

View file

@ -426,8 +426,20 @@ export class NativeWindow extends Disposable {
this.updateTouchbarMenu();
// Crash reporter (if enabled)
if (!this.environmentService.disableCrashReporter && product.crashReporter && product.appCenter && this.configurationService.getValue('telemetry.enableCrashReporter')) {
this.setupCrashReporter(product.crashReporter.companyName, product.crashReporter.productName, product.appCenter);
if (!this.environmentService.disableCrashReporter && this.configurationService.getValue('telemetry.enableCrashReporter')) {
const companyName = product.crashReporter?.companyName || 'Microsoft';
const productName = product.crashReporter?.productName || product.nameShort;
// With appCenter enabled, crashes will be uploaded
if (product.appCenter) {
this.setupCrashReporter(companyName, productName, product.appCenter, undefined);
}
// With a provided crash reporter directory, crashes
// will be stored only locally in that folder
else if (this.environmentService.crashReporterDirectory) {
this.setupCrashReporter(companyName, productName, undefined, this.environmentService.crashReporterDirectory);
}
}
}
@ -540,13 +552,14 @@ export class NativeWindow extends Disposable {
}
}
private async setupCrashReporter(companyName: string, productName: string, appCenterConfig: typeof product.appCenter): Promise<void> {
if (!appCenterConfig) {
return;
private async setupCrashReporter(companyName: string, productName: string, appCenter: typeof product.appCenter, crashesDirectory: undefined): Promise<void>;
private async setupCrashReporter(companyName: string, productName: string, appCenter: undefined, crashesDirectory: string): Promise<void>;
private async setupCrashReporter(companyName: string, productName: string, appCenter: typeof product.appCenter | undefined, crashesDirectory: string | undefined): Promise<void> {
let submitURL: string | undefined = undefined;
if (appCenter) {
submitURL = isWindows ? appCenter[process.arch === 'ia32' ? 'win32-ia32' : 'win32-x64'] : isLinux ? appCenter[`linux-x64`] : appCenter.darwin;
}
const appCenterURL = isWindows ? appCenterConfig[process.arch === 'ia32' ? 'win32-ia32' : 'win32-x64']
: isLinux ? appCenterConfig[`linux-x64`] : appCenterConfig.darwin;
const info = await this.telemetryService.getTelemetryInfo();
const crashReporterId = this.storageService.get(crashReporterIdStorageKey, StorageScope.GLOBAL)!;
@ -554,11 +567,14 @@ export class NativeWindow extends Disposable {
const options: CrashReporterStartOptions = {
companyName,
productName,
submitURL: appCenterURL.concat('&uid=', crashReporterId, '&iid=', crashReporterId, '&sid=', info.sessionId),
submitURL: (submitURL?.concat('&uid=', crashReporterId, '&iid=', crashReporterId, '&sid=', info.sessionId)) || '',
extra: {
vscode_version: product.version,
vscode_commit: product.commit || ''
}
},
// If `crashesDirectory` is specified, we do not upload
uploadToServer: !crashesDirectory,
};
// start crash reporter in the main process first.

View file

@ -18,6 +18,7 @@ export interface INativeWorkbenchEnvironmentService extends IWorkbenchEnvironmen
readonly configuration: INativeEnvironmentConfiguration;
readonly disableCrashReporter: boolean;
readonly crashReporterDirectory?: string;
readonly cliPath: string;