Notebook Extension: First logging improvements (#13729)

* First logging improvements

* PR feedback for err output
This commit is contained in:
Chris LaFreniere
2020-12-11 11:21:06 -08:00
committed by GitHub
parent 2df67c4f78
commit a5231ec0e5
12 changed files with 28 additions and 20 deletions

View File

@@ -262,7 +262,7 @@ export function getIgnoreSslVerificationConfigSetting(): boolean {
const config = vscode.workspace.getConfiguration(bdcConfigSectionName); const config = vscode.workspace.getConfiguration(bdcConfigSectionName);
return config.get<boolean>(ignoreSslConfigName, true); return config.get<boolean>(ignoreSslConfigName, true);
} catch (error) { } catch (error) {
console.error(`Unexpected error retrieving ${bdcConfigSectionName}.${ignoreSslConfigName} setting : ${error}`); console.error('Unexpected error retrieving ${bdcConfigSectionName}.${ignoreSslConfigName} setting : ', error);
} }
return true; return true;
} }

View File

@@ -5,6 +5,7 @@
import * as nls from 'vscode-nls'; import * as nls from 'vscode-nls';
import * as azdata from 'azdata'; import * as azdata from 'azdata';
import * as vscode from 'vscode';
import { BasePage } from './basePage'; import { BasePage } from './basePage';
import { ConfigurePathPage } from './configurePathPage'; import { ConfigurePathPage } from './configurePathPage';
import { PickPackagesPage } from './pickPackagesPage'; import { PickPackagesPage } from './pickPackagesPage';
@@ -36,9 +37,9 @@ export class ConfigurePythonWizard {
private _setupComplete: Deferred<void>; private _setupComplete: Deferred<void>;
private pythonPathsPromise: Promise<PythonPathInfo[]>; private pythonPathsPromise: Promise<PythonPathInfo[]>;
constructor(private jupyterInstallation: JupyterServerInstallation) { constructor(private jupyterInstallation: JupyterServerInstallation, private readonly _outputChannel: vscode.OutputChannel) {
this._setupComplete = new Deferred<void>(); this._setupComplete = new Deferred<void>();
this.pythonPathsPromise = (new PythonPathLookup()).getSuggestions(); this.pythonPathsPromise = (new PythonPathLookup(this._outputChannel)).getSuggestions();
} }
public get wizard(): azdata.window.Wizard { public get wizard(): azdata.window.Wizard {
@@ -49,7 +50,7 @@ export class ConfigurePythonWizard {
return this._setupComplete.promise; return this._setupComplete.promise;
} }
public async start(kernelName?: string, rejectOnCancel?: boolean, ...args: any[]): Promise<void> { public async start(kernelName?: string, rejectOnCancel?: boolean): Promise<void> {
this.model = <ConfigurePythonModel>{ this.model = <ConfigurePythonModel>{
kernelName: kernelName, kernelName: kernelName,
pythonPathsPromise: this.pythonPathsPromise, pythonPathsPromise: this.pythonPathsPromise,

View File

@@ -111,6 +111,8 @@ export class AddNewPackageTab {
placeHolder: this.SearchPlaceholder(this.dialog.model.currentPackageType) placeHolder: this.SearchPlaceholder(this.dialog.model.currentPackageType)
}); });
await this.setFieldsToEmpty(); await this.setFieldsToEmpty();
} catch (err) {
console.error('Exception encountered when resetting new package page fields: ', err);
} finally { } finally {
await this.toggleNewPackagesFields(true); await this.toggleNewPackagesFields(true);
} }

View File

@@ -65,7 +65,6 @@ export class InstalledPackagesTab {
} }
catch (err) { catch (err) {
this.dialog.showErrorMessage(utils.getErrorMessage(err)); this.dialog.showErrorMessage(utils.getErrorMessage(err));
} }
}); });

View File

