Skip to content

Commit e044a04

Browse files
author
Kartik Raj
authored
Do not fail interpreter discovery if accessing Windows registry fails. (#13369)
* Do not fail discovery if accessing Windows registry fails * News entry
1 parent e18d09b commit e044a04

File tree

3 files changed

+18
-3
lines changed

3 files changed

+18
-3
lines changed

news/2 Fixes/12962.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Do not fail interpreter discovery if accessing Windows registry fails.

src/client/common/platform/registry.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { injectable } from 'inversify';
22
import { Options } from 'winreg';
3+
import { traceError } from '../logger';
34
import { Architecture } from '../utils/platform';
45
import { IRegistry, RegistryHive } from './types';
56

@@ -11,10 +12,18 @@ enum RegistryArchitectures {
1112
@injectable()
1213
export class RegistryImplementation implements IRegistry {
1314
public async getKeys(key: string, hive: RegistryHive, arch?: Architecture) {
14-
return getRegistryKeys({ hive: translateHive(hive)!, arch: translateArchitecture(arch), key });
15+
return getRegistryKeys({ hive: translateHive(hive)!, arch: translateArchitecture(arch), key }).catch((ex) => {
16+
traceError('Fetching keys from windows registry resulted in an error', ex);
17+
return [];
18+
});
1519
}
1620
public async getValue(key: string, hive: RegistryHive, arch?: Architecture, name: string = '') {
17-
return getRegistryValue({ hive: translateHive(hive)!, arch: translateArchitecture(arch), key }, name);
21+
return getRegistryValue({ hive: translateHive(hive)!, arch: translateArchitecture(arch), key }, name).catch(
22+
(ex) => {
23+
traceError('Fetching key value from windows registry resulted in an error', ex);
24+
return undefined;
25+
}
26+
);
1827
}
1928
}
2029

src/client/pythonEnvironments/discovery/locators/services/windowsRegistryService.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,12 @@ export class WindowsRegistryService extends CacheableLocatorService {
4747
// tslint:disable-next-line:no-empty
4848
public dispose() {}
4949
protected async getInterpretersImplementation(_resource?: Uri): Promise<PythonInterpreter[]> {
50-
return this.platform.isWindows ? this.getInterpretersFromRegistry() : [];
50+
return this.platform.isWindows
51+
? this.getInterpretersFromRegistry().catch((ex) => {
52+
traceError('Fetching interpreters from registry failed with error', ex);
53+
return [];
54+
})
55+
: [];
5156
}
5257
private async getInterpretersFromRegistry() {
5358
// https://github.com/python/peps/blob/master/pep-0514.txt#L357

0 commit comments

Comments
 (0)