Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 60d9490

Browse files
committedAug 9, 2017
WIP: review comments
1 parent 6fa2899 commit 60d9490

File tree

1 file changed

+25
-16
lines changed

1 file changed

+25
-16
lines changed
 

‎src/org/intellij/erlang/debugger/xdebug/ErlangXDebugProcess.java

+25-16
Original file line numberDiff line numberDiff line change
@@ -139,30 +139,39 @@ public synchronized void evaluateExpression(@NotNull String expression,
139139
@Override
140140
public synchronized void handleEvaluationResponse(OtpErlangObject response) {
141141
if (myEvalCallback != null) {
142-
String error = null;
143-
144-
if (response instanceof OtpErlangAtom && ((OtpErlangAtom) response).atomValue().equals("Parse error")) {
145-
// it is a parsing error
146-
error = "Parse error";
147-
} else if (response instanceof OtpErlangTuple) {
148-
OtpErlangObject[] elements = ((OtpErlangTuple) response).elements();
149-
150-
// is it an uncaught exception?
151-
if (elements.length == 2
152-
&& elements[0] instanceof OtpErlangAtom
153-
&& ((OtpErlangAtom) elements[0]).atomValue().equals("EXIT")) {
154-
error = "Uncaught exception: " + elements[1];
155-
}
156-
}
142+
String error = maybeExtractErrorFromEvaluationResponse(response);
157143

158144
if (error == null) {
159145
myEvalCallback.evaluated(ErlangXValueFactory.create(response));
160-
} else {
146+
}
147+
else {
161148
myEvalCallback.errorOccurred(error);
162149
}
163150
}
164151
}
165152

153+
// Parses the response from an evaluation and determines whether it's an error
154+
// response or not; if it is an error, formats it as a displayable string, if
155+
// it's not, just returns null
156+
private static String maybeExtractErrorFromEvaluationResponse(OtpErlangObject response) {
157+
// is it a parsing error?
158+
if (response instanceof OtpErlangAtom && ((OtpErlangAtom) response).atomValue().equals("Parse error")) {
159+
return "Parse error";
160+
}
161+
162+
// is it an uncaught exception?
163+
if (response instanceof OtpErlangTuple) {
164+
OtpErlangObject[] elements = ((OtpErlangTuple) response).elements();
165+
if (elements.length == 2
166+
&& elements[0] instanceof OtpErlangAtom
167+
&& ((OtpErlangAtom) elements[0]).atomValue().equals("EXIT")) {
168+
return "Uncaught exception: " + elements[1];
169+
}
170+
}
171+
172+
return null;
173+
}
174+
166175
@Override
167176
public void debuggerStarted() {
168177
getSession().reportMessage("Debug process started", MessageType.INFO);

0 commit comments

Comments
 (0)
Please sign in to comment.