Add more error handling for python installation (#22650)

This commit is contained in:
Cory Rivera
2023-04-07 14:55:17 -07:00
committed by GitHub
parent 6a2ec12a35
commit 0412ba194b

View File

@@ -430,51 +430,56 @@ export class JupyterServerInstallation implements IJupyterServerInstallation {
this._installInProgress = true; this._installInProgress = true;
this._installCompletion = new Deferred<void>(); this._installCompletion = new Deferred<void>();
try {
this._pythonInstallationPath = installSettings.installPath;
this._usingExistingPython = installSettings.existingPython;
await this.configurePackagePaths();
this._pythonInstallationPath = installSettings.installPath; azdata.tasks.startBackgroundOperation({
this._usingExistingPython = installSettings.existingPython; displayName: msgTaskName,
await this.configurePackagePaths(); 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({ this._installCompletion.resolve();
displayName: msgTaskName, this._installInProgress = false;
description: msgTaskName, if (this._upgradeInProcess) {
isCancelable: false, // Pass in false for restartJupyterServer parameter since the jupyter server has already been shutdown
operation: op => { // when removing the old Python version on Windows.
this.installDependencies(op, forceInstall, installSettings.packages) if (process.platform === constants.winPlatform) {
.then(async () => { await vscode.commands.executeCommand('notebook.action.restartJupyterNotebookSessions', false);
let notebookConfig = vscode.workspace.getConfiguration(constants.notebookConfigKey); } else {
await notebookConfig.update(constants.pythonPathConfigKey, this._pythonInstallationPath, vscode.ConfigurationTarget.Global); await vscode.commands.executeCommand('notebook.action.restartJupyterNotebookSessions');
await notebookConfig.update(constants.existingPythonConfigKey, this._usingExistingPython, vscode.ConfigurationTarget.Global); }
await this.configurePackagePaths(); if (this._oldUserInstalledPipPackages.length !== 0) {
await this.createInstallPipPackagesHelpNotebook(this._oldUserInstalledPipPackages);
}
this._installCompletion.resolve(); await fs.remove(this._oldPythonInstallationPath);
this._installInProgress = false; this._upgradeInProcess = false;
if (this._upgradeInProcess) { } else if (!installSettings.packageUpgradeOnly) {
// 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'); await vscode.commands.executeCommand('notebook.action.restartJupyterNotebookSessions');
} }
if (this._oldUserInstalledPipPackages.length !== 0) { })
await this.createInstallPipPackagesHelpNotebook(this._oldUserInstalledPipPackages); .catch(err => {
} let errorMsg = msgDependenciesInstallationFailed(utils.getErrorMessage(err));
op.updateStatus(azdata.TaskStatus.Failed, errorMsg);
await fs.remove(this._oldPythonInstallationPath); this._installCompletion.reject(new Error(errorMsg));
this._upgradeInProcess = false; this._installInProgress = false;
} else if (!installSettings.packageUpgradeOnly) { });
await vscode.commands.executeCommand('notebook.action.restartJupyterNotebookSessions'); }
} });
}) } catch (err) {
.catch(err => { let errorMsg = msgDependenciesInstallationFailed(utils.getErrorMessage(err));
let errorMsg = msgDependenciesInstallationFailed(utils.getErrorMessage(err)); this._installCompletion.reject(new Error(errorMsg));
op.updateStatus(azdata.TaskStatus.Failed, errorMsg); this._installInProgress = false;
this._installCompletion.reject(errorMsg); }
this._installInProgress = false;
});
}
});
return this._installCompletion.promise; return this._installCompletion.promise;
} }