From 7e85afae69c7b5aa93be228609115b673a19d692 Mon Sep 17 00:00:00 2001 From: Jinbo Wang Date: Mon, 13 Sep 2021 14:02:59 +0800 Subject: [PATCH] Fix privacy in the logger (#1048) * Fix privacy in the logger * Improve the comment to clarify the reason for not tracking the errors --- src/configurationProvider.ts | 33 +++++++++++++++++++++++++++++++-- src/languageServerPlugin.ts | 5 +++++ src/utility.ts | 3 ++- 3 files changed, 38 insertions(+), 3 deletions(-) diff --git a/src/configurationProvider.ts b/src/configurationProvider.ts index 9c88ce2..27de003 100644 --- a/src/configurationProvider.ts +++ b/src/configurationProvider.ts @@ -6,7 +6,7 @@ import * as os from "os"; import * as path from "path"; import * as vscode from "vscode"; -import { instrumentOperation, sendInfo } from "vscode-extension-telemetry-wrapper"; +import { instrumentOperation, sendError, sendInfo, setUserError } from "vscode-extension-telemetry-wrapper"; import * as anchor from "./anchor"; import { buildWorkspace } from "./build"; import { populateStepFilters, substituteFilterVariables } from "./classFilter"; @@ -539,16 +539,43 @@ export class JavaDebugConfigurationProvider implements vscode.DebugConfiguration } } + private getValidationErrorMessage(error: lsPlugin.IValidationResult): string { + switch (error.kind) { + case lsPlugin.CONFIGERROR_INVALID_CLASS_NAME: + return "ConfigError: mainClass was configured with an invalid class name."; + case lsPlugin.CONFIGERROR_MAIN_CLASS_NOT_EXIST: + return "ConfigError: mainClass does not exist."; + case lsPlugin.CONFIGERROR_MAIN_CLASS_NOT_UNIQUE: + return "ConfigError: mainClass is not unique in the workspace"; + case lsPlugin.CONFIGERROR_INVALID_JAVA_PROJECT: + return "ConfigError: could not find a Java project with the configured projectName."; + } + + return "ConfigError: Invalid mainClass/projectName configs."; + } + private async fixMainClass(folder: vscode.Uri | undefined, config: vscode.DebugConfiguration, validationResponse: lsPlugin.ILaunchValidationResponse, progressReporter: IProgressReporter): Promise { const errors: string[] = []; if (!validationResponse.mainClass.isValid) { errors.push(String(validationResponse.mainClass.message)); + const errorLog: Error = { + name: "error", + message: this.getValidationErrorMessage(validationResponse.mainClass), + }; + setUserError(errorLog); + sendError(errorLog); } if (!validationResponse.projectName.isValid) { errors.push(String(validationResponse.projectName.message)); + const errorLog: Error = { + name: "error", + message: this.getValidationErrorMessage(validationResponse.projectName), + }; + setUserError(errorLog); + sendError(errorLog); } if (validationResponse.proposals && validationResponse.proposals.length) { @@ -557,6 +584,7 @@ export class JavaDebugConfigurationProvider implements vscode.DebugConfiguration message: errors.join(os.EOL), type: Type.USAGEERROR, anchor: anchor.FAILED_TO_RESOLVE_CLASSPATH, + bypassLog: true, // Avoid logging the raw user input in the logger for privacy. }, "Fix"); if (answer === "Fix") { const selectedFix = await mainClassPicker.showQuickPick(validationResponse.proposals, @@ -564,7 +592,7 @@ export class JavaDebugConfigurationProvider implements vscode.DebugConfiguration if (selectedFix) { sendInfo("", { fix: "yes", - fixMessage: errors.join(os.EOL), + fixMessage: "Fix the configs of mainClass and projectName", }); await this.persistMainClassOption(folder, config, selectedFix); } @@ -579,6 +607,7 @@ export class JavaDebugConfigurationProvider implements vscode.DebugConfiguration message: errors.join(os.EOL), type: Type.USAGEERROR, anchor: anchor.FAILED_TO_RESOLVE_CLASSPATH, + bypassLog: true, // Avoid logging the raw user input in the logger for privacy. }); } diff --git a/src/languageServerPlugin.ts b/src/languageServerPlugin.ts index ea1cbd6..9bf395d 100644 --- a/src/languageServerPlugin.ts +++ b/src/languageServerPlugin.ts @@ -23,9 +23,14 @@ export interface IMainMethod extends IMainClassOption { range: vscode.Range; } +export const CONFIGERROR_INVALID_CLASS_NAME = 1; +export const CONFIGERROR_MAIN_CLASS_NOT_EXIST = 2; +export const CONFIGERROR_MAIN_CLASS_NOT_UNIQUE = 3; +export const CONFIGERROR_INVALID_JAVA_PROJECT = 4; export interface IValidationResult { readonly isValid: boolean; readonly message?: string; + readonly kind?: number; } export interface ILaunchValidationResponse { diff --git a/src/utility.ts b/src/utility.ts index aa9b82c..c075267 100644 --- a/src/utility.ts +++ b/src/utility.ts @@ -40,6 +40,7 @@ interface ILoggingMessage { type?: Type; message: string; stack?: string; + bypassLog?: boolean; } interface ITroubleshootingMessage extends ILoggingMessage { @@ -47,7 +48,7 @@ interface ITroubleshootingMessage extends ILoggingMessage { } function logMessage(message: ILoggingMessage): void { - if (!message.type) { + if (!message.type || message.bypassLog) { return; }