diff --git a/.project b/.project index 1e41bef1..69b44885 100644 --- a/.project +++ b/.project @@ -1,6 +1,6 @@ - java-debug + java-debug-parent diff --git a/.travis.yml b/.travis.yml index 2c448eeb..cf7b3b57 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,8 +1,10 @@ language: java -os: - - linux - - osx +matrix: + include: + - os: linux + - os: osx + osx_image: xcode9.2 script: - ./mvnw clean verify diff --git a/com.microsoft.java.debug.core/src/main/java/com/microsoft/java/debug/core/adapter/AdapterUtils.java b/com.microsoft.java.debug.core/src/main/java/com/microsoft/java/debug/core/adapter/AdapterUtils.java index 64a25709..fbe20645 100644 --- a/com.microsoft.java.debug.core/src/main/java/com/microsoft/java/debug/core/adapter/AdapterUtils.java +++ b/com.microsoft.java.debug.core/src/main/java/com/microsoft/java/debug/core/adapter/AdapterUtils.java @@ -24,11 +24,13 @@ import java.nio.file.Paths; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; import java.util.concurrent.CompletableFuture; +import java.util.concurrent.CompletionException; import java.util.regex.Matcher; import java.util.regex.Pattern; import org.apache.commons.lang3.StringUtils; +import com.microsoft.java.debug.core.DebugException; import com.microsoft.java.debug.core.protocol.Messages.Response; import com.microsoft.java.debug.core.protocol.Responses; import com.microsoft.java.debug.core.protocol.Types; @@ -221,6 +223,14 @@ public class AdapterUtils { return CompletableFuture.completedFuture(setErrorResponse(response, errorCode, e)); } + public static CompletionException createCompletionException(String message, ErrorCode errorCode, Throwable cause) { + return new CompletionException(new DebugException(message, cause, errorCode.getId())); + } + + public static CompletionException createCompletionException(String message, ErrorCode errorCode) { + return new CompletionException(new DebugException(message, errorCode.getId())); + } + /** * Calculate SHA-256 Digest of given string. * @param content diff --git a/com.microsoft.java.debug.core/src/main/java/com/microsoft/java/debug/core/adapter/ProtocolServer.java b/com.microsoft.java.debug.core/src/main/java/com/microsoft/java/debug/core/adapter/ProtocolServer.java index 7d5e8158..88d37204 100644 --- a/com.microsoft.java.debug.core/src/main/java/com/microsoft/java/debug/core/adapter/ProtocolServer.java +++ b/com.microsoft.java.debug.core/src/main/java/com/microsoft/java/debug/core/adapter/ProtocolServer.java @@ -83,7 +83,6 @@ public class ProtocolServer extends AbstractProtocolServer { sendResponse(response); future.complete(null); } else { - logger.log(Level.SEVERE, "The request dispatcher should not return null response."); future.completeExceptionally(new DebugException("The request dispatcher should not return null response.", ErrorCode.UNKNOWN_FAILURE.getId())); } @@ -98,14 +97,13 @@ public class ProtocolServer extends AbstractProtocolServer { // mark it success to avoid reporting error on VSCode. response.success = true; sendResponse(response); - } else if (ex instanceof DebugException) { - sendResponse(AdapterUtils.setErrorResponse(response, - ErrorCode.parse(((DebugException) ex).getErrorCode()), - ex.getMessage() != null ? ex.getMessage() : ex.toString())); } else { + String exceptionMessage = ex.getMessage() != null ? ex.getMessage() : ex.toString(); + ErrorCode errorCode = ex instanceof DebugException ? ErrorCode.parse(((DebugException) ex).getErrorCode()) : ErrorCode.UNKNOWN_FAILURE; + logger.log(Level.SEVERE, String.format("[error response][%s]: %s", request.command, exceptionMessage), ex); sendResponse(AdapterUtils.setErrorResponse(response, - ErrorCode.UNKNOWN_FAILURE, - ex.getMessage() != null ? ex.getMessage() : ex.toString())); + errorCode, + exceptionMessage)); } return null; }).join(); diff --git a/com.microsoft.java.debug.core/src/main/java/com/microsoft/java/debug/core/adapter/handler/AttachRequestHandler.java b/com.microsoft.java.debug.core/src/main/java/com/microsoft/java/debug/core/adapter/handler/AttachRequestHandler.java index 727dc24b..d9968c3f 100644 --- a/com.microsoft.java.debug.core/src/main/java/com/microsoft/java/debug/core/adapter/handler/AttachRequestHandler.java +++ b/com.microsoft.java.debug.core/src/main/java/com/microsoft/java/debug/core/adapter/handler/AttachRequestHandler.java @@ -79,8 +79,10 @@ public class AttachRequestHandler implements IDebugRequestHandler { } } } catch (IOException | IllegalConnectorArgumentsException e) { - return AdapterUtils.createAsyncErrorResponse(response, ErrorCode.ATTACH_FAILURE, - String.format("Failed to attach to remote debuggee VM. Reason: %s", e.toString())); + throw AdapterUtils.createCompletionException( + String.format("Failed to attach to remote debuggee VM. Reason: %s", e.toString()), + ErrorCode.ATTACH_FAILURE, + e); } Map options = new HashMap<>(); diff --git a/com.microsoft.java.debug.core/src/main/java/com/microsoft/java/debug/core/adapter/handler/CompletionsHandler.java b/com.microsoft.java.debug.core/src/main/java/com/microsoft/java/debug/core/adapter/handler/CompletionsHandler.java index c3e186a7..8f8bd014 100644 --- a/com.microsoft.java.debug.core/src/main/java/com/microsoft/java/debug/core/adapter/handler/CompletionsHandler.java +++ b/com.microsoft.java.debug.core/src/main/java/com/microsoft/java/debug/core/adapter/handler/CompletionsHandler.java @@ -14,11 +14,7 @@ package com.microsoft.java.debug.core.adapter.handler; import java.util.Arrays; import java.util.List; import java.util.concurrent.CompletableFuture; -import java.util.concurrent.CompletionException; -import java.util.logging.Level; -import java.util.logging.Logger; -import com.microsoft.java.debug.core.Configuration; import com.microsoft.java.debug.core.adapter.AdapterUtils; import com.microsoft.java.debug.core.adapter.ErrorCode; import com.microsoft.java.debug.core.adapter.ICompletionsProvider; @@ -37,8 +33,6 @@ import com.sun.jdi.ThreadReference; public class CompletionsHandler implements IDebugRequestHandler { - private static final Logger logger = Logger.getLogger(Configuration.LOGGER_NAME); - @Override public List getTargetCommands() { return Arrays.asList(Requests.Command.COMPLETIONS); @@ -50,8 +44,10 @@ public class CompletionsHandler implements IDebugRequestHandler { StackFrameReference stackFrameReference = (StackFrameReference) context.getRecyclableIdPool().getObjectById(completionsArgs.frameId); if (stackFrameReference == null) { - return AdapterUtils.createAsyncErrorResponse(response, ErrorCode.COMPLETIONS_FAILURE, - String.format("Completions: cannot find the stack frame with frameID %s", completionsArgs.frameId)); + throw AdapterUtils.createCompletionException( + String.format("Completions: cannot find the stack frame with frameID %s", completionsArgs.frameId), + ErrorCode.COMPLETIONS_FAILURE + ); } return CompletableFuture.supplyAsync(() -> { @@ -66,8 +62,11 @@ public class CompletionsHandler implements IDebugRequestHandler { } return response; } catch (IncompatibleThreadStateException e) { - logger.log(Level.WARNING, String.format("Cannot provide code completions because of %s.", e.toString()), e); - throw new CompletionException(e); + throw AdapterUtils.createCompletionException( + String.format("Cannot provide code completions because of %s.", e.toString()), + ErrorCode.COMPLETIONS_FAILURE, + e + ); } }); } diff --git a/com.microsoft.java.debug.core/src/main/java/com/microsoft/java/debug/core/adapter/handler/EvaluateRequestHandler.java b/com.microsoft.java.debug.core/src/main/java/com/microsoft/java/debug/core/adapter/handler/EvaluateRequestHandler.java index 8bb04c98..ee2250a9 100644 --- a/com.microsoft.java.debug.core/src/main/java/com/microsoft/java/debug/core/adapter/handler/EvaluateRequestHandler.java +++ b/com.microsoft.java.debug.core/src/main/java/com/microsoft/java/debug/core/adapter/handler/EvaluateRequestHandler.java @@ -15,9 +15,7 @@ import java.util.Arrays; import java.util.List; import java.util.Map; import java.util.concurrent.CompletableFuture; -import java.util.concurrent.CompletionException; import java.util.concurrent.ExecutionException; -import java.util.logging.Level; import java.util.logging.Logger; import org.apache.commons.lang3.StringUtils; @@ -60,14 +58,16 @@ public class EvaluateRequestHandler implements IDebugRequestHandler { String expression = evalArguments.expression; if (StringUtils.isBlank(expression)) { - return AdapterUtils.createAsyncErrorResponse(response, ErrorCode.EVALUATE_FAILURE, - "Failed to evaluate. Reason: Empty expression cannot be evaluated."); + throw AdapterUtils.createCompletionException( + "Failed to evaluate. Reason: Empty expression cannot be evaluated.", + ErrorCode.EVALUATE_FAILURE); } StackFrameReference stackFrameReference = (StackFrameReference) context.getRecyclableIdPool().getObjectById(evalArguments.frameId); if (stackFrameReference == null) { // stackFrameReference is null means the stackframe is continued by user manually, - return AdapterUtils.createAsyncErrorResponse(response, ErrorCode.EVALUATE_FAILURE, - "Failed to evaluate. Reason: Cannot evaluate because the thread is resumed."); + throw AdapterUtils.createCompletionException( + "Failed to evaluate. Reason: Cannot evaluate because the thread is resumed.", + ErrorCode.EVALUATE_FAILURE); } return CompletableFuture.supplyAsync(() -> { @@ -100,8 +100,10 @@ public class EvaluateRequestHandler implements IDebugRequestHandler { cause = e.getCause(); } // TODO: distinguish user error of wrong expression(eg: compilation error) - logger.log(Level.WARNING, String.format("Cannot evalution expression because of %s.", cause.toString()), cause); - throw new CompletionException(cause); + throw AdapterUtils.createCompletionException( + String.format("Cannot evalution expression because of %s.", cause.toString()), + ErrorCode.EVALUATE_FAILURE, + cause); } }); } diff --git a/com.microsoft.java.debug.core/src/main/java/com/microsoft/java/debug/core/adapter/handler/LaunchRequestHandler.java b/com.microsoft.java.debug.core/src/main/java/com/microsoft/java/debug/core/adapter/handler/LaunchRequestHandler.java index d7602191..a47112f2 100644 --- a/com.microsoft.java.debug.core/src/main/java/com/microsoft/java/debug/core/adapter/handler/LaunchRequestHandler.java +++ b/com.microsoft.java.debug.core/src/main/java/com/microsoft/java/debug/core/adapter/handler/LaunchRequestHandler.java @@ -23,7 +23,6 @@ import java.util.Map; import java.util.Map.Entry; import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletionException; -import java.util.logging.Level; import java.util.logging.Logger; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -79,8 +78,9 @@ public class LaunchRequestHandler implements IDebugRequestHandler { LaunchArguments launchArguments = (LaunchArguments) arguments; if (StringUtils.isBlank(launchArguments.mainClass) || ArrayUtils.isEmpty(launchArguments.modulePaths) && ArrayUtils.isEmpty(launchArguments.classPaths)) { - return AdapterUtils.createAsyncErrorResponse(response, ErrorCode.ARGUMENT_MISSING, - String.format("Failed to launch debuggee VM. Missing mainClass or modulePaths/classPaths options in launch configuration")); + throw AdapterUtils.createCompletionException( + "Failed to launch debuggee VM. Missing mainClass or modulePaths/classPaths options in launch configuration.", + ErrorCode.ARGUMENT_MISSING); } context.setAttached(false); @@ -93,8 +93,9 @@ public class LaunchRequestHandler implements IDebugRequestHandler { context.setDebuggeeEncoding(StandardCharsets.UTF_8); } else { if (!Charset.isSupported(launchArguments.encoding)) { - return AdapterUtils.createAsyncErrorResponse(response, ErrorCode.INVALID_ENCODING, - String.format("Failed to launch debuggee VM. 'encoding' options in the launch configuration is not recognized.")); + throw AdapterUtils.createCompletionException( + "Failed to launch debuggee VM. 'encoding' options in the launch configuration is not recognized.", + ErrorCode.INVALID_ENCODING); } context.setDebuggeeEncoding(Charset.forName(launchArguments.encoding)); @@ -197,7 +198,6 @@ public class LaunchRequestHandler implements IDebugRequestHandler { logger.info("Launching debuggee in terminal console succeeded."); resultFuture.complete(response); } catch (IOException | IllegalConnectorArgumentsException e) { - logger.log(Level.SEVERE, String.format(launchInTerminalErrorFormat, e.toString())); resultFuture.completeExceptionally( new DebugException( String.format(launchInTerminalErrorFormat, e.toString()), @@ -206,7 +206,6 @@ public class LaunchRequestHandler implements IDebugRequestHandler { ); } } else { - logger.log(Level.SEVERE, String.format(launchInTerminalErrorFormat, runResponse.message)); resultFuture.completeExceptionally( new DebugException( String.format(launchInTerminalErrorFormat, runResponse.message), @@ -219,7 +218,6 @@ public class LaunchRequestHandler implements IDebugRequestHandler { ex = ex.getCause(); } String errorMessage = String.format(launchInTerminalErrorFormat, ex != null ? ex.toString() : "Null response"); - logger.log(Level.SEVERE, errorMessage); resultFuture.completeExceptionally( new DebugException( String.format(launchInTerminalErrorFormat, errorMessage), @@ -229,7 +227,6 @@ public class LaunchRequestHandler implements IDebugRequestHandler { } }); } catch (IOException | IllegalConnectorArgumentsException e) { - logger.log(Level.SEVERE, String.format(launchInTerminalErrorFormat, e.toString())); resultFuture.completeExceptionally( new DebugException( String.format(launchInTerminalErrorFormat, e.toString()), @@ -298,7 +295,6 @@ public class LaunchRequestHandler implements IDebugRequestHandler { resultFuture.complete(response); } catch (IOException | IllegalConnectorArgumentsException | VMStartException e) { - logger.log(Level.SEVERE, String.format("Failed to launch debuggee VM. Reason: %s", e.toString())); resultFuture.completeExceptionally( new DebugException( String.format("Failed to launch debuggee VM. Reason: %s", e.toString()), diff --git a/com.microsoft.java.debug.core/src/main/java/com/microsoft/java/debug/core/adapter/handler/RestartFrameHandler.java b/com.microsoft.java.debug.core/src/main/java/com/microsoft/java/debug/core/adapter/handler/RestartFrameHandler.java index 8e352fef..05218eb2 100644 --- a/com.microsoft.java.debug.core/src/main/java/com/microsoft/java/debug/core/adapter/handler/RestartFrameHandler.java +++ b/com.microsoft.java.debug.core/src/main/java/com/microsoft/java/debug/core/adapter/handler/RestartFrameHandler.java @@ -51,8 +51,9 @@ public class RestartFrameHandler implements IDebugRequestHandler { StackFrameReference stackFrameReference = (StackFrameReference) context.getRecyclableIdPool().getObjectById(restartFrameArgs.frameId); if (stackFrameReference == null) { - return AdapterUtils.createAsyncErrorResponse(response, ErrorCode.RESTARTFRAME_FAILURE, - String.format("RestartFrame: cannot find the stack frame with frameID %s", restartFrameArgs.frameId)); + throw AdapterUtils.createCompletionException( + String.format("RestartFrame: cannot find the stack frame with frameID %s", restartFrameArgs.frameId), + ErrorCode.RESTARTFRAME_FAILURE); } if (canRestartFrame(context, stackFrameReference)) { @@ -62,11 +63,15 @@ public class RestartFrameHandler implements IDebugRequestHandler { stepInto(context, reference); } catch (DebugException de) { context.getProtocolServer().sendEvent(new Events.UserNotificationEvent(NotificationType.ERROR, de.getMessage())); + throw AdapterUtils.createCompletionException( + String.format("Failed to restart stack frame. Reason: %s", de.getMessage()), + ErrorCode.RESTARTFRAME_FAILURE, + de); } return CompletableFuture.completedFuture(response); } else { context.getProtocolServer().sendEvent(new Events.UserNotificationEvent(NotificationType.ERROR, "Current stack frame doesn't support restart.")); - return AdapterUtils.createAsyncErrorResponse(response, ErrorCode.RESTARTFRAME_FAILURE, "Failed to restart the selected stack frame."); + throw AdapterUtils.createCompletionException("Current stack frame doesn't support restart.", ErrorCode.RESTARTFRAME_FAILURE); } } diff --git a/com.microsoft.java.debug.core/src/main/java/com/microsoft/java/debug/core/adapter/handler/SetBreakpointsRequestHandler.java b/com.microsoft.java.debug.core/src/main/java/com/microsoft/java/debug/core/adapter/handler/SetBreakpointsRequestHandler.java index 9bb34d85..3eeb4b46 100644 --- a/com.microsoft.java.debug.core/src/main/java/com/microsoft/java/debug/core/adapter/handler/SetBreakpointsRequestHandler.java +++ b/com.microsoft.java.debug.core/src/main/java/com/microsoft/java/debug/core/adapter/handler/SetBreakpointsRequestHandler.java @@ -117,8 +117,9 @@ public class SetBreakpointsRequestHandler implements IDebugRequestHandler { // When breakpoint source path is null or an invalid file path, send an ErrorResponse back. if (StringUtils.isBlank(sourcePath)) { - return AdapterUtils.createAsyncErrorResponse(response, ErrorCode.SET_BREAKPOINT_FAILURE, - String.format("Failed to setBreakpoint. Reason: '%s' is an invalid path.", bpArguments.source.path)); + throw AdapterUtils.createCompletionException( + String.format("Failed to setBreakpoint. Reason: '%s' is an invalid path.", bpArguments.source.path), + ErrorCode.SET_BREAKPOINT_FAILURE); } try { @@ -154,9 +155,9 @@ public class SetBreakpointsRequestHandler implements IDebugRequestHandler { response.body = new Responses.SetBreakpointsResponseBody(res); return CompletableFuture.completedFuture(response); } catch (DebugException e) { - return AdapterUtils.createAsyncErrorResponse(response, - ErrorCode.SET_BREAKPOINT_FAILURE, - String.format("Failed to setBreakpoint. Reason: '%s'", e.toString())); + throw AdapterUtils.createCompletionException( + String.format("Failed to setBreakpoint. Reason: '%s'", e.toString()), + ErrorCode.SET_BREAKPOINT_FAILURE); } } @@ -211,6 +212,7 @@ public class SetBreakpointsRequestHandler implements IDebugRequestHandler { private boolean handleEvaluationResult(IDebugAdapterContext context, ThreadReference bpThread, IBreakpoint breakpoint, Value value, Throwable ex) { if (StringUtils.isNotBlank(breakpoint.getLogMessage())) { if (ex != null) { + logger.log(Level.SEVERE, String.format("[Logpoint]: %s", ex.getMessage() != null ? ex.getMessage() : ex.toString()), ex); context.getProtocolServer().sendEvent(new Events.UserNotificationEvent( Events.UserNotificationEvent.NotificationType.ERROR, String.format("[Logpoint] Log message '%s' error: %s", breakpoint.getLogMessage(), ex.getMessage()))); @@ -236,6 +238,7 @@ public class SetBreakpointsRequestHandler implements IDebugRequestHandler { } else { context.getProtocolServer().sendEvent(new Events.StoppedEvent("breakpoint", bpThread.uniqueID())); if (ex != null) { + logger.log(Level.SEVERE, String.format("[ConditionalBreakpoint]: %s", ex.getMessage() != null ? ex.getMessage() : ex.toString()), ex); context.getProtocolServer().sendEvent(new Events.UserNotificationEvent( Events.UserNotificationEvent.NotificationType.ERROR, String.format("Breakpoint condition '%s' error: %s", breakpoint.getCondition(), ex.getMessage()))); diff --git a/com.microsoft.java.debug.core/src/main/java/com/microsoft/java/debug/core/adapter/handler/SetExceptionBreakpointsRequestHandler.java b/com.microsoft.java.debug.core/src/main/java/com/microsoft/java/debug/core/adapter/handler/SetExceptionBreakpointsRequestHandler.java index 1a8be8ef..6584e791 100644 --- a/com.microsoft.java.debug.core/src/main/java/com/microsoft/java/debug/core/adapter/handler/SetExceptionBreakpointsRequestHandler.java +++ b/com.microsoft.java.debug.core/src/main/java/com/microsoft/java/debug/core/adapter/handler/SetExceptionBreakpointsRequestHandler.java @@ -48,8 +48,10 @@ public class SetExceptionBreakpointsRequestHandler implements IDebugRequestHandl context.getDebugSession().setExceptionBreakpoints(notifyCaught, notifyUncaught); return CompletableFuture.completedFuture(response); } catch (Exception ex) { - return AdapterUtils.createAsyncErrorResponse(response, ErrorCode.SET_EXCEPTIONBREAKPOINT_FAILURE, - String.format("Failed to setExceptionBreakpoints. Reason: '%s'", ex.toString())); + throw AdapterUtils.createCompletionException( + String.format("Failed to setExceptionBreakpoints. Reason: '%s'", ex.toString()), + ErrorCode.SET_EXCEPTIONBREAKPOINT_FAILURE, + ex); } } diff --git a/com.microsoft.java.debug.core/src/main/java/com/microsoft/java/debug/core/adapter/handler/SetVariableRequestHandler.java b/com.microsoft.java.debug.core/src/main/java/com/microsoft/java/debug/core/adapter/handler/SetVariableRequestHandler.java index b940abbb..568d22c4 100644 --- a/com.microsoft.java.debug.core/src/main/java/com/microsoft/java/debug/core/adapter/handler/SetVariableRequestHandler.java +++ b/com.microsoft.java.debug.core/src/main/java/com/microsoft/java/debug/core/adapter/handler/SetVariableRequestHandler.java @@ -64,11 +64,13 @@ public class SetVariableRequestHandler implements IDebugRequestHandler { // Just exit out of editing if we're given an empty expression. return CompletableFuture.completedFuture(response); } else if (setVarArguments.variablesReference == -1) { - return AdapterUtils.createAsyncErrorResponse(response, ErrorCode.ARGUMENT_MISSING, - "SetVariablesRequest: property 'variablesReference' is missing, null, or empty"); + throw AdapterUtils.createCompletionException( + "SetVariablesRequest: property 'variablesReference' is missing, null, or empty", + ErrorCode.ARGUMENT_MISSING); } else if (StringUtils.isBlank(setVarArguments.name)) { - return AdapterUtils.createAsyncErrorResponse(response, ErrorCode.ARGUMENT_MISSING, - "SetVariablesRequest: property 'name' is missing, null, or empty"); + throw AdapterUtils.createCompletionException( + "SetVariablesRequest: property 'name' is missing, null, or empty", + ErrorCode.ARGUMENT_MISSING); } this.context = context; @@ -80,8 +82,9 @@ public class SetVariableRequestHandler implements IDebugRequestHandler { Object container = context.getRecyclableIdPool().getObjectById(setVarArguments.variablesReference); // container is null means the stack frame is continued by user manually. if (container == null) { - return AdapterUtils.createAsyncErrorResponse(response, ErrorCode.SET_VARIABLE_FAILURE, - "Failed to set variable. Reason: Cannot set value because the thread is resumed."); + throw AdapterUtils.createCompletionException( + "Failed to set variable. Reason: Cannot set value because the thread is resumed.", + ErrorCode.SET_VARIABLE_FAILURE); } String name = setVarArguments.name; @@ -103,13 +106,16 @@ public class SetVariableRequestHandler implements IDebugRequestHandler { } else if (containerObj instanceof ObjectReference) { newValue = handleSetValueForObject(name, belongToClass, setVarArguments.value, (ObjectReference) containerObj, options); } else { - return AdapterUtils.createAsyncErrorResponse(response, ErrorCode.SET_VARIABLE_FAILURE, - String.format("SetVariableRequest: Variable %s cannot be found.", setVarArguments.variablesReference)); + throw AdapterUtils.createCompletionException( + String.format("SetVariableRequest: Variable %s cannot be found.", setVarArguments.variablesReference), + ErrorCode.SET_VARIABLE_FAILURE); } } catch (IllegalArgumentException | AbsentInformationException | InvalidTypeException | UnsupportedOperationException | ClassNotLoadedException e) { - return AdapterUtils.createAsyncErrorResponse(response, ErrorCode.SET_VARIABLE_FAILURE, - String.format("Failed to set variable. Reason: %s", e.toString())); + throw AdapterUtils.createCompletionException( + String.format("Failed to set variable. Reason: %s", e.toString()), + ErrorCode.SET_VARIABLE_FAILURE, + e); } int referenceId = 0; if (newValue instanceof ObjectReference && VariableUtils.hasChildren(newValue, showStaticVariables)) { diff --git a/com.microsoft.java.debug.core/src/main/java/com/microsoft/java/debug/core/adapter/handler/StepRequestHandler.java b/com.microsoft.java.debug.core/src/main/java/com/microsoft/java/debug/core/adapter/handler/StepRequestHandler.java index 320ad05a..5f521ffa 100644 --- a/com.microsoft.java.debug.core/src/main/java/com/microsoft/java/debug/core/adapter/handler/StepRequestHandler.java +++ b/com.microsoft.java.debug.core/src/main/java/com/microsoft/java/debug/core/adapter/handler/StepRequestHandler.java @@ -14,12 +14,9 @@ package com.microsoft.java.debug.core.adapter.handler; import java.util.Arrays; import java.util.List; import java.util.concurrent.CompletableFuture; -import java.util.logging.Level; -import java.util.logging.Logger; import org.apache.commons.lang3.ArrayUtils; -import com.microsoft.java.debug.core.Configuration; import com.microsoft.java.debug.core.DebugEvent; import com.microsoft.java.debug.core.DebugUtility; import com.microsoft.java.debug.core.IDebugSession; @@ -46,7 +43,6 @@ import com.sun.jdi.request.StepRequest; import io.reactivex.disposables.Disposable; public class StepRequestHandler implements IDebugRequestHandler { - private static final Logger logger = Logger.getLogger(Configuration.LOGGER_NAME); @Override public List getTargetCommands() { @@ -92,12 +88,16 @@ public class StepRequestHandler implements IDebugRequestHandler { ThreadsRequestHandler.checkThreadRunningAndRecycleIds(thread, context); } catch (IncompatibleThreadStateException ex) { final String failureMessage = String.format("Failed to step because the thread '%s' is not suspended in the target VM.", thread.name()); - logger.log(Level.SEVERE, failureMessage); - return AdapterUtils.createAsyncErrorResponse(response, ErrorCode.STEP_FAILURE, failureMessage); + throw AdapterUtils.createCompletionException( + failureMessage, + ErrorCode.STEP_FAILURE, + ex); } catch (IndexOutOfBoundsException ex) { final String failureMessage = String.format("Failed to step because the thread '%s' doesn't contain any stack frame", thread.name()); - logger.log(Level.SEVERE, failureMessage); - return AdapterUtils.createAsyncErrorResponse(response, ErrorCode.STEP_FAILURE, failureMessage); + throw AdapterUtils.createCompletionException( + failureMessage, + ErrorCode.STEP_FAILURE, + ex); } } diff --git a/com.microsoft.java.debug.core/src/main/java/com/microsoft/java/debug/core/adapter/handler/VariablesRequestHandler.java b/com.microsoft.java.debug.core/src/main/java/com/microsoft/java/debug/core/adapter/handler/VariablesRequestHandler.java index 3d651dd9..ba5b80c2 100644 --- a/com.microsoft.java.debug.core/src/main/java/com/microsoft/java/debug/core/adapter/handler/VariablesRequestHandler.java +++ b/com.microsoft.java.debug.core/src/main/java/com/microsoft/java/debug/core/adapter/handler/VariablesRequestHandler.java @@ -75,8 +75,9 @@ public class VariablesRequestHandler implements IDebugRequestHandler { } if (!(container instanceof VariableProxy)) { - return AdapterUtils.createAsyncErrorResponse(response, ErrorCode.GET_VARIABLE_FAILURE, - String.format("VariablesRequest: Invalid variablesReference %d.", varArgs.variablesReference)); + throw AdapterUtils.createCompletionException( + String.format("VariablesRequest: Invalid variablesReference %d.", varArgs.variablesReference), + ErrorCode.GET_VARIABLE_FAILURE); } VariableProxy containerNode = (VariableProxy) container; @@ -86,8 +87,9 @@ public class VariablesRequestHandler implements IDebugRequestHandler { StackFrameReference stackFrameReference = (StackFrameReference) containerNode.getProxiedVariable(); StackFrame frame = stackFrameManager.getStackFrame(stackFrameReference); if (frame == null) { - return AdapterUtils.createAsyncErrorResponse(response, ErrorCode.GET_VARIABLE_FAILURE, - String.format("Invalid stackframe id %d to get variables.", varArgs.variablesReference)); + throw AdapterUtils.createCompletionException( + String.format("Invalid stackframe id %d to get variables.", varArgs.variablesReference), + ErrorCode.GET_VARIABLE_FAILURE); } try { childrenList = VariableUtils.listLocalVariables(frame); @@ -99,8 +101,10 @@ public class VariablesRequestHandler implements IDebugRequestHandler { childrenList.addAll(VariableUtils.listStaticVariables(frame)); } } catch (AbsentInformationException | InternalException | InvalidStackFrameException e) { - return AdapterUtils.createAsyncErrorResponse(response, ErrorCode.GET_VARIABLE_FAILURE, - String.format("Failed to get variables. Reason: %s", e.toString())); + throw AdapterUtils.createCompletionException( + String.format("Failed to get variables. Reason: %s", e.toString()), + ErrorCode.GET_VARIABLE_FAILURE, + e); } } else { try { @@ -111,8 +115,10 @@ public class VariablesRequestHandler implements IDebugRequestHandler { childrenList = VariableUtils.listFieldVariables(containerObj, showStaticVariables); } } catch (AbsentInformationException e) { - return AdapterUtils.createAsyncErrorResponse(response, ErrorCode.GET_VARIABLE_FAILURE, - String.format("Failed to get variables. Reason: %s", e.toString())); + throw AdapterUtils.createCompletionException( + String.format("Failed to get variables. Reason: %s", e.toString()), + ErrorCode.GET_VARIABLE_FAILURE, + e); } } diff --git a/com.microsoft.java.debug.plugin/src/main/java/com/microsoft/java/debug/plugin/internal/CompletionsProvider.java b/com.microsoft.java.debug.plugin/src/main/java/com/microsoft/java/debug/plugin/internal/CompletionsProvider.java index 0407a4b4..af5fe0a6 100644 --- a/com.microsoft.java.debug.plugin/src/main/java/com/microsoft/java/debug/plugin/internal/CompletionsProvider.java +++ b/com.microsoft.java.debug.plugin/src/main/java/com/microsoft/java/debug/plugin/internal/CompletionsProvider.java @@ -80,7 +80,7 @@ public class CompletionsProvider implements ICompletionsProvider { } } catch (DebugException | CoreException e) { - logger.log(Level.WARNING, String.format("Failed to code complete because of %s", e.toString()), e); + logger.log(Level.SEVERE, String.format("Failed to code complete because of %s", e.toString()), e); } return res; diff --git a/com.microsoft.java.debug.plugin/src/main/java/com/microsoft/java/debug/plugin/internal/eval/JdtEvaluationProvider.java b/com.microsoft.java.debug.plugin/src/main/java/com/microsoft/java/debug/plugin/internal/eval/JdtEvaluationProvider.java index 79cb2585..4aee0602 100644 --- a/com.microsoft.java.debug.plugin/src/main/java/com/microsoft/java/debug/plugin/internal/eval/JdtEvaluationProvider.java +++ b/com.microsoft.java.debug.plugin/src/main/java/com/microsoft/java/debug/plugin/internal/eval/JdtEvaluationProvider.java @@ -112,7 +112,6 @@ public class JdtEvaluationProvider implements IEvaluationProvider { JDIThread jdiThread = getMockJDIThread(thread); JDIStackFrame stackframe = createStackFrame(jdiThread, depth); if (stackframe == null) { - logger.severe("Cannot evaluate because the stackframe is not available."); throw new IllegalStateException("Cannot evaluate because the stackframe is not available."); } @@ -295,7 +294,7 @@ public class JdtEvaluationProvider implements IEvaluationProvider { try { jdiThread.terminateEvaluation(); } catch (DebugException e) { - logger.warning(String.format("Error stopping evalutoin on thread %d: %s", thread.uniqueID(), + logger.warning(String.format("Error stopping evaluation on thread %d: %s", thread.uniqueID(), e.toString())); } threadMap.remove(thread);