Skip to content

Commit 5b3d57d

Browse files
Factor out sendStartupTelemetryInBackground().
1 parent c9cbb95 commit 5b3d57d

2 files changed

Lines changed: 18 additions & 8 deletions

File tree

‎src/client/extension.ts‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ import { registerTypes as providersRegisterTypes } from './providers/serviceRegi
9898
import { activateSimplePythonRefactorProvider } from './providers/simpleRefactorProvider';
9999
import { TerminalProvider } from './providers/terminalProvider';
100100
import { ISortImportsEditingProvider } from './providers/types';
101-
import { sendErrorTelemetry, sendStartupTelemetry } from './startupTelemetry';
101+
import { sendErrorTelemetry, sendStartupTelemetryInBackground } from './startupTelemetry';
102102
import { registerTypes as commonRegisterTerminalTypes } from './terminals/serviceRegistry';
103103
import { ICodeExecutionManager, ITerminalAutoActivation } from './terminals/types';
104104
import { TEST_OUTPUT_CHANNEL } from './testing/common/constants';
@@ -118,7 +118,9 @@ export async function activate(context: ExtensionContext): Promise<IExtensionApi
118118
try {
119119
return await activateUnsafe(context);
120120
} catch (ex) {
121-
handleError(ex);
121+
// We want to completely handle the error
122+
// before notifying VS Code.
123+
await handleError(ex);
122124
throw ex; // re-raise
123125
}
124126
}
@@ -156,9 +158,7 @@ async function activateUnsafe(context: ExtensionContext): Promise<IExtensionApi>
156158
durations.endActivateTime = stopWatch.elapsedTime;
157159
activationDeferred.resolve();
158160

159-
sendStartupTelemetry(activationPromise, durations, stopWatch, serviceContainer)
160-
// It will run in the background.
161-
.ignoreErrors();
161+
sendStartupTelemetryInBackground(activationPromise, durations, stopWatch, serviceContainer);
162162

163163
return buildApi(activationPromise, serviceManager, serviceContainer);
164164
}
@@ -360,12 +360,12 @@ async function initializeServices(
360360
/////////////////////////////
361361
// error handling
362362

363-
function handleError(ex: Error) {
363+
async function handleError(ex: Error) {
364364
notifyUser(
365365
"Extension activation failed, run the 'Developer: Toggle Developer Tools' command for more information."
366366
);
367367
traceError('extension activation failed', ex);
368-
sendErrorTelemetry(ex, durations, activatedServiceContainer).ignoreErrors();
368+
await sendErrorTelemetry(ex, durations, activatedServiceContainer);
369369
}
370370

371371
interface IAppShell {

‎src/client/startupTelemetry.ts‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,17 @@ interface IStopWatch {
2121
elapsedTime: number;
2222
}
2323

24-
export async function sendStartupTelemetry(
24+
export function sendStartupTelemetryInBackground(
25+
// tslint:disable-next-line:no-any
26+
activatedPromise: Promise<any>,
27+
durations: Record<string, number>,
28+
stopWatch: IStopWatch,
29+
serviceContainer: IServiceContainer
30+
) {
31+
sendStartupTelemetry(activatedPromise, durations, stopWatch, serviceContainer).ignoreErrors();
32+
}
33+
34+
async function sendStartupTelemetry(
2535
// tslint:disable-next-line:no-any
2636
activatedPromise: Promise<any>,
2737
durations: Record<string, number>,

0 commit comments

Comments
 (0)