|
1 | 1 | /******************************************************************************* |
2 | | -* Copyright (c) 2017-2020 Microsoft Corporation and others. |
| 2 | +* Copyright (c) 2017-2021 Microsoft Corporation and others. |
3 | 3 | * All rights reserved. This program and the accompanying materials |
4 | 4 | * are made available under the terms of the Eclipse Public License v1.0 |
5 | 5 | * which accompanies this distribution, and is available at |
|
14 | 14 | import java.util.Arrays; |
15 | 15 | import java.util.List; |
16 | 16 | import java.util.Map; |
17 | | -import java.util.concurrent.CancellationException; |
18 | 17 | import java.util.concurrent.CompletableFuture; |
19 | 18 | import java.util.concurrent.CompletionException; |
20 | 19 | import java.util.concurrent.ExecutionException; |
@@ -106,31 +105,58 @@ public CompletableFuture<Response> handle(Command command, Arguments arguments, |
106 | 105 | indexedVariables = ((IntegerValue) sizeValue).value(); |
107 | 106 | } |
108 | 107 | } |
109 | | - } catch (CancellationException | IllegalArgumentException | InterruptedException |
110 | | - | ExecutionException | UnsupportedOperationException e) { |
111 | | - logger.log(Level.INFO, |
112 | | - String.format("Failed to get the logical size for the type %s.", value.type().name()), e); |
| 108 | + } catch (Exception e) { |
| 109 | + logger.log(Level.INFO, "Failed to get the logical size of the variable", e); |
113 | 110 | } |
114 | 111 | } |
115 | 112 | int referenceId = 0; |
116 | 113 | if (indexedVariables > 0 || (indexedVariables < 0 && value instanceof ObjectReference)) { |
117 | 114 | referenceId = context.getRecyclableIdPool().addObject(threadId, varProxy); |
118 | 115 | } |
119 | 116 |
|
120 | | - String valueString = variableFormatter.valueToString(value, options); |
| 117 | + boolean hasErrors = false; |
| 118 | + String valueString = null; |
| 119 | + try { |
| 120 | + valueString = variableFormatter.valueToString(value, options); |
| 121 | + } catch (OutOfMemoryError e) { |
| 122 | + hasErrors = true; |
| 123 | + logger.log(Level.SEVERE, "Failed to convert the value of a large object to a string", e); |
| 124 | + valueString = "<Unable to display the value of a large object>"; |
| 125 | + } catch (Exception e) { |
| 126 | + hasErrors = true; |
| 127 | + logger.log(Level.SEVERE, "Failed to resolve the variable value", e); |
| 128 | + valueString = "<Failed to resolve the variable value due to \"" + e.getMessage() + "\">"; |
| 129 | + } |
| 130 | + |
121 | 131 | String detailsString = null; |
122 | | - if (sizeValue != null) { |
| 132 | + if (hasErrors) { |
| 133 | + // If failed to resolve the variable value, skip the details info as well. |
| 134 | + } else if (sizeValue != null) { |
123 | 135 | detailsString = "size=" + variableFormatter.valueToString(sizeValue, options); |
124 | 136 | } else if (DebugSettings.getCurrent().showToString) { |
125 | | - detailsString = VariableDetailUtils.formatDetailsValue(value, stackFrameReference.getThread(), variableFormatter, options, engine); |
| 137 | + try { |
| 138 | + detailsString = VariableDetailUtils.formatDetailsValue(value, stackFrameReference.getThread(), variableFormatter, options, engine); |
| 139 | + } catch (OutOfMemoryError e) { |
| 140 | + logger.log(Level.SEVERE, "Failed to compute the toString() value of a large object", e); |
| 141 | + detailsString = "<Unable to display the details of a large object>"; |
| 142 | + } catch (Exception e) { |
| 143 | + logger.log(Level.SEVERE, "Failed to compute the toString() value", e); |
| 144 | + detailsString = "<Failed to resolve the variable details due to \"" + e.getMessage() + "\">"; |
| 145 | + } |
126 | 146 | } |
127 | 147 |
|
128 | 148 | if ("clipboard".equals(evalArguments.context) && detailsString != null) { |
129 | 149 | response.body = new Responses.EvaluateResponseBody(detailsString, -1, "String", 0); |
130 | 150 | } else { |
| 151 | + String typeString = ""; |
| 152 | + try { |
| 153 | + typeString = variableFormatter.typeToString(value == null ? null : value.type(), options); |
| 154 | + } catch (Exception e) { |
| 155 | + logger.log(Level.SEVERE, "Failed to resolve the variable type", e); |
| 156 | + typeString = ""; |
| 157 | + } |
131 | 158 | response.body = new Responses.EvaluateResponseBody((detailsString == null) ? valueString : valueString + " " + detailsString, |
132 | | - referenceId, variableFormatter.typeToString(value == null ? null : value.type(), options), |
133 | | - Math.max(indexedVariables, 0)); |
| 159 | + referenceId, typeString, Math.max(indexedVariables, 0)); |
134 | 160 | } |
135 | 161 | return response; |
136 | 162 | } |
|
0 commit comments