microsoft/vscode-react-native

Public

mirrored from https://github.com/microsoft/vscode-react-nativeAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
0.1.4

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

src/common/entryPointHandler.ts

56lines · modeblame

8ee905e8digeff10 years ago1// Copyright (c) Microsoft Corporation. All rights reserved.
2// Licensed under the MIT license. See LICENSE file in the project root for details.
3
190e393cMeena Kunnathur Balakrishnan10 years ago4
5import {ErrorHelper} from "../common/error/errorHelper";
6import {InternalError} from "../common/error/internalError";
8e2d694fdigeff10 years ago7import {TelemetryHelper} from "../common/telemetryHelper";
8import {Telemetry} from "../common/telemetry";
190e393cMeena Kunnathur Balakrishnan10 years ago9import {Log} from "../common/log/log";
e8771a03Meena Kunnathur Balakrishnan10 years ago10import {ILogger} from "../common/log/loggers";
10873e11digeff10 years ago11
12/* This class should we used for each entry point of the code, so we handle telemetry and error reporting properly */
47958817digeff10 years ago13export class EntryPointHandler {
e8771a03Meena Kunnathur Balakrishnan10 years ago14private isDebugeeProcess: boolean;
10873e11digeff10 years ago15
e8771a03Meena Kunnathur Balakrishnan10 years ago16constructor(isDebugeeProcess: boolean = false, logger?: ILogger) {
17if (logger) {
18Log.SetGlobalLogger(logger);
898cb3c6Meena Kunnathur Balakrishnan10 years ago19}
e8771a03Meena Kunnathur Balakrishnan10 years ago20
21this.isDebugeeProcess = isDebugeeProcess;
10873e11digeff10 years ago22}
23
ac1bd6f1digeff10 years ago24
10873e11digeff10 years ago25/* This method should wrap any async entry points to the code, so we handle telemetry and error reporting properly */
190e393cMeena Kunnathur Balakrishnan10 years ago26public runFunction(taskName: string, error: InternalError, codeToRun: () => Q.Promise<void> | void, errorsAreFatal: boolean = false): void {
27return this.handleErrors(error, TelemetryHelper.generate(taskName, codeToRun), /*errorsAreFatal*/ errorsAreFatal);
10873e11digeff10 years ago28}
29
41c61f9aJoshua Skelton10 years ago30// This method should wrap the entry point of the whole app, so we handle telemetry and error reporting properly
190e393cMeena Kunnathur Balakrishnan10 years ago31public runApp(appName: string, getAppVersion: () => string, error: InternalError, codeToRun: () => Q.Promise<void>): void {
41c61f9aJoshua Skelton10 years ago32try {
33Telemetry.init(appName, getAppVersion(), {isExtensionProcess: !this.isDebugeeProcess});
34return this.runFunction(appName, error, codeToRun, true);
10873e11digeff10 years ago35} catch (error) {
41c61f9aJoshua Skelton10 years ago36Log.logError(error, false);
10873e11digeff10 years ago37throw error;
38}
39}
40
190e393cMeena Kunnathur Balakrishnan10 years ago41private handleErrors(error: InternalError, resultOfCode: Q.Promise<void>, errorsAreFatal: boolean): void {
0af0605cdigeff10 years ago42resultOfCode.done(() => { }, reason => {
e8771a03Meena Kunnathur Balakrishnan10 years ago43const shouldLogStack = !errorsAreFatal || this.isDebugeeProcess;
898cb3c6Meena Kunnathur Balakrishnan10 years ago44Log.logError(ErrorHelper.wrapError(error, reason), /*logStack*/ shouldLogStack);
b2992671Joshua Skelton10 years ago45// For the debugee process we don't want to throw an exception because the debugger
46// will appear to the user if he turned on the VS Code uncaught exceptions feature.
0af0605cdigeff10 years ago47if (errorsAreFatal) {
6e4d7a62Joshua Skelton10 years ago48if (this.isDebugeeProcess) {
49process.exit(1);
50} else {
51throw reason;
52}
10873e11digeff10 years ago53}
54});
55}
56}