mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-16 18:46:40 -05:00
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:
@@ -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,14 +520,19 @@ export class JupyterServerInstallation {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public async getInstalledPipPackages(): Promise<PythonPkgDetails[]> {
|
public async getInstalledPipPackages(): Promise<PythonPkgDetails[]> {
|
||||||
let cmd = `"${this.pythonExecutable}" -m pip list --format=json`;
|
try {
|
||||||
let packagesInfo = await this.executeBufferedCommand(cmd);
|
let cmd = `"${this.pythonExecutable}" -m pip list --format=json`;
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
catch (err) {
|
||||||
|
this.outputChannel.appendLine(msgPackageRetrievalFailed(utils.getErrorMessage(err)));
|
||||||
|
return [];
|
||||||
}
|
}
|
||||||
return packagesResult;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public installPipPackages(packages: PythonPkgDetails[], useMinVersion: boolean): Promise<void> {
|
public installPipPackages(packages: PythonPkgDetails[], useMinVersion: boolean): Promise<void> {
|
||||||
@@ -549,19 +555,25 @@ export class JupyterServerInstallation {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public async getInstalledCondaPackages(): Promise<PythonPkgDetails[]> {
|
public async getInstalledCondaPackages(): Promise<PythonPkgDetails[]> {
|
||||||
let condaExe = this.getCondaExePath();
|
try {
|
||||||
let cmd = `"${condaExe}" list --json`;
|
let condaExe = this.getCondaExePath();
|
||||||
let packagesInfo = await this.executeBufferedCommand(cmd);
|
let cmd = `"${condaExe}" list --json`;
|
||||||
|
let packagesInfo = await this.executeBufferedCommand(cmd);
|
||||||
|
|
||||||
if (packagesInfo) {
|
if (packagesInfo) {
|
||||||
let packagesResult = JSON.parse(packagesInfo);
|
let packagesResult = JSON.parse(packagesInfo);
|
||||||
if (Array.isArray(packagesResult)) {
|
if (Array.isArray(packagesResult)) {
|
||||||
return packagesResult
|
return packagesResult
|
||||||
.filter(pkg => pkg && pkg.channel && pkg.channel !== 'pypi')
|
.filter(pkg => pkg && pkg.channel && pkg.channel !== 'pypi')
|
||||||
.map(pkg => <PythonPkgDetails>{ name: pkg.name, version: pkg.version });
|
.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> {
|
public installCondaPackages(packages: PythonPkgDetails[], useMinVersion: boolean): Promise<void> {
|
||||||
|
|||||||
Reference in New Issue
Block a user