Skip to content

Commit 14a6f50

Browse files
committed
feat: improve response error exception logs
Instead of just !ENTRY org.eclipse.lsp4e 4 0 2025-12-17 09:07:40.931 !MESSAGE Internal error. Produce an error that contains the internal error, such us !ENTRY org.eclipse.lsp4e 4 0 2025-12-17 09:21:46.530 !MESSAGE Internal error.(-32603) java.util.concurrent.CompletionException: java.lang.NullPointerException: Cannot invoke "org.eclipse.xtext.nodemodel.INode.getParent()" because "localNode" is null ... (abbreviated) ... at java.base/java.lang.Thread.run(Thread.java:1583) Caused by: java.lang.NullPointerException: Cannot invoke "org.eclipse.xtext.nodemodel.INode.getParent()" because "localNode" is null at org.eclipse.xtext.nodemodel.util.NodeModelUtils$Implementation.findLeafNodeAtOffset(NodeModelUtils.java:235) at org.eclipse.xtext.nodemodel.util.NodeModelUtils.findLeafNodeAtOffset(NodeModelUtils.java:74) ... (abbreviated) ...
1 parent 6281ee7 commit 14a6f50

1 file changed

Lines changed: 19 additions & 2 deletions

File tree

org.eclipse.lsp4e/src/org/eclipse/lsp4e/LanguageServerPlugin.java

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,15 @@
2424
import org.eclipse.jface.resource.ImageRegistry;
2525
import org.eclipse.jface.text.BadLocationException;
2626
import org.eclipse.lsp4e.ui.LSPImages;
27+
import org.eclipse.lsp4j.jsonrpc.ResponseErrorException;
28+
import org.eclipse.lsp4j.jsonrpc.messages.ResponseError;
2729
import org.eclipse.ui.plugin.AbstractUIPlugin;
2830
import org.osgi.framework.BundleContext;
2931

3032
import com.google.common.base.Throwables;
3133
import com.google.common.hash.HashCode;
3234
import com.google.common.hash.Hashing;
35+
import com.google.gson.JsonPrimitive;
3336

3437
public class LanguageServerPlugin extends AbstractUIPlugin {
3538

@@ -110,7 +113,21 @@ public static void logError(final @Nullable String message, final @Nullable Thro
110113
return;
111114
EXCEPTIONS_COUNTER.compute(key, (k, v) -> v == null ? 1 : ++v);
112115
}
113-
plugin.getLog().log(new Status(IStatus.ERROR, PLUGIN_ID, 0, message, thr));
116+
117+
logThrowable(message, IStatus.ERROR, thr, plugin);
118+
}
119+
}
120+
121+
private static void logThrowable(final @Nullable String message, final int status, final @Nullable Throwable thr, final LanguageServerPlugin plugin) {
122+
if (thr != null && thr.getCause() instanceof ResponseErrorException ree) {
123+
ResponseError responseError = ree.getResponseError();
124+
if (responseError.getData() instanceof JsonPrimitive p) {
125+
plugin.getLog().log(new Status(status, PLUGIN_ID, responseError.getMessage() + '(' + responseError.getCode() + ')' + '\n' + p.getAsString()));
126+
} else {
127+
plugin.getLog().log(new Status(status, PLUGIN_ID, responseError.toString()));
128+
}
129+
} else {
130+
plugin.getLog().log(new Status(status, PLUGIN_ID, 0, message, thr));
114131
}
115132
}
116133

@@ -145,7 +162,7 @@ public static void logWarning(final @Nullable String message) {
145162
*/
146163
public static void logWarning(final @Nullable String message, final @Nullable Throwable thr) {
147164
if (plugin != null) {
148-
plugin.getLog().log(new Status(IStatus.WARNING, PLUGIN_ID, 0, message, thr));
165+
logThrowable(message, IStatus.WARNING, thr, plugin);
149166
}
150167
}
151168

0 commit comments

Comments
 (0)