@@ -4,6 +4,7 @@
*--------------------------------------------------------------------------------------------*/ *--------------------------------------------------------------------------------------------*/
import * as glob from 'glob'; import * as glob from 'glob';
import * as vscode from 'vscode';
import * as utils from '../common/utils'; import * as utils from '../common/utils';
import * as constants from '../common/constants'; import * as constants from '../common/constants';
@@ -15,7 +16,7 @@ export interface PythonPathInfo {
export class PythonPathLookup { export class PythonPathLookup {
private condaLocations: string[]; private condaLocations: string[];
constructor() { constructor(private readonly _outputChannel: vscode.OutputChannel) {
if (process.platform !== constants.winPlatform) { if (process.platform !== constants.winPlatform) {
let userFolder = process.env['HOME']; let userFolder = process.env['HOME'];
this.condaLocations = [ this.condaLocations = [
@@ -56,6 +57,7 @@ export class PythonPathLookup {
let condaFiles = condaResults.reduce((first, second) => first.concat(second)); let condaFiles = condaResults.reduce((first, second) => first.concat(second));
return condaFiles.filter(condaPath => condaPath && condaPath.length > 0); return condaFiles.filter(condaPath => condaPath && condaPath.length > 0);
} catch (err) { } catch (err) {
this._outputChannel.appendLine(`Problem encountered getting Conda installations: ${err}`);
} }
return []; return [];
} }
@@ -95,7 +97,7 @@ export class PythonPathLookup {
return value; return value;
} }
} catch (err) { } catch (err) {
// Ignore errors here, since this python version will just be excluded. this._outputChannel.appendLine(`Problem encountered getting Python path: ${err}`);
} }
return undefined; return undefined;
@@ -158,7 +160,7 @@ export class PythonPathLookup {
}; };
} }
} catch (err) { } catch (err) {
// Ignore errors here, since this python version will just be excluded. this._outputChannel.appendLine(`Problem encountered getting Python info for path: ${err}`);
} }
return undefined; return undefined;
} }

View File

@@ -114,6 +114,7 @@ export async function activate(extensionContext: vscode.ExtensionContext): Promi
cellType = selection.id; cellType = selection.id;
} }
} catch (err) { } catch (err) {
console.error('Unexpected error adding new cell: ', err);
return; return;
} }
if (cellType) { if (cellType) {

View File

@@ -57,8 +57,8 @@ export class NotebookCompletionItemProvider implements vscode.CompletionItemProv
return session.kernel; return session.kernel;
} }
} }
} catch { } catch (err) {
// If an exception occurs, swallow it currently console.error('Exception encountered finding document kernel: ', err);
return undefined; return undefined;
} }
return undefined; return undefined;
@@ -194,4 +194,4 @@ export interface INewIntellisenseInfo {
cell: nb.NotebookCell; cell: nb.NotebookCell;
notebook: nb.NotebookDocument; notebook: nb.NotebookDocument;
kernel?: nb.IKernel; kernel?: nb.IKernel;
} }

View File

