Skip to content

Commit 3ec417e

Browse files
authored
detach tags from error messages (#1027)
Signed-off-by: Yan Zhang <yanzh@microsoft.com>
1 parent e5fb73d commit 3ec417e

2 files changed

Lines changed: 43 additions & 28 deletions

File tree

src/daemon/serverLog/logWatcher.ts

Lines changed: 33 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -56,16 +56,22 @@ export class LogWatcher {
5656
const consentToCollectLogs = vscode.workspace.getConfiguration("java").get<boolean>("help.collectErrorLog");
5757
if (errors) {
5858
errors.forEach(e => {
59-
consentToCollectLogs ? sendInfo("", {
60-
name: "jdtls-error",
61-
error: e.message,
62-
stack: e.stack!,
63-
timestamp: e.timestamp!.toString()
64-
}) : sendInfo("", {
65-
name: "jdtls-error",
66-
error: redact(e.message),
67-
timestamp: e.timestamp!.toString()
68-
});
59+
if (consentToCollectLogs) {
60+
sendInfo("", {
61+
name: "jdtls-error",
62+
error: e.message,
63+
stack: e.stack!,
64+
timestamp: e.timestamp!.toString()
65+
});
66+
} else {
67+
const {message, tags} = redact(e.message);
68+
sendInfo("", {
69+
name: "jdtls-error",
70+
error: message,
71+
tags: tags.join(","),
72+
timestamp: e.timestamp!.toString()
73+
})
74+
}
6975
})
7076
}
7177
this.logProcessedTimestamp = Date.now();
@@ -108,16 +114,23 @@ export class LogWatcher {
108114
const consentToCollectLogs = vscode.workspace.getConfiguration("java").get<boolean>("help.collectErrorLog");
109115
if (errors) {
110116
errors.forEach(e => {
111-
consentToCollectLogs ? sendInfo("", {
112-
name: "jdtls-error-in-crashed-session",
113-
error: e.message,
114-
stack: e.stack!,
115-
timestamp: e.timestamp!.toString()
116-
}) : sendInfo("", {
117-
name: "jdtls-error-in-crashed-session",
118-
error: redact(e.message),
119-
timestamp: e.timestamp!.toString()
120-
});
117+
if (consentToCollectLogs) {
118+
sendInfo("", {
119+
name: "jdtls-error-in-crashed-session",
120+
error: e.message,
121+
stack: e.stack!,
122+
timestamp: e.timestamp!.toString()
123+
})
124+
} else {
125+
const { message, tags } = redact(e.message);
126+
sendInfo("", {
127+
name: "jdtls-error-in-crashed-session",
128+
error: message,
129+
tags: tags.join(","),
130+
timestamp: e.timestamp!.toString()
131+
})
132+
}
133+
121134
})
122135
}
123136
}

src/daemon/serverLog/whitelist.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,15 @@ const MESSAGE_WHITELIST: string[] = [
4242
"Workspace restored, but some problems occurred.",
4343
];
4444

45-
export function redact(rawMessage: string): string {
46-
const matchedMessage = MESSAGE_WHITELIST.find(msg => rawMessage.includes(msg));
47-
if (matchedMessage) {
48-
return matchedMessage;
49-
} else {
50-
const lower = rawMessage.toLocaleLowerCase();
51-
const tags = TAGS.filter(tag => lower.includes(tag));
52-
return tags.length > 0 ? `Tags:${tags.join(",")}` : "";
45+
export function redact(rawMessage: string): {
46+
message: string;
47+
tags: string[];
48+
} {
49+
const message = MESSAGE_WHITELIST.find(msg => rawMessage.includes(msg)) ?? "";
50+
const tags = TAGS.filter(tag => rawMessage.toLocaleLowerCase().includes(tag));
51+
52+
return {
53+
message,
54+
tags
5355
}
5456
}

0 commit comments

Comments
 (0)