diff --git a/USAGE_DATA.md b/USAGE_DATA.md index ce86f7ea20..e97a205297 100644 --- a/USAGE_DATA.md +++ b/USAGE_DATA.md @@ -17,6 +17,7 @@ vscode-java has opt-in telemetry collection, provided by [vscode-redhat-telemetr * Information about the following settings. In the case of settings that store a well defined value (eg. path/url/string), we simply collect whether the setting has been set. * `java.settings.url`, `java.format.settings.url`, `java.quickfix.showAt`, `java.symbols.includeSourceMethodDeclarations`, `java.completion.guessMethodArguments`, `java.completion.postfix.enabled`, `java.cleanup.actionsOnSave`, `java.sharedIndexes.enabled`, `java.inlayHints.parameterNames.enabled`, `java.server.launchMode`, `java.autobuild.enabled` * The extension name and the choice made when a recommendation to install a 3rd party extension is proposed + * The name of Java commands being manually executed, and any resulting errors ## What's included in the general telemetry data diff --git a/src/errorUtils.ts b/src/errorUtils.ts new file mode 100644 index 0000000000..a098b73691 --- /dev/null +++ b/src/errorUtils.ts @@ -0,0 +1,24 @@ +// copied from https://github.com/redhat-developer/openshift-dd-ext/blob/f8c053bded9bc6c1bfac682cf4867b187e87ee76/client/src/utils/ErrorUtils.ts#L12 +export function getMessage(error: any): string { + return getRawMessage(error).trim(); +} + +export function getRawMessage(error: any): string { + if (typeof error === 'string') { + return error; + } + if (error.stderr) { + return error.stderr; + } + if (error.message) { + return error.message; + } + if (error.error) { + return error.error; + } + + // Unlikely to happen, as we're either getting an Error object with a message + // or we're dealing with a failed promise with a stderr message + // in any other case, we'll need to figure out what to return on a case by case basis + return JSON.stringify(error); +} \ No newline at end of file diff --git a/src/extension.ts b/src/extension.ts index bae01b902f..12f1040fdc 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -32,6 +32,7 @@ import { SyntaxLanguageClient } from './syntaxLanguageClient'; import { convertToGlob, deleteDirectory, ensureExists, getBuildFilePatterns, getExclusionBlob, getInclusionPatternsFromNegatedExclusion, getJavaConfig, getJavaConfiguration, hasBuildToolConflicts } from './utils'; import glob = require('glob'); import { Telemetry } from './telemetry'; +import { getMessage } from './errorUtils'; const syntaxClient: SyntaxLanguageClient = new SyntaxLanguageClient(); const standardClient: StandardLanguageClient = new StandardLanguageClient(); @@ -291,13 +292,16 @@ export function activate(context: ExtensionContext): Promise { const cleanWorkspaceExists = fs.existsSync(path.join(workspacePath, cleanWorkspaceFileName)); if (cleanWorkspaceExists) { + const data = {}; try { cleanupLombokCache(context); deleteDirectory(workspacePath); deleteDirectory(syntaxServerWorkspacePath); } catch (error) { + data['error'] = getMessage(error); window.showErrorMessage(`Failed to delete ${workspacePath}: ${error}`); } + await Telemetry.sendTelemetry(Commands.CLEAN_WORKSPACE, data); } // Register commands here to make it available even when the language client fails