Skip to content

Commit

Permalink
Provide shorter evaluation error, without the unneccessary prefix.
Browse files Browse the repository at this point in the history
  • Loading branch information
entlicher authored and lkishalmi committed Nov 22, 2020
1 parent 461dd54 commit bcdd20f
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.netbeans.api.debugger.jpda.JPDAThread;
import org.netbeans.api.debugger.jpda.ObjectVariable;
import org.netbeans.api.debugger.jpda.Variable;
import org.netbeans.modules.debugger.jpda.expr.InvocationExceptionTranslated;
import org.netbeans.modules.debugger.jpda.truffle.TruffleDebugManager;
import org.openide.util.Exceptions;
import org.openide.util.NbBundle;
Expand Down Expand Up @@ -58,6 +59,13 @@ public static Variable evaluate(JPDADebugger debugger, String expression) throws
new Variable[] { stackFrameInstance,
mirrorExpression });
return valueVar;
} catch (InvalidExpressionException ex) {
Throwable targetException = ex.getTargetException();
if (targetException instanceof InvocationExceptionTranslated) {
// We do not want to prepend Java exception message:
((InvocationExceptionTranslated) targetException).resetInvocationMessage();
}
throw ex;
} catch (InvalidObjectException | NoSuchMethodException ex) {
try {
return debugger.createMirrorVar(ex.getLocalizedMessage());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ private InvocationExceptionTranslated(String invocationMessage, ObjectReference
this.createdAt = new Throwable().fillInStackTrace();
}

public void resetInvocationMessage() {
this.invocationMessage = null;
}

public void setPreferredThread(JPDAThreadImpl preferredThread) {
this.preferredThread = preferredThread;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -379,13 +379,13 @@ public CompletableFuture<EvaluateResponse> evaluate(EvaluateArguments args) {
String expression = args.getExpression();
if (StringUtils.isBlank(expression)) {
throw ErrorUtilities.createResponseErrorException(
"Failed to evaluate. Reason: Empty expression cannot be evaluated.",
"Empty expression cannot be evaluated.",
ResponseErrorCode.InvalidParams);
}
NbFrame stackFrame = (NbFrame) context.getThreadsProvider().getThreadObjects().getObject(args.getFrameId());
if (stackFrame == null) {
throw ErrorUtilities.createResponseErrorException(
"Failed to evaluate. Reason: Unknown frame " + args.getFrameId(),
"Unknown frame " + args.getFrameId(),
ResponseErrorCode.InvalidParams);
}
stackFrame.getDVFrame().makeCurrent(); // The evaluation is always performed with respect to the current frame
Expand All @@ -397,7 +397,7 @@ public CompletableFuture<EvaluateResponse> evaluate(EvaluateArguments args) {
variable = debugger.evaluate(expression);
} catch (InvalidExpressionException ex) {
throw ErrorUtilities.createResponseErrorException(
"Failed to evaluate. Reason: " + ex.getLocalizedMessage(),
ex.getLocalizedMessage(),
ResponseErrorCode.ParseError);
}
EvaluateResponse response = new EvaluateResponse();
Expand Down

0 comments on commit bcdd20f

Please sign in to comment.