Fix privacy in the logger (#1048)

* Fix privacy in the logger
* Improve the comment to clarify the reason for not tracking the errors
This commit is contained in:
Jinbo Wang 2021-09-13 14:02:59 +08:00 committed by GitHub
parent a971831ea2
commit 7e85afae69
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 38 additions and 3 deletions

View File

@ -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<lsPlugin.IMainClassOption | undefined> {
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.
});
}

View File

@ -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 {

View File

@ -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;
}