From 0412ba194bc0b073a9436cd57c0fbd43458054d6 Mon Sep 17 00:00:00 2001 From: Cory Rivera Date: Fri, 7 Apr 2023 14:55:17 -0700 Subject: [PATCH] Add more error handling for python installation (#22650) --- .../src/jupyter/jupyterServerInstallation.ts | 85 ++++++++++--------- 1 file changed, 45 insertions(+), 40 deletions(-) diff --git a/extensions/notebook/src/jupyter/jupyterServerInstallation.ts b/extensions/notebook/src/jupyter/jupyterServerInstallation.ts index e0a72fc1bf..1924e26415 100644 --- a/extensions/notebook/src/jupyter/jupyterServerInstallation.ts +++ b/extensions/notebook/src/jupyter/jupyterServerInstallation.ts @@ -430,51 +430,56 @@ export class JupyterServerInstallation implements IJupyterServerInstallation { this._installInProgress = true; this._installCompletion = new Deferred(); + try { + this._pythonInstallationPath = installSettings.installPath; + this._usingExistingPython = installSettings.existingPython; + await this.configurePackagePaths(); - this._pythonInstallationPath = installSettings.installPath; - this._usingExistingPython = installSettings.existingPython; - await this.configurePackagePaths(); + azdata.tasks.startBackgroundOperation({ + displayName: msgTaskName, + description: msgTaskName, + isCancelable: false, + operation: op => { + this.installDependencies(op, forceInstall, installSettings.packages) + .then(async () => { + let notebookConfig = vscode.workspace.getConfiguration(constants.notebookConfigKey); + await notebookConfig.update(constants.pythonPathConfigKey, this._pythonInstallationPath, vscode.ConfigurationTarget.Global); + await notebookConfig.update(constants.existingPythonConfigKey, this._usingExistingPython, vscode.ConfigurationTarget.Global); + await this.configurePackagePaths(); - azdata.tasks.startBackgroundOperation({ - displayName: msgTaskName, - description: msgTaskName, - isCancelable: false, - operation: op => { - this.installDependencies(op, forceInstall, installSettings.packages) - .then(async () => { - let notebookConfig = vscode.workspace.getConfiguration(constants.notebookConfigKey); - await notebookConfig.update(constants.pythonPathConfigKey, this._pythonInstallationPath, vscode.ConfigurationTarget.Global); - await notebookConfig.update(constants.existingPythonConfigKey, this._usingExistingPython, vscode.ConfigurationTarget.Global); - await this.configurePackagePaths(); + this._installCompletion.resolve(); + this._installInProgress = false; + if (this._upgradeInProcess) { + // Pass in false for restartJupyterServer parameter since the jupyter server has already been shutdown + // when removing the old Python version on Windows. + if (process.platform === constants.winPlatform) { + await vscode.commands.executeCommand('notebook.action.restartJupyterNotebookSessions', false); + } else { + await vscode.commands.executeCommand('notebook.action.restartJupyterNotebookSessions'); + } + if (this._oldUserInstalledPipPackages.length !== 0) { + await this.createInstallPipPackagesHelpNotebook(this._oldUserInstalledPipPackages); + } - this._installCompletion.resolve(); - this._installInProgress = false; - if (this._upgradeInProcess) { - // Pass in false for restartJupyterServer parameter since the jupyter server has already been shutdown - // when removing the old Python version on Windows. - if (process.platform === constants.winPlatform) { - await vscode.commands.executeCommand('notebook.action.restartJupyterNotebookSessions', false); - } else { + await fs.remove(this._oldPythonInstallationPath); + this._upgradeInProcess = false; + } else if (!installSettings.packageUpgradeOnly) { await vscode.commands.executeCommand('notebook.action.restartJupyterNotebookSessions'); } - if (this._oldUserInstalledPipPackages.length !== 0) { - await this.createInstallPipPackagesHelpNotebook(this._oldUserInstalledPipPackages); - } - - await fs.remove(this._oldPythonInstallationPath); - this._upgradeInProcess = false; - } else if (!installSettings.packageUpgradeOnly) { - await vscode.commands.executeCommand('notebook.action.restartJupyterNotebookSessions'); - } - }) - .catch(err => { - let errorMsg = msgDependenciesInstallationFailed(utils.getErrorMessage(err)); - op.updateStatus(azdata.TaskStatus.Failed, errorMsg); - this._installCompletion.reject(errorMsg); - this._installInProgress = false; - }); - } - }); + }) + .catch(err => { + let errorMsg = msgDependenciesInstallationFailed(utils.getErrorMessage(err)); + op.updateStatus(azdata.TaskStatus.Failed, errorMsg); + this._installCompletion.reject(new Error(errorMsg)); + this._installInProgress = false; + }); + } + }); + } catch (err) { + let errorMsg = msgDependenciesInstallationFailed(utils.getErrorMessage(err)); + this._installCompletion.reject(new Error(errorMsg)); + this._installInProgress = false; + } return this._installCompletion.promise; }