Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move kernel error types #10497

Merged
merged 2 commits into from
Jun 20, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Update kernel error types
rebornix committed Jun 18, 2022

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit 0a5bd6318be68b95f66f36d18ae8a3bb8ad5ab67
2 changes: 1 addition & 1 deletion src/interactive-window/editor-integration/codewatcher.ts
Original file line number Diff line number Diff line change
@@ -26,13 +26,13 @@ import { captureTelemetry, sendTelemetryEvent } from '../../telemetry';
import { ICodeExecutionHelper } from '../../platform/terminals/types';
import { InteractiveCellResultError } from '../../platform/errors/interactiveCellResultError';
import { Telemetry, Commands, Identifiers } from '../../platform/common/constants';
import { IDataScienceErrorHandler } from '../../platform/errors/types';
import { IInteractiveWindowProvider, IInteractiveWindow } from '../types';
import { CellMatcher } from './cellMatcher';
import { ICodeWatcher, ICodeLensFactory } from './types';
import { traceDecoratorVerbose } from '../../platform/logging';
import { TraceOptions } from '../../platform/logging/types';
import * as urlPath from '../../platform/vscode-path/resources';
import { IDataScienceErrorHandler } from '../../kernels/errors/types';

function getIndex(index: number, length: number): number {
// return index within the length range with negative indexing
2 changes: 1 addition & 1 deletion src/interactive-window/interactiveWindow.ts
Original file line number Diff line number Diff line change
@@ -51,7 +51,6 @@ import { IServiceContainer } from '../platform/ioc/types';
import { SysInfoReason } from '../platform/messageTypes';
import { createOutputWithErrorMessageForDisplay } from '../platform/errors/errorUtils';
import { INotebookExporter } from '../kernels/jupyter/types';
import { IDataScienceErrorHandler } from '../platform/errors/types';
import { IExportDialog, ExportFormat } from '../notebooks/export/types';
import { generateCellsFromNotebookDocument } from './editor-integration/cellFactory';
import { CellMatcher } from './editor-integration/cellMatcher';
@@ -67,6 +66,7 @@ import {
IGeneratedCodeStorageFactory,
InteractiveCellMetadata
} from './editor-integration/types';
import { IDataScienceErrorHandler } from '../kernels/errors/types';
import { CellExecutionCreator } from '../kernels/execution/cellExecutionCreator';
import { updateNotebookMetadata } from '../kernels/execution/helpers';
import { chainWithPendingUpdates } from '../kernels/execution/notebookUpdater';
2 changes: 1 addition & 1 deletion src/interactive-window/interactiveWindowCommandListener.ts
Original file line number Diff line number Diff line change
@@ -40,7 +40,7 @@ import { JupyterInstallError } from '../platform/errors/jupyterInstallError';
import { INotebookControllerManager, INotebookEditorProvider } from '../notebooks/types';
import { KernelConnectionMetadata } from '../kernels/types';
import { INotebookExporter, IJupyterExecution } from '../kernels/jupyter/types';
import { IDataScienceErrorHandler } from '../platform/errors/types';
import { IDataScienceErrorHandler } from '../kernels/errors/types';
import { IFileConverter, IExportDialog, ExportFormat } from '../notebooks/export/types';
import { IStatusProvider } from '../platform/progress/types';
import { generateCellsFromDocument } from './editor-integration/cellFactory';
2 changes: 1 addition & 1 deletion src/interactive-window/interactiveWindowProvider.ts
Original file line number Diff line number Diff line change
@@ -53,7 +53,7 @@ import { getInteractiveWindowTitle } from './identity';
import { createDeferred } from '../platform/common/utils/async';
import { getDisplayPath } from '../platform/common/platform/fs-paths';
import { INotebookExporter } from '../kernels/jupyter/types';
import { IDataScienceErrorHandler } from '../platform/errors/types';
import { IDataScienceErrorHandler } from '../kernels/errors/types';
import { IExportDialog } from '../notebooks/export/types';
import { IVSCodeNotebookController } from '../notebooks/controllers/types';
import { ICodeGeneratorFactory, IGeneratedCodeStorageFactory } from './editor-integration/types';
2 changes: 1 addition & 1 deletion src/kernels/errors/jupyterDebuggerNotInstalledError.ts
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@

import { DataScience } from '../../platform/common/utils/localize';
import { KernelConnectionMetadata } from '../types';
import { BaseKernelError } from '../../platform/errors/types';
import { BaseKernelError } from './types';

export class JupyterDebuggerNotInstalledError extends BaseKernelError {
constructor(debuggerPkg: string, message: string | undefined, kernelConnectionMetadata: KernelConnectionMetadata) {
2 changes: 1 addition & 1 deletion src/kernels/errors/jupyterInvalidKernelError.ts
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@ import { DataScience } from '../../platform/common/utils/localize';
import { sendTelemetryEvent, Telemetry } from '../../telemetry';
import { getDisplayNameOrNameOfKernelConnection } from '../helpers';
import { KernelConnectionMetadata } from '../types';
import { BaseKernelError } from '../../platform/errors/types';
import { BaseKernelError } from './types';

export class JupyterInvalidKernelError extends BaseKernelError {
constructor(kernelConnectionMetadata: KernelConnectionMetadata) {
2 changes: 1 addition & 1 deletion src/kernels/errors/jupyterKernelDependencyError.ts
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@
import { DataScience } from '../../platform/common/utils/localize';
import { getDisplayNameOrNameOfKernelConnection } from '../helpers';
import { KernelConnectionMetadata, KernelInterpreterDependencyResponse } from '../types';
import { BaseKernelError } from '../../platform/errors/types';
import { BaseKernelError } from './types';

export class JupyterKernelDependencyError extends BaseKernelError {
constructor(
2 changes: 1 addition & 1 deletion src/kernels/errors/jupyterWaitForIdleError.ts
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@
import { DataScience } from '../../platform/common/utils/localize';
import { sendTelemetryEvent, Telemetry } from '../../telemetry';
import { KernelConnectionMetadata } from '../types';
import { BaseKernelError } from '../../platform/errors/types';
import { BaseKernelError } from './types';

export class JupyterWaitForIdleError extends BaseKernelError {
constructor(kernelConnectionMetadata: KernelConnectionMetadata) {
2 changes: 1 addition & 1 deletion src/kernels/errors/kernelConnectionTimeoutError.ts
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@
import { DataScience } from '../../platform/common/utils/localize';
import { getDisplayNameOrNameOfKernelConnection } from '../helpers';
import { KernelConnectionMetadata } from '../types';
import { BaseKernelError } from '../../platform/errors/types';
import { BaseKernelError } from './types';

export class KernelConnectionTimeoutError extends BaseKernelError {
constructor(kernelConnection: KernelConnectionMetadata) {
2 changes: 1 addition & 1 deletion src/kernels/errors/kernelDeadError.ts
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@
import { DataScience } from '../../platform/common/utils/localize';
import { getDisplayNameOrNameOfKernelConnection } from '../helpers';
import { KernelConnectionMetadata } from '../types';
import { WrappedKernelError } from '../../platform/errors/types';
import { WrappedKernelError } from './types';

export class KernelDeadError extends WrappedKernelError {
constructor(kernelConnectionMetadata: KernelConnectionMetadata) {
2 changes: 1 addition & 1 deletion src/kernels/errors/kernelDiedError.ts
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@
// Licensed under the MIT License.

import { KernelConnectionMetadata } from '../types';
import { WrappedKernelError } from '../../platform/errors/types';
import { WrappedKernelError } from './types';

export class KernelDiedError extends WrappedKernelError {
constructor(
9 changes: 2 additions & 7 deletions src/kernels/errors/kernelErrorHandler.ts
Original file line number Diff line number Diff line change
@@ -38,13 +38,7 @@ import {
} from '../../platform/errors/errorUtils';
import { JupyterConnectError } from '../../platform/errors/jupyterConnectError';
import { JupyterKernelDependencyError } from './jupyterKernelDependencyError';
import {
WrappedError,
BaseKernelError,
WrappedKernelError,
BaseError,
IDataScienceErrorHandler
} from '../../platform/errors/types';
import { WrappedError, BaseError } from '../../platform/errors/types';
import { noop } from '../../platform/common/utils/misc';
import { EnvironmentType } from '../../platform/pythonEnvironments/info';
import { KernelDeadError } from './kernelDeadError';
@@ -62,6 +56,7 @@ import { computeServerId } from '../jupyter/jupyterUtils';
import { RemoteJupyterServerConnectionError } from '../../platform/errors/remoteJupyterServerConnectionError';
import { RemoteJupyterServerUriProviderError } from './remoteJupyterServerUriProviderError';
import { InvalidRemoteJupyterServerUriHandleError } from './invalidRemoteJupyterServerUriHandleError';
import { BaseKernelError, IDataScienceErrorHandler, WrappedKernelError } from './types';

@injectable()
export class DataScienceErrorHandler implements IDataScienceErrorHandler {
2 changes: 1 addition & 1 deletion src/kernels/errors/kernelInterruptTimeoutError.ts
Original file line number Diff line number Diff line change
@@ -3,7 +3,7 @@

import { DataScience } from '../../platform/common/utils/localize';
import { KernelConnectionMetadata } from '../types';
import { BaseKernelError } from '../../platform/errors/types';
import { BaseKernelError } from './types';

export class KernelInterruptTimeoutError extends BaseKernelError {
constructor(kernelConnection: KernelConnectionMetadata) {
2 changes: 1 addition & 1 deletion src/kernels/errors/kernelPortNotUsedTimeoutError.ts
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@
import { DataScience } from '../../platform/common/utils/localize';
import { getDisplayNameOrNameOfKernelConnection } from '../helpers';
import { KernelConnectionMetadata } from '../types';
import { BaseKernelError } from '../../platform/errors/types';
import { BaseKernelError } from './types';

export class KernelPortNotUsedTimeoutError extends BaseKernelError {
constructor(kernelConnection: KernelConnectionMetadata) {
2 changes: 1 addition & 1 deletion src/kernels/errors/kernelProcessExitedError.ts
Original file line number Diff line number Diff line change
@@ -3,7 +3,7 @@

import { KernelConnectionMetadata } from '../types';
import { DataScience } from '../../platform/common/utils/localize';
import { BaseKernelError } from '../../platform/errors/types';
import { BaseKernelError } from './types';

export class KernelProcessExitedError extends BaseKernelError {
constructor(
57 changes: 57 additions & 0 deletions src/kernels/errors/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

import {
KernelAction,
KernelActionSource,
KernelConnectionMetadata,
KernelInterpreterDependencyResponse
} from '../../kernels/types';
import { Resource } from '../../platform/common/types';
import { BaseError, ErrorCategory, WrappedError } from '../../platform/errors/types';

export const IDataScienceErrorHandler = Symbol('IDataScienceErrorHandler');
export interface IDataScienceErrorHandler {
/**
* Handles the errors and if necessary displays an error message.
*/
handleError(err: Error): Promise<void>;
/**
* Handles errors specific to kernels.
* The value of `errorContext` is used to determine the context of the error message, whether it applies to starting or interrupting kernels or the like.
* Thus based on the context the error message would be different.
*/
handleKernelError(
err: Error,
errorContext: KernelAction,
kernelConnection: KernelConnectionMetadata,
resource: Resource,
actionSource: KernelActionSource
): Promise<KernelInterpreterDependencyResponse>;
/**
* The value of `errorContext` is used to determine the context of the error message, whether it applies to starting or interrupting kernels or the like.
* Thus based on the context the error message would be different.
*/
getErrorMessageForDisplayInCell(err: Error, errorContext: KernelAction): Promise<string>;
}

export abstract class BaseKernelError extends BaseError {
public override stdErr?: string;
constructor(
category: ErrorCategory,
message: string,
public readonly kernelConnectionMetadata: KernelConnectionMetadata
) {
super(category, message);
}
}

export class WrappedKernelError extends WrappedError {
constructor(
message: string,
originalException: Error | undefined,
public readonly kernelConnectionMetadata: KernelConnectionMetadata
) {
super(message, originalException);
}
}
2 changes: 1 addition & 1 deletion src/kernels/jupyter/serverSelector.ts
Original file line number Diff line number Diff line change
@@ -24,7 +24,7 @@ import {
IJupyterServerUriStorage,
JupyterServerUriHandle
} from './types';
import { IDataScienceErrorHandler } from '../../platform/errors/types';
import { IDataScienceErrorHandler } from '../errors/types';
import { IConfigurationService, IsWebExtension } from '../../platform/common/types';
import {
handleExpiredCertsError,
2 changes: 1 addition & 1 deletion src/kernels/jupyter/serviceRegistry.node.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
import { IExtensionSingleActivationService, IExtensionSyncActivationService } from '../../platform/activation/types';
import { IDataScienceErrorHandler } from '../../platform/errors/types';
import { IServiceManager } from '../../platform/ioc/types';
import { DataScienceErrorHandler } from '../errors/kernelErrorHandler';
import { IDataScienceErrorHandler } from '../errors/types';
import { IRemoteKernelFinder } from '../raw/types';
import { INotebookProvider } from '../types';
import { JupyterCommandLineSelectorCommand } from './commands/commandLineSelector';
2 changes: 1 addition & 1 deletion src/kernels/jupyter/serviceRegistry.web.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
import { IExtensionSingleActivationService, IExtensionSyncActivationService } from '../../platform/activation/types';
import { IDataScienceErrorHandler } from '../../platform/errors/types';
import { IServiceManager } from '../../platform/ioc/types';
import { DataScienceErrorHandler } from '../errors/kernelErrorHandler';
import { IDataScienceErrorHandler } from '../errors/types';
import { IRemoteKernelFinder } from '../raw/types';
import { INotebookProvider } from '../types';
import { JupyterCommandLineSelectorCommand } from './commands/commandLineSelector';
2 changes: 1 addition & 1 deletion src/notebooks/controllers/kernelConnector.ts
Original file line number Diff line number Diff line change
@@ -27,8 +27,8 @@ import { Product } from '../../kernels/installer/types';
import { INotebookControllerManager, INotebookEditorProvider } from '../types';
import { selectKernel } from './kernelSelector';
import { KernelDeadError } from '../../kernels/errors/kernelDeadError';
import { IDataScienceErrorHandler } from '../../kernels/errors/types';
import { noop } from '../../platform/common/utils/misc';
import { IDataScienceErrorHandler } from '../../platform/errors/types';
import { IStatusProvider } from '../../platform/progress/types';
import { IRawNotebookProvider } from '../../kernels/raw/types';
import { IVSCodeNotebookController } from './types';
3 changes: 2 additions & 1 deletion src/notebooks/controllers/vscodeNotebookController.ts
Original file line number Diff line number Diff line change
@@ -54,7 +54,7 @@ import { IServiceContainer } from '../../platform/ioc/types';
import { EnvironmentType } from '../../platform/pythonEnvironments/info';
import { Commands } from '../../platform/common/constants';
import { Telemetry } from '../../telemetry';
import { IDataScienceErrorHandler, WrappedError } from '../../platform/errors/types';
import { WrappedError } from '../../platform/errors/types';
import { IPyWidgetMessages } from '../../platform/messageTypes';
import {
getKernelConnectionPath,
@@ -94,6 +94,7 @@ import {
import { KernelMessage } from '@jupyterlab/services';
import { initializeInteractiveOrNotebookTelemetryBasedOnUserAction } from '../../kernels/telemetry/helper';
import { NotebookCellLanguageService } from '../languages/cellLanguageService';
import { IDataScienceErrorHandler } from '../../kernels/errors/types';

export class VSCodeNotebookController implements Disposable, IVSCodeNotebookController {
private readonly _onNotebookControllerSelected: EventEmitter<{
2 changes: 1 addition & 1 deletion src/notebooks/notebookCommandListener.ts
Original file line number Diff line number Diff line change
@@ -27,11 +27,11 @@ import { traceInfoIfCI, traceInfo } from '../platform/logging';
import { sendTelemetryEvent, Telemetry } from '../telemetry';
import { trackKernelResourceInformation } from '../kernels/telemetry/helper';
import { INotebookControllerManager, INotebookEditorProvider } from './types';
import { IDataScienceErrorHandler } from '../platform/errors/types';
import { IServiceContainer } from '../platform/ioc/types';
import { endCellAndDisplayErrorsInCell } from '../kernels/execution/helpers';
import { chainWithPendingUpdates } from '../kernels/execution/notebookUpdater';
import { getAssociatedNotebookDocument } from '../kernels/helpers';
import { IDataScienceErrorHandler } from '../kernels/errors/types';
import { getNotebookMetadata } from '../platform/common/utils';
import { KernelConnector } from './controllers/kernelConnector';

2 changes: 1 addition & 1 deletion src/platform/common/utils.ts
Original file line number Diff line number Diff line change
@@ -19,7 +19,7 @@ import { traceError, traceInfo } from '../logging';

import { ICell } from './types';
import { DataScience } from './utils/localize';
import { IJupyterKernelSpec } from '../../webviews/extension-side/api/extension';
import { IJupyterKernelSpec } from '../../kernels/types';

// Can't figure out a better way to do this. Enumerate
// the allowed keys of different output formats.
53 changes: 0 additions & 53 deletions src/platform/errors/types.ts
Original file line number Diff line number Diff line change
@@ -1,32 +1,13 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

import {
KernelAction,
KernelActionSource,
KernelConnectionMetadata,
KernelInterpreterDependencyResponse
} from '../../kernels/types';
import { Resource } from '../common/types';

export abstract class BaseError extends Error {
public stdErr?: string;
constructor(public readonly category: ErrorCategory, message: string) {
super(message);
}
}

export abstract class BaseKernelError extends BaseError {
public override stdErr?: string;
constructor(
category: ErrorCategory,
message: string,
public readonly kernelConnectionMetadata: KernelConnectionMetadata
) {
super(category, message);
}
}

/**
* Wraps an error with a custom error message, retaining the call stack information.
*/
@@ -61,15 +42,6 @@ export class WrappedError extends BaseError {
return err;
}
}
export class WrappedKernelError extends WrappedError {
constructor(
message: string,
originalException: Error | undefined,
public readonly kernelConnectionMetadata: KernelConnectionMetadata
) {
super(message, originalException);
}
}

export function getErrorCategory(error?: Error): ErrorCategory {
if (!error) {
@@ -134,28 +106,3 @@ export type TelemetryErrorProperties = {
*/
pythonErrorPackage?: string;
};

export const IDataScienceErrorHandler = Symbol('IDataScienceErrorHandler');
export interface IDataScienceErrorHandler {
/**
* Handles the errors and if necessary displays an error message.
*/
handleError(err: Error): Promise<void>;
/**
* Handles errors specific to kernels.
* The value of `errorContext` is used to determine the context of the error message, whether it applies to starting or interrupting kernels or the like.
* Thus based on the context the error message would be different.
*/
handleKernelError(
err: Error,
errorContext: KernelAction,
kernelConnection: KernelConnectionMetadata,
resource: Resource,
actionSource: KernelActionSource
): Promise<KernelInterpreterDependencyResponse>;
/**
* The value of `errorContext` is used to determine the context of the error message, whether it applies to starting or interrupting kernels or the like.
* Thus based on the context the error message would be different.
*/
getErrorMessageForDisplayInCell(err: Error, errorContext: KernelAction): Promise<string>;
}
2 changes: 1 addition & 1 deletion src/test/datascience/data-viewing/dataViewer.unit.test.ts
Original file line number Diff line number Diff line change
@@ -16,7 +16,7 @@ import { WorkspaceService } from '../../../platform/common/application/workspace
import { JupyterSettings } from '../../../platform/common/configSettings';
import { ConfigurationService } from '../../../platform/common/configuration/service.node';
import { IConfigurationService, IExtensionContext } from '../../../platform/common/types';
import { IDataScienceErrorHandler } from '../../../platform/errors/types';
import { IDataScienceErrorHandler } from '../../../kernels/errors/types';
import { DataViewer } from '../../../webviews/extension-side/dataviewer/dataViewer';
import { JupyterVariableDataProvider } from '../../../webviews/extension-side/dataviewer/jupyterVariableDataProvider';
import { IDataViewer, IDataViewerDataProvider } from '../../../webviews/extension-side/dataviewer/types';
Original file line number Diff line number Diff line change
@@ -42,10 +42,10 @@ import { InteractiveCellResultError } from '../../../platform/errors/interactive
import { ICodeWatcher, IGeneratedCodeStorageFactory } from '../../../interactive-window/editor-integration/types';
import { IInteractiveWindowProvider, IInteractiveWindow } from '../../../interactive-window/types';
import { Commands, EditorContexts } from '../../../platform/common/constants';
import { IDataScienceErrorHandler } from '../../../platform/errors/types';
import { SystemVariables } from '../../../platform/common/variables/systemVariables.node';
import { IDebugLocationTracker } from '../../../kernels/debugger/types';
import { noop } from '../../core';
import { IDataScienceErrorHandler } from '../../../kernels/errors/types';

/* eslint-disable @typescript-eslint/no-explicit-any */

Loading