-
Notifications
You must be signed in to change notification settings - Fork 369
Expand file tree
/
Copy pathkernelErrorHandler.node.ts
More file actions
88 lines (86 loc) · 4.27 KB
/
kernelErrorHandler.node.ts
File metadata and controls
88 lines (86 loc) · 4.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
import { inject, injectable, optional } from 'inversify';
import { Uri } from 'vscode';
import { IConfigurationService, Resource } from '../../platform/common/types';
import { DataScience, Common } from '../../platform/common/utils/localize';
import { IKernelDependencyService } from '../types';
import {
IJupyterInterpreterDependencyManager,
IJupyterServerProviderRegistry,
IJupyterServerUriStorage
} from '../jupyter/types';
import * as path from '../../platform/vscode-path/resources';
import { IReservedPythonNamedProvider } from '../../platform/interpreter/types';
import { JupyterKernelStartFailureOverrideReservedName } from '../../platform/interpreter/constants';
import { DataScienceErrorHandler } from './kernelErrorHandler';
import { getDisplayPath } from '../../platform/common/platform/fs-paths';
import { IFileSystem } from '../../platform/common/platform/types';
import { IInterpreterService } from '../../platform/interpreter/contracts';
/**
* Common code for handling errors. This one is node specific.
*/
@injectable()
export class DataScienceErrorHandlerNode extends DataScienceErrorHandler {
constructor(
@inject(IJupyterInterpreterDependencyManager)
@optional()
dependencyManager: IJupyterInterpreterDependencyManager | undefined,
@inject(IConfigurationService) configuration: IConfigurationService,
@inject(IKernelDependencyService)
@optional()
kernelDependency: IKernelDependencyService | undefined,
@inject(IJupyterServerUriStorage) serverUriStorage: IJupyterServerUriStorage,
@inject(IJupyterServerProviderRegistry) jupyterUriProviderRegistration: IJupyterServerProviderRegistry,
@inject(IReservedPythonNamedProvider) private readonly reservedPythonNames: IReservedPythonNamedProvider,
@inject(IFileSystem) fs: IFileSystem,
@inject(IInterpreterService) interpreterService: IInterpreterService
) {
super(
dependencyManager,
configuration,
kernelDependency,
serverUriStorage,
jupyterUriProviderRegistration,
fs,
interpreterService
);
}
protected override async addErrorMessageIfPythonArePossiblyOverridingPythonModules(
messages: string[],
resource: Resource
) {
// Looks like some other module is missing.
// Sometimes when you create files like xml.py, then kernel startup fails due to xml.dom module not being found.
const problematicFiles =
await this.getFilesInWorkingDirectoryThatCouldPotentiallyOverridePythonModules(resource);
if (problematicFiles.length > 0) {
const cwd = resource ? path.dirname(resource) : undefined;
const fileLinks = problematicFiles.map((item) => {
if (item.type === 'file') {
const displayPath = resource ? getDisplayPath(item.uri, [], cwd) : path.basename(item.uri);
return `<a href='${item.uri.toString()}?line=1'>${displayPath}</a>`;
} else {
const displayPath = resource
? getDisplayPath(item.uri, [], cwd)
: `${path.basename(path.dirname(item.uri))}/__init__.py`;
return `<a href='${item.uri.toString()}?line=1'>${displayPath}</a>`;
}
});
let files = '';
if (fileLinks.length === 1) {
files = fileLinks[0];
} else {
files = `${fileLinks.slice(0, -1).join(', ')} ${Common.and} ${fileLinks.slice(-1)}`;
}
messages.push(DataScience.filesPossiblyOverridingPythonModulesMayHavePreventedKernelFromStarting(files));
messages.push(DataScience.listOfFilesWithLinksThatMightNeedToBeRenamed(files));
messages.push(Common.clickHereForMoreInfoWithHtml(JupyterKernelStartFailureOverrideReservedName));
}
}
protected override async getFilesInWorkingDirectoryThatCouldPotentiallyOverridePythonModules(
resource: Resource
): Promise<{ uri: Uri; type: 'file' | '__init__' }[]> {
return resource ? this.reservedPythonNames.getUriOverridingReservedPythonNames(path.dirname(resource)) : [];
}
}