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.");
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 msgPackageRetrievalFailed(errorMessage: string): string { return localize('msgPackageRetrievalFailed', "Encountered an error when trying to retrieve list of installed packages: {0}", errorMessage); }
export class JupyterServerInstallation {
public apiWrapper: ApiWrapper;
@@ -519,14 +520,19 @@ export class JupyterServerInstallation {
}
public async getInstalledPipPackages(): Promise<PythonPkgDetails[]> {
let cmd = `"${this.pythonExecutable}" -m pip list --format=json`;
let packagesInfo = await this.executeBufferedCommand(cmd);
let packagesResult: PythonPkgDetails[] = [];
if (packagesInfo) {
packagesResult = <PythonPkgDetails[]>JSON.parse(packagesInfo);
try {
let cmd = `"${this.pythonExecutable}" -m pip list --format=json`;
let packagesInfo = await this.executeBufferedCommand(cmd);
let packagesResult: PythonPkgDetails[] = [];
if (packagesInfo) {
packagesResult = <PythonPkgDetails[]>JSON.parse(packagesInfo);
}
return packagesResult;
}
catch (err) {
this.outputChannel.appendLine(msgPackageRetrievalFailed(utils.getErrorMessage(err)));
return [];
}
return packagesResult;
}
public installPipPackages(packages: PythonPkgDetails[], useMinVersion: boolean): Promise<void> {
@@ -549,19 +555,25 @@ export class JupyterServerInstallation {
}
public async getInstalledCondaPackages(): Promise<PythonPkgDetails[]> {
let condaExe = this.getCondaExePath();
let cmd = `"${condaExe}" list --json`;
let packagesInfo = await this.executeBufferedCommand(cmd);
try {
let condaExe = this.getCondaExePath();
let cmd = `"${condaExe}" list --json`;
let packagesInfo = await this.executeBufferedCommand(cmd);
if (packagesInfo) {
let packagesResult = JSON.parse(packagesInfo);
if (Array.isArray(packagesResult)) {
return packagesResult
.filter(pkg => pkg && pkg.channel && pkg.channel !== 'pypi')
.map(pkg => <PythonPkgDetails>{ name: pkg.name, version: pkg.version });
if (packagesInfo) {
let packagesResult = JSON.parse(packagesInfo);
if (Array.isArray(packagesResult)) {
return packagesResult
.filter(pkg => pkg && pkg.channel && pkg.channel !== 'pypi')
.map(pkg => <PythonPkgDetails>{ name: pkg.name, version: pkg.version });
}
}
return [];
}
catch (err) {
this.outputChannel.appendLine(msgPackageRetrievalFailed(utils.getErrorMessage(err)));
return [];
}
return [];
}
public installCondaPackages(packages: PythonPkgDetails[], useMinVersion: boolean): Promise<void> {