Skip to content

Commit

Permalink
Log the error details when initialization failed (#3472)
Browse files Browse the repository at this point in the history
  • Loading branch information
testforstephen authored Jan 22, 2024
1 parent fa2a63c commit bd61dc6
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -272,6 +272,7 @@ export async function activate(context: ExtensionContext): Promise<ExtensionAPI>
name: "java.client.error.initialization",
properties: {
message: error && error.toString(),
data: resolveActualCause(error?.data),
},
});
}
Expand Down
17 changes: 17 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -299,3 +299,20 @@ async function addAutoDetectedJdks(configuredJREs: any[]): Promise<any[]> {

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;
}

0 comments on commit bd61dc6

Please sign in to comment.