Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
94 changes: 71 additions & 23 deletions vscode/core/src/client/analyzerClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import { Logger } from "winston";
import { executeExtensionCommand } from "../commands";

const uid = (() => {

Check warning on line 28 in vscode/core/src/client/analyzerClient.ts

View workflow job for this annotation

GitHub Actions / Lint

'uid' is assigned a value but never used
let counter = 0;
return (prefix: string = "") => `${prefix}${counter++}`;
})();
Expand Down Expand Up @@ -111,29 +111,6 @@

const pipeName = rpc.generateRandomPipeName();
const [analyzerRpcServer, analyzerPid] = this.startAnalysisServer(pipeName);
analyzerRpcServer.on("exit", (code, signal) => {
this.logger.info(`Analyzer RPC server terminated [signal: ${signal}, code: ${code}]`);
if (code) {
vscode.window.showErrorMessage(
`Analyzer RPC server failed. Status code: ${code}. Please see the output channel for details.`,
);
}
this.fireServerStateChange("stopped");
this.analyzerRpcServer = null;
});
analyzerRpcServer.on("close", (code, signal) => {
this.logger.info(`Analyzer RPC server closed [signal: ${signal}, code: ${code}]`);
this.fireServerStateChange("stopped");
this.analyzerRpcServer = null;
});
analyzerRpcServer.on("error", (err) => {
this.logger.error("Analyzer RPC server error", err);
this.fireServerStateChange("startFailed");
this.analyzerRpcServer = null;
vscode.window.showErrorMessage(
`Analyzer RPC server failed - ${err instanceof Error ? err.message : String(err)}`,
);
});
this.analyzerRpcServer = analyzerRpcServer;
this.logger.info(`Analyzer RPC server started successfully [pid: ${analyzerPid}]`);

Expand Down Expand Up @@ -311,9 +288,80 @@
},
);

// Buffer to collect stderr for error analysis
let stderrBuffer = "";

analyzerRpcServer.stderr.on("data", (data) => {
const asString: string = data.toString().trimEnd();
this.logger.error(`${asString}`);
// Collect stderr for potential Java/Maven error detection
stderrBuffer += asString + "\n";
});

// Handle exit event with Java/Maven error detection
analyzerRpcServer.on("exit", (code, signal) => {
this.logger.info(`Analyzer RPC server terminated [signal: ${signal}, code: ${code}]`);

if (code) {
// Check if it's the specific Java error
if (stderrBuffer.toLowerCase().includes("java is not installed")) {
// Show user-friendly Java error with action button
vscode.window
.showErrorMessage(
"Java runtime is required for the analyzer server but was not found. " +
"Please install Red Hat OpenJDK (JDK 11 or later) and ensure the 'java' " +
"command is available in your system PATH.",
"Install Red Hat OpenJDK",
)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion | 🟠 Major

🧩 Analysis chain

Verify the Java error message across platforms.

The detection relies on an exact string match (case-insensitive) for "java is not installed or not on the path". Error message text can vary across operating systems, Java implementations, or analyzer versions.

Run this script to search for the error message generation in the analyzer codebase:

Consider using a regex pattern or checking for multiple known Java error indicators (e.g., "java.*not found", "JAVA_HOME.*not set", "command not found.*java") to make the detection more robust across different environments.


🏁 Script executed:

#!/bin/bash
# Search for where this error message is generated in the analyzer
rg -i "java is not installed" -A 2 -B 2
rg -i "not on the path" -A 2 -B 2
rg -i "java.*not.*found" -A 2 -B 2

Length of output: 278104


Improve Java‐not‐available detection
Relying on a single text check for “java is not installed or not on the path” is brittle. Update this to match multiple known error patterns (e.g. /java.*not found/, /command not found.*java/, /JAVA_HOME.*not set/) or consolidate into one regex to catch variations across platforms.
Location: vscode/src/client/analyzerClient.ts:307

🤖 Prompt for AI Agents
In vscode/src/client/analyzerClient.ts around line 307, the current check using
stderrBuffer.toLowerCase().includes("java is not installed or not on the path")
is too brittle; replace it with a single case-insensitive regex that matches
multiple known error patterns (examples: "java.*not found", "command not
found.*java", "java: command not found", "JAVA_HOME.*not set") and use
regex.test(stderrBuffer) after normalizing the buffer (trim/ensure string).
Update the condition to use that consolidated RegExp so variations across
platforms are caught reliably.

.then((selection) => {
if (selection === "Install Red Hat OpenJDK") {
vscode.env.openExternal(
vscode.Uri.parse("https://developers.redhat.com/products/openjdk/download"),
);
}
});
} else if (stderrBuffer.toLowerCase().includes("maven is not installed")) {
// Show user-friendly Maven error with action button
vscode.window
.showErrorMessage(
"Maven is required for the analyzer server but was not found. " +
"Please install Maven (version 3.6 or later) and ensure the 'mvn' " +
"command is available in your system PATH.",
"Install Maven",
"Maven Setup Guide",
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion | 🟠 Major

Make Maven error detection more robust.

Similar to the Java check, this Maven detection using .includes("maven is not installed") won't catch platform variations like "mvn: command not found" or "Maven not found".

Use a regex pattern:

-        } else if (stderrBuffer.toLowerCase().includes("maven is not installed")) {
+        const mavenErrorPattern = /maven.*not\s+(found|installed)|command\s+not\s+found.*(mvn|maven)|mvn.*not\s+recognized/i;
+        } else if (mavenErrorPattern.test(stderrBuffer)) {
           // Show user-friendly Maven error with action button

Committable suggestion skipped: line range outside the PR's diff.

🤖 Prompt for AI Agents
In vscode/src/client/analyzerClient.ts around line 323, the current Maven
detection uses stderrBuffer.toLowerCase().includes("maven is not installed")
which misses common variants; replace that check with a case-insensitive regex
test that matches patterns like "mvn: command not found", "command not found:
mvn", "maven not found", or "maven.*not.*installed" (e.g. /mvn: command not
found|command not found: mvn|maven not found|maven.*not.*installed/i) and use
RegExp.test(stderrBuffer) so the detection is robust across platforms and
message variations.

)
.then((selection) => {
if (selection === "Install Maven") {
vscode.env.openExternal(vscode.Uri.parse("https://maven.apache.org/download.cgi"));
} else if (selection === "Maven Setup Guide") {
vscode.env.openExternal(vscode.Uri.parse("https://maven.apache.org/install.html"));
}
});
} else {
// Show generic error as before
vscode.window.showErrorMessage(
`Analyzer RPC server failed. Status code: ${code}. Please see the output channel for details.`,
);
}
}

this.fireServerStateChange("stopped");
this.analyzerRpcServer = null;
});

analyzerRpcServer.on("close", (code, signal) => {
this.logger.info(`Analyzer RPC server closed [signal: ${signal}, code: ${code}]`);
this.fireServerStateChange("stopped");
this.analyzerRpcServer = null;
});

analyzerRpcServer.on("error", (err) => {
this.logger.error("Analyzer RPC server error", err);
this.fireServerStateChange("startFailed");
this.analyzerRpcServer = null;
vscode.window.showErrorMessage(
`Analyzer RPC server failed - ${err instanceof Error ? err.message : String(err)}`,
);
});

return [analyzerRpcServer, analyzerRpcServer.pid];
Expand Down
Loading