public async callWithTelemetryAndErrorHandling()

in src/helpers/telemetryHelper.ts [113:151]


    public async callWithTelemetryAndErrorHandling<T>(callback: () => Promise<T>): Promise<T | void> {
        try {
            return await this.executeFunctionWithTimeTelemetry(callback, 'duration');
        } catch (error) {
            const parsedError = parseError(error);
            if (parsedError.isUserCancelledError) {
                this.setTelemetry(TelemetryKeys.Result, Result.Canceled);
            } else {
                this.setTelemetry(TelemetryKeys.Result, Result.Failed);
                this.setTelemetry('error', parsedError.errorType);
                this.setTelemetry('errorMessage', parsedError.message);
                this.setTelemetry('stack', parsedError.stack ?? '');
                if (this.options.suppressIfSuccessful) {
                    this.setTelemetry('suppressTelemetry', 'true');
                }

                logger.log(parsedError.message);
                if (parsedError.message.includes('\n')) {
                    vscode.window.showErrorMessage('An error has occurred. Check the output window for more details.');
                } else {
                    vscode.window.showErrorMessage(parsedError.message);
                }
            }
        } finally {
            if (this.properties.result === Result.Failed) {
                TelemetryHelper.reporter.sendTelemetryErrorEvent(
                    this.command, {
                        ...this.properties,
                        [TelemetryKeys.JourneyId]: this.journeyId,
                    }, undefined, ['error', 'errorMesage', 'stack']);
            } else if (!(this.options.suppressIfSuccessful && this.properties.result === Result.Succeeded)) {
                TelemetryHelper.reporter.sendTelemetryEvent(
                    this.command, {
                        ...this.properties,
                        [TelemetryKeys.JourneyId]: this.journeyId,
                    });
            }
        }
    }