Skip to content

Commit 2756d12

Browse files
authored
focusing on specific error in server logs (#947)
1 parent 6531008 commit 2756d12

File tree

3 files changed

+78
-12
lines changed

3 files changed

+78
-12
lines changed

src/daemon/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ async function checkJavaExtActivated(_context: vscode.ExtensionContext): Promise
4444
if (mode === "Standard") {
4545
daemon.logWatcher.sendStartupMetadata("jdtls standard server ready");
4646

47+
daemon.logWatcher.stop(); // Only focus on errors occurred during startup.
48+
4749
// watchdog
4850
if (await daemon.processWatcher.start()) {
4951
daemon.processWatcher.monitor();

src/daemon/serverLog/logWatcher.ts

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,19 @@ import { sendInfo } from "vscode-extension-telemetry-wrapper";
88
import { LSDaemon } from "../daemon";
99
import { collectErrors, collectErrorsSince, logsForLatestSession, sessionMetadata } from "./logUtils";
1010
import { toElapsed } from "./utils";
11+
import { redact } from "./whitelist";
1112

1213
export class LogWatcher {
1314
private serverLogUri: vscode.Uri | undefined;
1415
private logProcessedTimestamp: number = Date.now();
1516
private context: vscode.ExtensionContext;
17+
private watcher: vscode.FileSystemWatcher | undefined;
1618
constructor(daemon: LSDaemon) {
1719
this.context = daemon.context;
1820
if (this.context.storageUri) {
1921
const javaExtStoragePath: string = path.join(this.context.storageUri.fsPath, "..", "redhat.java");
2022
const serverLogPath: string = path.join(javaExtStoragePath, "jdt_ws", ".metadata");
21-
this.serverLogUri = this.context.storageUri.with({path: serverLogPath});
23+
this.serverLogUri = this.context.storageUri.with({ path: serverLogPath });
2224
}
2325
}
2426

@@ -27,20 +29,20 @@ export class LogWatcher {
2729
*/
2830
public async start() {
2931
if (!this.serverLogUri) {
30-
sendInfo("", {name: "no-server-log"});
32+
sendInfo("", { name: "no-server-log" });
3133
return;
32-
}
34+
}
3335

3436
try {
3537
await fs.promises.access(this.serverLogUri.fsPath);
3638
} catch (error) {
37-
sendInfo("", {name: "no-server-log"});
39+
sendInfo("", { name: "no-server-log" });
3840
return;
3941
}
4042

41-
const watcher = vscode.workspace.createFileSystemWatcher(new vscode.RelativePattern(this.serverLogUri, "*.log"));
42-
watcher.onDidChange(async (e)=> {
43-
if (Date.now() - this.logProcessedTimestamp < 1000) {return;} // reduce frequency of log file I/O.
43+
this.watcher = vscode.workspace.createFileSystemWatcher(new vscode.RelativePattern(this.serverLogUri, "*.log"));
44+
this.watcher.onDidChange(async (e) => {
45+
if (Date.now() - this.logProcessedTimestamp < 1000) { return; } // reduce frequency of log file I/O.
4446
const logs = await logsForLatestSession(e.fsPath);
4547
const errors = collectErrorsSince(logs, this.logProcessedTimestamp);
4648
const consentToCollectLogs = vscode.workspace.getConfiguration("java").get<boolean>("help.shareDiagnostics");
@@ -53,6 +55,7 @@ export class LogWatcher {
5355
timestamp: e.timestamp!.toString()
5456
}) : sendInfo("", {
5557
name: "jdtls-error",
58+
error: redact(e.message),
5659
timestamp: e.timestamp!.toString()
5760
});
5861
})
@@ -61,13 +64,20 @@ export class LogWatcher {
6164
});
6265
}
6366

67+
public stop() {
68+
if (this.watcher) {
69+
this.watcher.dispose()
70+
this.watcher = undefined;
71+
}
72+
}
73+
6474
/**
6575
* metadata
6676
*/
6777
public async sendStartupMetadata(remark?: string) {
68-
if (this.serverLogUri){
69-
const logs = await logsForLatestSession(path.join(this.serverLogUri?.fsPath, ".log"));
70-
const metadata = sessionMetadata(logs);
78+
if (this.serverLogUri) {
79+
const logs = await logsForLatestSession(path.join(this.serverLogUri?.fsPath, ".log"));
80+
const metadata = sessionMetadata(logs);
7181
sendInfo("", {
7282
name: "jdtls-startup-metadata",
7383
remark: remark!,
@@ -84,8 +94,8 @@ export class LogWatcher {
8494
}
8595

8696
public async sendErrorAndStackOnCrash() {
87-
if (this.serverLogUri){
88-
const logs = await logsForLatestSession(path.join(this.serverLogUri?.fsPath, ".log"));
97+
if (this.serverLogUri) {
98+
const logs = await logsForLatestSession(path.join(this.serverLogUri?.fsPath, ".log"));
8999
const errors = collectErrors(logs);
90100
const consentToCollectLogs = vscode.workspace.getConfiguration("java").get<boolean>("help.shareDiagnostics");
91101
if (errors) {
@@ -97,6 +107,7 @@ export class LogWatcher {
97107
timestamp: e.timestamp!.toString()
98108
}) : sendInfo("", {
99109
name: "jdtls-error-in-crashed-session",
110+
error: redact(e.message),
100111
timestamp: e.timestamp!.toString()
101112
});
102113
})

src/daemon/serverLog/whitelist.ts

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT license.
3+
4+
const TAGS: string[] = [
5+
"buildship",
6+
"m2e",
7+
"gradle",
8+
"maven",
9+
"bundle"
10+
];
11+
12+
const MESSAGE_WHITELIST: string[] = [
13+
"Application error",
14+
"BadLocationException",
15+
"Could not load Gradle version information",
16+
"Error computing hover",
17+
"Error in calling delegate command handler",
18+
"Error in JDT Core during AST creation",
19+
"Error occurred while deleting",
20+
"Error filtering index locations based on qualifier.",
21+
"Failed to publish diagnostics for",
22+
"Failed to detect project changes",
23+
"Failed to update qualified index.",
24+
"Failed to launch debuggee in terminal. Reason: java.util.concurrent.TimeoutException: timeout",
25+
"Failed to save JDT index",
26+
"failed to send diagnostics",
27+
"FrameworkEvent ERROR",
28+
"Initialization failed",
29+
"Index out of bounds",
30+
"JavaBuilder handling CoreException",
31+
"Offset > length",
32+
"Problems occurred when invoking code from plug-in: \"org.eclipse.jdt.ls.core\".",
33+
"Problems occurred when invoking code from plug-in: \"org.eclipse.core.resources\".",
34+
"Problems occurred when invoking code from plug-in: \"org.eclipse.jdt.core.manipulation\".",
35+
"Problem resolving refactor code actions",
36+
"Problem with folding range",
37+
"Problem with codeComplete for",
38+
"Synchronize Gradle projects with workspace failed due to an error connecting to the Gradle build.",
39+
"Synchronize Gradle projects with workspace failed due to an error in the referenced Gradle build.",
40+
"Unable to read JavaModelManager nonChainingJarsCache file",
41+
"Workspace restored, but some problems occurred.",
42+
];
43+
44+
export function redact(rawMessage: string): string {
45+
const matchedMessage = MESSAGE_WHITELIST.find(msg => rawMessage.includes(msg));
46+
if (matchedMessage) {
47+
return matchedMessage;
48+
} else {
49+
const lower = rawMessage.toLocaleLowerCase();
50+
const tags = TAGS.filter(tag => lower.includes(tag));
51+
return tags.length > 0 ? `Tags:${tags.join(",")}` : "";
52+
}
53+
}

0 commit comments

Comments
 (0)