From bd61dc65e8c77ea23504bd4cbc279bf3e62c2235 Mon Sep 17 00:00:00 2001 From: Jinbo Wang Date: Mon, 22 Jan 2024 14:02:06 +0800 Subject: [PATCH] Log the error details when initialization failed (#3472) --- src/extension.ts | 3 ++- src/utils.ts | 17 +++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/extension.ts b/src/extension.ts index 30cf1b506..398b6a00f 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -29,7 +29,7 @@ import { snippetCompletionProvider } from './snippetCompletionProvider'; import { JavaClassEditorProvider } from './javaClassEditor'; import { StandardLanguageClient } from './standardLanguageClient'; import { SyntaxLanguageClient } from './syntaxLanguageClient'; -import { convertToGlob, deleteClientLog, deleteDirectory, ensureExists, getBuildFilePatterns, getExclusionGlob, getInclusionPatternsFromNegatedExclusion, getJavaConfig, getJavaConfiguration, hasBuildToolConflicts } from './utils'; +import { convertToGlob, deleteClientLog, deleteDirectory, ensureExists, getBuildFilePatterns, getExclusionGlob, getInclusionPatternsFromNegatedExclusion, getJavaConfig, getJavaConfiguration, hasBuildToolConflicts, resolveActualCause } from './utils'; import glob = require('glob'); import { Telemetry } from './telemetry'; import { getMessage } from './errorUtils'; @@ -272,6 +272,7 @@ export async function activate(context: ExtensionContext): Promise name: "java.client.error.initialization", properties: { message: error && error.toString(), + data: resolveActualCause(error?.data), }, }); } diff --git a/src/utils.ts b/src/utils.ts index 97acc7ac5..c3ff4805f 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -299,3 +299,20 @@ async function addAutoDetectedJdks(configuredJREs: any[]): Promise { return configuredJREs; } + +export function resolveActualCause(callstack: any): any { + if (!callstack) { + return; + } + + const callstacks = callstack.split(/\r?\n/); + if (callstacks?.length) { + for (let i = callstacks.length - 1; i >= 0; i--) { + if (callstacks[i]?.startsWith("Caused by:")) { + return callstacks.slice(i).join("\n"); + } + } + } + + return callstack; +}