added try catch aroud the json parse and bypassing the err by logging… (#8166)

* added try catch aroud the json parse and bypassing the err by logging to console

* updated error message with package info

* updates to address PR comments

* added package info and refactored the err logging

* backslash update

* refactored error method and added try for the entire method
This commit is contained in:
Maddy
2019-10-31 17:57:26 -07:00
committed by GitHub
parent 2558d6bff6
commit 7cc430d199

View File

@@ -36,6 +36,7 @@ const msgSkipPythonInstall = localize('msgSkipPythonInstall', "Python already ex
const msgWaitingForInstall = localize('msgWaitingForInstall', "Another Python installation is currently in progress. Waiting for it to complete."); const msgWaitingForInstall = localize('msgWaitingForInstall', "Another Python installation is currently in progress. Waiting for it to complete.");
function msgDependenciesInstallationFailed(errorMessage: string): string { return localize('msgDependenciesInstallationFailed', "Installing Notebook dependencies failed with error: {0}", errorMessage); } function msgDependenciesInstallationFailed(errorMessage: string): string { return localize('msgDependenciesInstallationFailed', "Installing Notebook dependencies failed with error: {0}", errorMessage); }
function msgDownloadPython(platform: string, pythonDownloadUrl: string): string { return localize('msgDownloadPython', "Downloading local python for platform: {0} to {1}", platform, pythonDownloadUrl); } function msgDownloadPython(platform: string, pythonDownloadUrl: string): string { return localize('msgDownloadPython', "Downloading local python for platform: {0} to {1}", platform, pythonDownloadUrl); }
function msgPackageRetrievalFailed(errorMessage: string): string { return localize('msgPackageRetrievalFailed', "Encountered an error when trying to retrieve list of installed packages: {0}", errorMessage); }
export class JupyterServerInstallation { export class JupyterServerInstallation {
public apiWrapper: ApiWrapper; public apiWrapper: ApiWrapper;
@@ -519,15 +520,20 @@ export class JupyterServerInstallation {
} }
public async getInstalledPipPackages(): Promise<PythonPkgDetails[]> { public async getInstalledPipPackages(): Promise<PythonPkgDetails[]> {
try {
let cmd = `"${this.pythonExecutable}" -m pip list --format=json`; let cmd = `"${this.pythonExecutable}" -m pip list --format=json`;
let packagesInfo = await this.executeBufferedCommand(cmd); let packagesInfo = await this.executeBufferedCommand(cmd);
let packagesResult: PythonPkgDetails[] = []; let packagesResult: PythonPkgDetails[] = [];
if (packagesInfo) { if (packagesInfo) {
packagesResult = <PythonPkgDetails[]>JSON.parse(packagesInfo); packagesResult = <PythonPkgDetails[]>JSON.parse(packagesInfo);
} }
return packagesResult; return packagesResult;
} }
catch (err) {
this.outputChannel.appendLine(msgPackageRetrievalFailed(utils.getErrorMessage(err)));
return [];
}
}
public installPipPackages(packages: PythonPkgDetails[], useMinVersion: boolean): Promise<void> { public installPipPackages(packages: PythonPkgDetails[], useMinVersion: boolean): Promise<void> {
if (!packages || packages.length === 0) { if (!packages || packages.length === 0) {
@@ -549,6 +555,7 @@ export class JupyterServerInstallation {
} }
public async getInstalledCondaPackages(): Promise<PythonPkgDetails[]> { public async getInstalledCondaPackages(): Promise<PythonPkgDetails[]> {
try {
let condaExe = this.getCondaExePath(); let condaExe = this.getCondaExePath();
let cmd = `"${condaExe}" list --json`; let cmd = `"${condaExe}" list --json`;
let packagesInfo = await this.executeBufferedCommand(cmd); let packagesInfo = await this.executeBufferedCommand(cmd);
@@ -563,6 +570,11 @@ export class JupyterServerInstallation {
} }
return []; return [];
} }
catch (err) {
this.outputChannel.appendLine(msgPackageRetrievalFailed(utils.getErrorMessage(err)));
return [];
}
}
public installCondaPackages(packages: PythonPkgDetails[], useMinVersion: boolean): Promise<void> { public installCondaPackages(packages: PythonPkgDetails[], useMinVersion: boolean): Promise<void> {
if (!packages || packages.length === 0) { if (!packages || packages.length === 0) {