@@ -234,7 +234,7 @@ export class JupyterController {
} }
public doConfigurePython(jupyterInstaller: JupyterServerInstallation): void { public doConfigurePython(jupyterInstaller: JupyterServerInstallation): void {
let pythonWizard = new ConfigurePythonWizard(jupyterInstaller); let pythonWizard = new ConfigurePythonWizard(jupyterInstaller, this.appContext.outputChannel);
pythonWizard.start().catch((err: any) => { pythonWizard.start().catch((err: any) => {
vscode.window.showErrorMessage(utils.getErrorMessage(err)); vscode.window.showErrorMessage(utils.getErrorMessage(err));
}); });

View File

@@ -435,7 +435,7 @@ export class JupyterServerInstallation implements IJupyterServerInstallation {
let isPythonInstalled = JupyterServerInstallation.isPythonInstalled(); let isPythonInstalled = JupyterServerInstallation.isPythonInstalled();
let areRequiredPackagesInstalled = await this.areRequiredPackagesInstalled(kernelDisplayName); let areRequiredPackagesInstalled = await this.areRequiredPackagesInstalled(kernelDisplayName);
if (!isPythonInstalled || !areRequiredPackagesInstalled) { if (!isPythonInstalled || !areRequiredPackagesInstalled) {
let pythonWizard = new ConfigurePythonWizard(this); let pythonWizard = new ConfigurePythonWizard(this, this.outputChannel);
await pythonWizard.start(kernelDisplayName, true); await pythonWizard.start(kernelDisplayName, true);
return pythonWizard.setupComplete.then(() => { return pythonWizard.setupComplete.then(() => {
this._kernelSetupCache.set(kernelDisplayName, true); this._kernelSetupCache.set(kernelDisplayName, true);

View File

@@ -184,7 +184,7 @@ export class JupyterSession implements nb.ISession {
skipSettingEnvironmentVars?: boolean, skipSettingEnvironmentVars?: boolean,
private _pythonEnvVarPath?: string) { private _pythonEnvVarPath?: string) {
this.setEnvironmentVars(skipSettingEnvironmentVars).catch(error => { this.setEnvironmentVars(skipSettingEnvironmentVars).catch(error => {
console.error(`Unexpected exception setting Jupyter Session variables : ${error}`); console.error('Unexpected exception setting Jupyter Session variables : ', error);
// We don't want callers to hang forever waiting - it's better to continue on even if we weren't // We don't want callers to hang forever waiting - it's better to continue on even if we weren't
// able to set environment variables // able to set environment variables
this._messagesComplete.resolve(); this._messagesComplete.resolve();
@@ -240,7 +240,7 @@ export class JupyterSession implements nb.ISession {
await this._installation.promptForPythonInstall(kernelInfo.display_name); await this._installation.promptForPythonInstall(kernelInfo.display_name);
} catch (err) { } catch (err) {
// Have to swallow the error here to prevent hangs when changing back to the old kernel. // Have to swallow the error here to prevent hangs when changing back to the old kernel.
console.error(err.toString()); console.error('Exception encountered prompting for Python install', err);
return this._kernel; return this._kernel;
} }
} }

View File

@@ -279,7 +279,7 @@ export class PerFolderServerInstance implements IServerInstance {
} }
private handleConnectionError(error: Error): void { private handleConnectionError(error: Error): void {
let action = this.errorHandler.handleError(error); let action = this.errorHandler.handleError();
if (action === ErrorAction.Shutdown) { if (action === ErrorAction.Shutdown) {
this.notify(this.options.install, localize('jupyterError', "Error sent from Jupyter: {0}", utils.getErrorMessage(error))); this.notify(this.options.install, localize('jupyterError', "Error sent from Jupyter: {0}", utils.getErrorMessage(error)));
this.stop(); this.stop();
@@ -365,7 +365,7 @@ export class PerFolderServerInstance implements IServerInstance {
class ErrorHandler { class ErrorHandler {
private numErrors: number = 0; private numErrors: number = 0;
public handleError(error: Error): ErrorAction { public handleError(): ErrorAction {
this.numErrors++; this.numErrors++;
return this.numErrors > 3 ? ErrorAction.Shutdown : ErrorAction.Continue; return this.numErrors > 3 ? ErrorAction.Shutdown : ErrorAction.Continue;
} }

View File

@@ -13,13 +13,16 @@ import { PickPackagesPage } from '../../dialog/configurePython/pickPackagesPage'
import { python3DisplayName, allKernelsName } from '../../common/constants'; import { python3DisplayName, allKernelsName } from '../../common/constants';
import { TestContext, createViewContext, TestButton } from '../common'; import { TestContext, createViewContext, TestButton } from '../common';
import { EventEmitter } from 'vscode'; import { EventEmitter } from 'vscode';
import { MockOutputChannel } from '../common/stubs';
describe('Configure Python Wizard', function () { describe('Configure Python Wizard', function () {
let testWizard: ConfigurePythonWizard; let testWizard: ConfigurePythonWizard;
let viewContext: TestContext; let viewContext: TestContext;
let testInstallation: JupyterServerInstallation; let testInstallation: JupyterServerInstallation;
let mockOutputChannel: TypeMoq.IMock<MockOutputChannel>;
beforeEach(() => { beforeEach(() => {
mockOutputChannel = TypeMoq.Mock.ofType(MockOutputChannel);
let mockInstall = TypeMoq.Mock.ofType(JupyterServerInstallation); let mockInstall = TypeMoq.Mock.ofType(JupyterServerInstallation);
mockInstall.setup(i => i.getInstalledPipPackages(TypeMoq.It.isAnyString())).returns(() => Promise.resolve([])); mockInstall.setup(i => i.getInstalledPipPackages(TypeMoq.It.isAnyString())).returns(() => Promise.resolve([]));
mockInstall.setup(i => i.getRequiredPackagesForKernel(TypeMoq.It.isAnyString())).returns(() => [{ name: 'TestPkg', version: '1.0.0'}]); mockInstall.setup(i => i.getRequiredPackagesForKernel(TypeMoq.It.isAnyString())).returns(() => [{ name: 'TestPkg', version: '1.0.0'}]);
@@ -41,21 +44,21 @@ describe('Configure Python Wizard', function () {
}); });
it('Start wizard test', async () => { it('Start wizard test', async () => {
let wizard = new ConfigurePythonWizard(testInstallation); let wizard = new ConfigurePythonWizard(testInstallation, mockOutputChannel.object);
await wizard.start(); await wizard.start();
await wizard.close(); await wizard.close();
await should(wizard.setupComplete).be.resolved(); await should(wizard.setupComplete).be.resolved();
}); });
it('Reject setup on cancel test', async () => { it('Reject setup on cancel test', async () => {
let wizard = new ConfigurePythonWizard(testInstallation); let wizard = new ConfigurePythonWizard(testInstallation, mockOutputChannel.object);
await wizard.start(undefined, true); await wizard.start(undefined, true);
await wizard.close(); await wizard.close();
await should(wizard.setupComplete).be.rejected(); await should(wizard.setupComplete).be.rejected();
}); });
it('Error message test', async () => { it('Error message test', async () => {
let wizard = new ConfigurePythonWizard(testInstallation); let wizard = new ConfigurePythonWizard(testInstallation, mockOutputChannel.object);
await wizard.start(); await wizard.start();
should(wizard.wizard.message).be.undefined(); should(wizard.wizard.message).be.undefined();