From b69f1e0d15fffc05ddd9ab4c77f21e4e5cb64397 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20Porras=20Campo?= Date: Wed, 17 Dec 2025 09:37:36 +0100 Subject: [PATCH] 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) ... --- .../eclipse/lsp4e/LanguageServerPlugin.java | 21 +++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/org.eclipse.lsp4e/src/org/eclipse/lsp4e/LanguageServerPlugin.java b/org.eclipse.lsp4e/src/org/eclipse/lsp4e/LanguageServerPlugin.java index 0e95f700c..b06d635cf 100644 --- a/org.eclipse.lsp4e/src/org/eclipse/lsp4e/LanguageServerPlugin.java +++ b/org.eclipse.lsp4e/src/org/eclipse/lsp4e/LanguageServerPlugin.java @@ -24,12 +24,15 @@ import org.eclipse.jface.resource.ImageRegistry; import org.eclipse.jface.text.BadLocationException; import org.eclipse.lsp4e.ui.LSPImages; +import org.eclipse.lsp4j.jsonrpc.ResponseErrorException; +import org.eclipse.lsp4j.jsonrpc.messages.ResponseError; import org.eclipse.ui.plugin.AbstractUIPlugin; import org.osgi.framework.BundleContext; import com.google.common.base.Throwables; import com.google.common.hash.HashCode; import com.google.common.hash.Hashing; +import com.google.gson.JsonPrimitive; public class LanguageServerPlugin extends AbstractUIPlugin { @@ -110,7 +113,21 @@ public static void logError(final @Nullable String message, final @Nullable Thro return; EXCEPTIONS_COUNTER.compute(key, (k, v) -> v == null ? 1 : ++v); } - plugin.getLog().log(new Status(IStatus.ERROR, PLUGIN_ID, 0, message, thr)); + + logThrowable(message, IStatus.ERROR, thr, plugin); + } + } + + private static void logThrowable(final @Nullable String message, final int status, final @Nullable Throwable thr, final LanguageServerPlugin plugin) { + if (thr != null && thr.getCause() instanceof ResponseErrorException ree) { + ResponseError responseError = ree.getResponseError(); + if (responseError.getData() instanceof JsonPrimitive p) { + plugin.getLog().log(new Status(status, PLUGIN_ID, responseError.getMessage() + '(' + responseError.getCode() + ')' + '\n' + p.getAsString())); + } else { + plugin.getLog().log(new Status(status, PLUGIN_ID, responseError.toString())); + } + } else { + plugin.getLog().log(new Status(status, PLUGIN_ID, 0, message, thr)); } } @@ -145,7 +162,7 @@ public static void logWarning(final @Nullable String message) { */ public static void logWarning(final @Nullable String message, final @Nullable Throwable thr) { if (plugin != null) { - plugin.getLog().log(new Status(IStatus.WARNING, PLUGIN_ID, 0, message, thr)); + logThrowable(message, IStatus.WARNING, thr, plugin); } }