Skip to content
Merged
Show file tree
Hide file tree
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
19 changes: 16 additions & 3 deletions Troubleshooting.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ The debugger works with [Language Support for Java(TM) by Red Hat](https://marke

## Failed to resolve classpath:
### Reason:
Below are the common failure reasons.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

In the document, it should avoid using xyz which is not meaningful.

Should use meaningful name such as mainClassName, projectName

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Nice suggestion. thanks.

- Main class 'C:\demo\org\microsoft\app\Main.java' doesn't exist in the workspace.
- Main class 'org.microsoft.app.Main' isn't unique in the workspace.
- The project 'demo' is not a valid java project.

In launch mode, the debugger resolves the classpaths automatically based on the given `mainClass` and `projectName`. It looks for the class specified by `mainClass` as the entry point for launching an application. If there are multiple classes with the same name in the current workspace, the debugger uses the one inside the project specified by `projectName`.

### Try:
Expand Down Expand Up @@ -65,7 +70,7 @@ You configure the incorrect main class name in `mainClass` of *launch.json*.

### Try:
1. Check whether the class name specified in `mainClass` exists and is in the right form.
2. If the problem persists, it's probably because the language server doesn't load your project correctly. Please reference *"Java Language Support extension fails to start"* paragraph for more troubleshooting info.
2. If the problem persists, it's probably because the language server doesn't load your project correctly. Please reference the [language server troubleshooting](#try) paragraph for more troubleshooting info.

## The DEBUG CONSOLE throws ClassNotFoundException
### Reason:
Expand All @@ -74,12 +79,20 @@ This error indicates your application attempts to reference some classes which a
### Try:
1. Check whether you configure the required libraries in the dependency settings file (e.g. *pom.xml*).
2. Run VS Code command *"Java: Force Java compilation"* to force the language server to rebuild the current project.
3. If the problem persists, it's probably because the language server doesn't load your project correctly. Please reference *"Java Language Support extension fails to start"* paragraph for more troubleshooting info.
3. If the problem persists, it's probably because the language server doesn't load your project correctly. Please reference the [language server troubleshooting](#try) paragraph for more troubleshooting info.

## Cannot find a class with the main method
### Reason:
When the `mainClass` is unconfigured in the *launch.json*, the debugger will resolve a class with main method automatically. This error indicates the debugger doesn't find any main class in the whole workspace.

### Try:
1. Check at least one main class exists in your workspace.
2. If no main class exists, please create a main class first. Otherwise, it's probably because the language server fails to start. Please reference *"Java Language Support extension fails to start"* paragraph for more troubleshooting info.
2. If no main class exists, please create a main class first. Otherwise, it's probably because the language server fails to start. Please reference the [language server troubleshooting](#try) paragraph for more troubleshooting info.

## Build failed, do you want to continue?
### Reason:
The error indicates your workspace has build errors. There are two kinds of build errors. One is compilation error for source code, the other is project error.

### Try:
1. Open VS Code PROBLEMS View, and fix the errors there.
2. If no errors are found in the PROBLEMS View, reference the [language server troubleshooting](#try) paragraph to update project configuration, and clean workspace cache.
11 changes: 11 additions & 0 deletions src/anchor.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

export const LS_FAILS_TO_START = "java-language-support-extension-fails-to-start";
export const FAILED_TO_RESOLVE_CLASSPATH = "failed-to-resolve-classpath";
export const REQUEST_TYPE_NOT_SUPPORTED = "request-type-xyz-is-not-supported-only-launch-and-attach-are-supported";
export const FAILED_TO_COMPLETE_HCR = "failed-to-complete-hot-code-replace";
export const ATTACH_CONFIG_ERROR = "please-specify-the-host-name-and-the-port-of-the-remote-debuggee-in-the-launchjson";
export const EVALUATE_ON_RUNNING_THREAD = "failed-to-evaluate-reason-cannot-evaluate-because-the-thread-is-resumed";
export const DEBUGCONSOLE_MAIN_CLASS_NOT_FOUND = "the-debug-console-throws-error-could-not-find-or-load-main-class-xyz";
export const DEBUGCONSOLE_CLASS_NOT_FOUND_EXCEPTION = "the-debug-console-throws-classnotfoundexception";
export const CANNOT_FIND_MAIN_CLASS = "cannot-find-a-class-with-the-main-method";
export const BUILD_FAILED = "build-failed-do-you-want-to-continue";
11 changes: 10 additions & 1 deletion src/configurationProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// Licensed under the MIT license.

import * as vscode from "vscode";

import * as anchor from "./anchor";
import * as commands from "./commands";
import { logger, Type } from "./logger";
import * as utility from "./utility";
Expand Down Expand Up @@ -113,7 +115,11 @@ export class JavaDebugConfigurationProvider implements vscode.DebugConfiguration
try {
const buildResult = await vscode.commands.executeCommand(commands.JAVA_BUILD_WORKSPACE, false);
} catch (err) {
const ans = await vscode.window.showErrorMessage("Build failed, do you want to continue?", "Proceed", "Abort");
const ans = await utility.showErrorMessageWithTroubleshooting({
message: "Build failed, do you want to continue?",
type: Type.USAGEERROR,
anchor: anchor.BUILD_FAILED,
}, "Proceed", "Abort");
if (ans !== "Proceed") {
return undefined;
}
Expand Down Expand Up @@ -144,13 +150,15 @@ export class JavaDebugConfigurationProvider implements vscode.DebugConfiguration
utility.showErrorMessageWithTroubleshooting({
message: "Please specify the host name and the port of the remote debuggee in the launch.json.",
type: Type.USAGEERROR,
anchor: anchor.ATTACH_CONFIG_ERROR,
});
return undefined;
}
} else {
const ans = await utility.showErrorMessageWithTroubleshooting({
message: `Request type "${config.request}" is not supported. Only "launch" and "attach" are supported.`,
type: Type.USAGEERROR,
anchor: anchor.REQUEST_TYPE_NOT_SUPPORTED,
}, "Open launch.json");
if (ans === "Open launch.json") {
await vscode.commands.executeCommand(commands.VSCODE_ADD_DEBUGCONFIGURATION);
Expand Down Expand Up @@ -201,6 +209,7 @@ export class JavaDebugConfigurationProvider implements vscode.DebugConfiguration
utility.showErrorMessageWithTroubleshooting({
message: "Cannot find a class with the main method.",
type: Type.USAGEERROR,
anchor: anchor.CANNOT_FIND_MAIN_CLASS,
});
return undefined;
}
Expand Down
2 changes: 2 additions & 0 deletions src/hotCodeReplace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import * as vscode from "vscode";

import * as anchor from "./anchor";
import { HCR_EVENT, JAVA_LANGID } from "./constants";
import * as utility from "./utility";

Expand Down Expand Up @@ -43,6 +44,7 @@ export function handleHotCodeReplaceCustomEvent(hcrEvent) {
if (!suppressedReasons.has(hcrEvent.body.message)) {
utility.showWarningMessageWithTroubleshooting({
message: `Hot code replace failed - ${hcrEvent.body.message}. Would you like to restart the debug session?`,
anchor: anchor.FAILED_TO_COMPLETE_HCR,
}, YES_BUTTON, NO_BUTTON, NEVER_BUTTON).then((res) => {
if (res === NEVER_BUTTON) {
suppressedReasons.add(hcrEvent.body.message);
Expand Down
30 changes: 17 additions & 13 deletions src/utility.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,17 @@ import { logger, Type } from "./logger";
const TROUBLESHOOTING_LINK = "https://github.com/Microsoft/vscode-java-debug/blob/master/Troubleshooting.md";
const LEARN_MORE = "Learn More";

interface IMessage {
interface ILoggingMessage {
message: string;
type?: Type;
details?: { [key: string]: string; };
}

function logMessage(message: IMessage): void {
interface ITroubleshootingMessage extends ILoggingMessage {
anchor?: string;
}

function logMessage(message: ILoggingMessage): void {
if (!message.type) {
return;
}
Expand All @@ -26,43 +30,43 @@ function logMessage(message: IMessage): void {
}
}

export async function showInformationMessage(message: IMessage, ...items: string[]): Promise<string | undefined> {
export async function showInformationMessage(message: ILoggingMessage, ...items: string[]): Promise<string | undefined> {
logMessage(message);
return await vscode.window.showInformationMessage(message.message, ...items);
}

export async function showWarningMessage(message: IMessage, ...items: string[]): Promise<string | undefined> {
export async function showWarningMessage(message: ILoggingMessage, ...items: string[]): Promise<string | undefined> {
logMessage(message);
return await vscode.window.showWarningMessage(message.message, ...items);
}

export async function showErrorMessage(message: IMessage, ...items: string[]): Promise<string | undefined> {
export async function showErrorMessage(message: ILoggingMessage, ...items: string[]): Promise<string | undefined> {
logMessage(message);
return await vscode.window.showErrorMessage(message.message, ...items);
}

export async function showInformationMessageWithTroubleshooting(message: IMessage, ...items: string[]): Promise<string | undefined> {
export async function showInformationMessageWithTroubleshooting(message: ITroubleshootingMessage, ...items: string[]): Promise<string | undefined> {
const choice = await showInformationMessage(message, ...items, LEARN_MORE);
return handleTroubleshooting(choice, message.message);
return handleTroubleshooting(choice, message.message, message.anchor);
}

export async function showWarningMessageWithTroubleshooting(message: IMessage, ...items: string[]): Promise<string | undefined> {
export async function showWarningMessageWithTroubleshooting(message: ITroubleshootingMessage, ...items: string[]): Promise<string | undefined> {
const choice = await showWarningMessage(message, ...items, LEARN_MORE);
return handleTroubleshooting(choice, message.message);
return handleTroubleshooting(choice, message.message, message.anchor);
}

export async function showErrorMessageWithTroubleshooting(message: IMessage, ...items: string[]): Promise<string | undefined> {
export async function showErrorMessageWithTroubleshooting(message: ITroubleshootingMessage, ...items: string[]): Promise<string | undefined> {
const choice = await showErrorMessage(message, ...items, LEARN_MORE);
return handleTroubleshooting(choice, message.message);
return handleTroubleshooting(choice, message.message, message.anchor);
}

function openLink(url: string): void {
opn(url);
}

function handleTroubleshooting(choice: string, message: string): string | undefined {
function handleTroubleshooting(choice: string, message: string, anchor: string): string | undefined {
if (choice === LEARN_MORE) {
openLink(TROUBLESHOOTING_LINK);
openLink(anchor ? `${TROUBLESHOOTING_LINK}#${anchor}` : TROUBLESHOOTING_LINK);
logger.log(Type.USAGEDATA, {
troubleshooting: "yes",
troubleshootingMessage: message,
Expand Down