From 708dbfc4f28a7a5ed906028174a7cb849e64afd6 Mon Sep 17 00:00:00 2001 From: Kartik Raj Date: Mon, 10 Aug 2020 08:41:24 -0700 Subject: [PATCH 1/2] Do not fail discovery if accessing Windows registry fails --- src/client/common/platform/registry.ts | 13 +++++++++++-- .../locators/services/windowsRegistryService.ts | 7 ++++++- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/client/common/platform/registry.ts b/src/client/common/platform/registry.ts index 6657d8dd8670..3e920f03c30c 100644 --- a/src/client/common/platform/registry.ts +++ b/src/client/common/platform/registry.ts @@ -1,5 +1,6 @@ import { injectable } from 'inversify'; import { Options } from 'winreg'; +import { traceError } from '../logger'; import { Architecture } from '../utils/platform'; import { IRegistry, RegistryHive } from './types'; @@ -11,10 +12,18 @@ enum RegistryArchitectures { @injectable() export class RegistryImplementation implements IRegistry { public async getKeys(key: string, hive: RegistryHive, arch?: Architecture) { - return getRegistryKeys({ hive: translateHive(hive)!, arch: translateArchitecture(arch), key }); + return getRegistryKeys({ hive: translateHive(hive)!, arch: translateArchitecture(arch), key }).catch((ex) => { + traceError('Fetching keys from windows registry resulted in an error', ex); + return []; + }); } public async getValue(key: string, hive: RegistryHive, arch?: Architecture, name: string = '') { - return getRegistryValue({ hive: translateHive(hive)!, arch: translateArchitecture(arch), key }, name); + return getRegistryValue({ hive: translateHive(hive)!, arch: translateArchitecture(arch), key }, name).catch( + (ex) => { + traceError('Fetching key value from windows registry resulted in an error', ex); + return undefined; + } + ); } } diff --git a/src/client/pythonEnvironments/discovery/locators/services/windowsRegistryService.ts b/src/client/pythonEnvironments/discovery/locators/services/windowsRegistryService.ts index 2c145c12f5d5..6f0c00440f35 100644 --- a/src/client/pythonEnvironments/discovery/locators/services/windowsRegistryService.ts +++ b/src/client/pythonEnvironments/discovery/locators/services/windowsRegistryService.ts @@ -47,7 +47,12 @@ export class WindowsRegistryService extends CacheableLocatorService { // tslint:disable-next-line:no-empty public dispose() {} protected async getInterpretersImplementation(_resource?: Uri): Promise { - return this.platform.isWindows ? this.getInterpretersFromRegistry() : []; + return this.platform.isWindows + ? this.getInterpretersFromRegistry().catch((ex) => { + traceError('Fetching interpreters from registry failed with error', ex); + return []; + }) + : []; } private async getInterpretersFromRegistry() { // https://github.com/python/peps/blob/master/pep-0514.txt#L357 From 776a5adb414fc4fd76a8ca99ae7479bb2402d7f3 Mon Sep 17 00:00:00 2001 From: Kartik Raj Date: Mon, 10 Aug 2020 08:46:12 -0700 Subject: [PATCH 2/2] News entry --- news/2 Fixes/12962.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 news/2 Fixes/12962.md diff --git a/news/2 Fixes/12962.md b/news/2 Fixes/12962.md new file mode 100644 index 000000000000..c94aeff6e07f --- /dev/null +++ b/news/2 Fixes/12962.md @@ -0,0 +1 @@ +Do not fail interpreter discovery if accessing Windows registry fails.