@@ -139,30 +139,39 @@ public synchronized void evaluateExpression(@NotNull String expression,
139
139
@ Override
140
140
public synchronized void handleEvaluationResponse (OtpErlangObject response ) {
141
141
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 );
157
143
158
144
if (error == null ) {
159
145
myEvalCallback .evaluated (ErlangXValueFactory .create (response ));
160
- } else {
146
+ }
147
+ else {
161
148
myEvalCallback .errorOccurred (error );
162
149
}
163
150
}
164
151
}
165
152
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
+
166
175
@ Override
167
176
public void debuggerStarted () {
168
177
getSession ().reportMessage ("Debug process started" , MessageType .INFO );
0 commit comments