Send detailed error message when installed standalone simulator failed (#521)

* Send detailed error message when installed standalone simulator failed

* Fix vulnerable dependency, and update according to the comments
This commit is contained in:
Renlong Tu 2019-12-09 17:22:49 +08:00 коммит произвёл GitHub
Родитель 93d0b57c66
Коммит 21034e2c9b
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
3 изменённых файлов: 45 добавлений и 47 удалений

34
package-lock.json сгенерированный
Просмотреть файл

@ -2396,14 +2396,12 @@
"balanced-match": {
"version": "1.0.0",
"bundled": true,
"dev": true,
"optional": true
"dev": true
},
"brace-expansion": {
"version": "1.1.11",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"balanced-match": "^1.0.0",
"concat-map": "0.0.1"
@ -2418,20 +2416,17 @@
"code-point-at": {
"version": "1.1.0",
"bundled": true,
"dev": true,
"optional": true
"dev": true
},
"concat-map": {
"version": "0.0.1",
"bundled": true,
"dev": true,
"optional": true
"dev": true
},
"console-control-strings": {
"version": "1.1.0",
"bundled": true,
"dev": true,
"optional": true
"dev": true
},
"core-util-is": {
"version": "1.0.2",
@ -2548,8 +2543,7 @@
"inherits": {
"version": "2.0.3",
"bundled": true,
"dev": true,
"optional": true
"dev": true
},
"ini": {
"version": "1.3.5",
@ -2561,7 +2555,6 @@
"version": "1.0.0",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"number-is-nan": "^1.0.0"
}
@ -2576,7 +2569,6 @@
"version": "3.0.4",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"brace-expansion": "^1.1.7"
}
@ -2584,14 +2576,12 @@
"minimist": {
"version": "0.0.8",
"bundled": true,
"dev": true,
"optional": true
"dev": true
},
"minipass": {
"version": "2.3.5",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"safe-buffer": "^5.1.2",
"yallist": "^3.0.0"
@ -2610,7 +2600,6 @@
"version": "0.5.1",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"minimist": "0.0.8"
}
@ -2691,8 +2680,7 @@
"number-is-nan": {
"version": "1.0.1",
"bundled": true,
"dev": true,
"optional": true
"dev": true
},
"object-assign": {
"version": "4.1.1",
@ -2704,7 +2692,6 @@
"version": "1.4.0",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"wrappy": "1"
}
@ -2826,7 +2813,6 @@
"version": "1.0.2",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"code-point-at": "^1.0.0",
"is-fullwidth-code-point": "^1.0.0",
@ -3211,9 +3197,9 @@
"dev": true
},
"https-proxy-agent": {
"version": "2.2.2",
"resolved": "https://registry.npmjs.org/https-proxy-agent/-/https-proxy-agent-2.2.2.tgz",
"integrity": "sha512-c8Ndjc9Bkpfx/vCJueCPy0jlP4ccCCSNDp8xwCZzPjKJUm+B+u9WX2x98Qx4n1PiMNTWo3D7KK5ifNV/yJyRzg==",
"version": "2.2.4",
"resolved": "https://registry.npmjs.org/https-proxy-agent/-/https-proxy-agent-2.2.4.tgz",
"integrity": "sha512-OmvfoQ53WLjtA9HeYP9RNrWMJzzAz1JGaSFr1nijg0PVR1JaD/xbJq1mdEIIlxGpXp9eSe/O2LgU9DJmTPd0Eg==",
"dev": true,
"requires": {
"agent-base": "^4.3.0",

20
src/edge/InstallResult.ts Normal file
Просмотреть файл

@ -0,0 +1,20 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
"use strict";
export enum InstallReturn {
Success = 0,
Failed,
Canceled,
NotSupported,
IsInstalling,
}
export class InstallResult {
public readonly resultType: InstallReturn;
public readonly errMsg: string;
constructor(resultType: InstallReturn, errMsg: string = null) {
this.resultType = resultType;
this.errMsg = errMsg;
}
}

Просмотреть файл

@ -19,14 +19,7 @@ import { TelemetryClient } from "../common/telemetryClient";
import { UserCancelledError } from "../common/UserCancelledError";
import { Utility } from "../common/utility";
import { IDeviceItem } from "../typings/IDeviceItem";
enum InstallReturn {
Success = 0,
Failed,
Canceled,
NotSupported,
IsInstalling,
}
import { InstallResult, InstallReturn } from "./InstallResult";
enum SimulatorType {
Pip = 0,
@ -116,14 +109,14 @@ export class Simulator {
TelemetryClient.sendEvent(`${telemetryName}.${type}`);
const installRes = await this.autoInstallSimulator(outputChannel);
TelemetryClient.sendEvent(`${telemetryName}.${type}.${InstallReturn[installRes]}`);
if (InstallReturn.NotSupported === installRes) {
const installResult = await this.autoInstallSimulator(outputChannel);
TelemetryClient.sendEvent(`${telemetryName}.${type}.${InstallReturn[installResult.resultType]}`, { error: installResult.errMsg });
if (InstallReturn.NotSupported === installResult.resultType) {
const learnMore: vscode.MessageItem = { title: Constants.learnMore };
if (await vscode.window.showWarningMessage(message, ...[learnMore]) === learnMore) {
await vscode.commands.executeCommand("vscode.open", vscode.Uri.parse(Simulator.learnMoreUrl));
}
} else if (InstallReturn.Failed === installRes) {
} else if (InstallReturn.Failed === installResult.resultType) {
await vscode.window.showErrorMessage(Constants.installStandaloneSimulatorFailedMsg);
}
} catch (err) {
@ -281,9 +274,7 @@ export class Simulator {
req.on("response", (res) => {
if (res.statusCode === 200) {
req.pipe(unzipper.Extract({ path: Simulator.WindowsStandaloneSimulatorFolder }))
.on("close", () => resolve()).on("error", (e) => reject(e));
} else if (res.statusCode === 404) {
reject(new Error("Cannot download simulator, please check that the simulator version has been configured correctly (Example version: 0.12.0)."));
.on("close", () => resolve()).on("error", (e) => reject(new Error("Cannot extract simulator binaries from zip file: " + e.message)));
} else {
reject(new Error("Cannot download simulator with status code: " + res.statusCode));
}
@ -303,16 +294,16 @@ export class Simulator {
this.simulatorExecutablePath = path.join(Simulator.WindowsStandaloneSimulatorFolder, version , Simulator.simulatorExecutableName);
}
private async autoInstallSimulator(outputChannel: vscode.OutputChannel = null): Promise<InstallReturn> {
private async autoInstallSimulator(outputChannel: vscode.OutputChannel = null): Promise<InstallResult> {
// auto install only supported on windows. For linux/macOS ask user install manually.
if (Simulator.currentPlatform !== "win32") {
return InstallReturn.NotSupported;
return new InstallResult(InstallReturn.NotSupported);
}
if (!this.isInstalling) {
this.isInstalling = true;
let ret: InstallReturn = InstallReturn.Success;
let errMsg: string;
try {
await this.downloadStandaloneSimulatorWithProgress();
} catch (error) {
@ -320,12 +311,13 @@ export class Simulator {
outputChannel.appendLine(`${Constants.failedInstallSimulator} ${error.message}`);
}
ret = InstallReturn.Failed;
errMsg = error.message;
}
this.isInstalling = false;
return ret;
return new InstallResult(ret, errMsg);
} else {
return InstallReturn.IsInstalling;
return new InstallResult(InstallReturn.IsInstalling);
}
}
@ -381,9 +373,9 @@ export class Simulator {
const telemetryName = "simulatorInstalled";
if (await this.simulatorInstalled() === SimulatorType.NotInstalled) {
TelemetryClient.sendEvent(`${telemetryName}.install`);
const installRes = await this.autoInstallSimulator(outputChannel);
TelemetryClient.sendEvent(`${telemetryName}.install.${InstallReturn[installRes]}`);
return installRes;
const installResult = await this.autoInstallSimulator(outputChannel);
TelemetryClient.sendEvent(`${telemetryName}.install.${InstallReturn[installResult.resultType]}`, { error: installResult.errMsg });
return installResult.resultType;
} else {
return InstallReturn.Success;
}