Skip to content

Commit 7e85afa

Browse files
Fix privacy in the logger (#1048)
* Fix privacy in the logger * Improve the comment to clarify the reason for not tracking the errors
1 parent a971831 commit 7e85afa

File tree

3 files changed

+38
-3
lines changed

3 files changed

+38
-3
lines changed

src/configurationProvider.ts

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import * as os from "os";
66
import * as path from "path";
77
import * as vscode from "vscode";
88

9-
import { instrumentOperation, sendInfo } from "vscode-extension-telemetry-wrapper";
9+
import { instrumentOperation, sendError, sendInfo, setUserError } from "vscode-extension-telemetry-wrapper";
1010
import * as anchor from "./anchor";
1111
import { buildWorkspace } from "./build";
1212
import { populateStepFilters, substituteFilterVariables } from "./classFilter";
@@ -539,16 +539,43 @@ export class JavaDebugConfigurationProvider implements vscode.DebugConfiguration
539539
}
540540
}
541541

542+
private getValidationErrorMessage(error: lsPlugin.IValidationResult): string {
543+
switch (error.kind) {
544+
case lsPlugin.CONFIGERROR_INVALID_CLASS_NAME:
545+
return "ConfigError: mainClass was configured with an invalid class name.";
546+
case lsPlugin.CONFIGERROR_MAIN_CLASS_NOT_EXIST:
547+
return "ConfigError: mainClass does not exist.";
548+
case lsPlugin.CONFIGERROR_MAIN_CLASS_NOT_UNIQUE:
549+
return "ConfigError: mainClass is not unique in the workspace";
550+
case lsPlugin.CONFIGERROR_INVALID_JAVA_PROJECT:
551+
return "ConfigError: could not find a Java project with the configured projectName.";
552+
}
553+
554+
return "ConfigError: Invalid mainClass/projectName configs.";
555+
}
556+
542557
private async fixMainClass(folder: vscode.Uri | undefined, config: vscode.DebugConfiguration,
543558
validationResponse: lsPlugin.ILaunchValidationResponse, progressReporter: IProgressReporter):
544559
Promise<lsPlugin.IMainClassOption | undefined> {
545560
const errors: string[] = [];
546561
if (!validationResponse.mainClass.isValid) {
547562
errors.push(String(validationResponse.mainClass.message));
563+
const errorLog: Error = {
564+
name: "error",
565+
message: this.getValidationErrorMessage(validationResponse.mainClass),
566+
};
567+
setUserError(errorLog);
568+
sendError(errorLog);
548569
}
549570

550571
if (!validationResponse.projectName.isValid) {
551572
errors.push(String(validationResponse.projectName.message));
573+
const errorLog: Error = {
574+
name: "error",
575+
message: this.getValidationErrorMessage(validationResponse.projectName),
576+
};
577+
setUserError(errorLog);
578+
sendError(errorLog);
552579
}
553580

554581
if (validationResponse.proposals && validationResponse.proposals.length) {
@@ -557,14 +584,15 @@ export class JavaDebugConfigurationProvider implements vscode.DebugConfiguration
557584
message: errors.join(os.EOL),
558585
type: Type.USAGEERROR,
559586
anchor: anchor.FAILED_TO_RESOLVE_CLASSPATH,
587+
bypassLog: true, // Avoid logging the raw user input in the logger for privacy.
560588
}, "Fix");
561589
if (answer === "Fix") {
562590
const selectedFix = await mainClassPicker.showQuickPick(validationResponse.proposals,
563591
"Please select main class<project name>.", false);
564592
if (selectedFix) {
565593
sendInfo("", {
566594
fix: "yes",
567-
fixMessage: errors.join(os.EOL),
595+
fixMessage: "Fix the configs of mainClass and projectName",
568596
});
569597
await this.persistMainClassOption(folder, config, selectedFix);
570598
}
@@ -579,6 +607,7 @@ export class JavaDebugConfigurationProvider implements vscode.DebugConfiguration
579607
message: errors.join(os.EOL),
580608
type: Type.USAGEERROR,
581609
anchor: anchor.FAILED_TO_RESOLVE_CLASSPATH,
610+
bypassLog: true, // Avoid logging the raw user input in the logger for privacy.
582611
});
583612
}
584613

src/languageServerPlugin.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,14 @@ export interface IMainMethod extends IMainClassOption {
2323
range: vscode.Range;
2424
}
2525

26+
export const CONFIGERROR_INVALID_CLASS_NAME = 1;
27+
export const CONFIGERROR_MAIN_CLASS_NOT_EXIST = 2;
28+
export const CONFIGERROR_MAIN_CLASS_NOT_UNIQUE = 3;
29+
export const CONFIGERROR_INVALID_JAVA_PROJECT = 4;
2630
export interface IValidationResult {
2731
readonly isValid: boolean;
2832
readonly message?: string;
33+
readonly kind?: number;
2934
}
3035

3136
export interface ILaunchValidationResponse {

src/utility.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,15 @@ interface ILoggingMessage {
4040
type?: Type;
4141
message: string;
4242
stack?: string;
43+
bypassLog?: boolean;
4344
}
4445

4546
interface ITroubleshootingMessage extends ILoggingMessage {
4647
anchor?: string;
4748
}
4849

4950
function logMessage(message: ILoggingMessage): void {
50-
if (!message.type) {
51+
if (!message.type || message.bypassLog) {
5152
return;
5253
}
5354

0 commit comments

Comments
 (0)