forked from DonJayamanne/pythonVSCode
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Do not fail interpreter discovery if accessing Windows registry fails. #13369
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Do not fail interpreter discovery if accessing Windows registry fails. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above. |
||
} | ||
); | ||
} | ||
} | ||
|
||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -47,7 +47,12 @@ export class WindowsRegistryService extends CacheableLocatorService { | |
// tslint:disable-next-line:no-empty | ||
public dispose() {} | ||
protected async getInterpretersImplementation(_resource?: Uri): Promise<PythonInterpreter[]> { | ||
return this.platform.isWindows ? this.getInterpretersFromRegistry() : []; | ||
return this.platform.isWindows | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have put this just to make sure we fix the bug. We should probably have done this with all locators. |
||
? 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 | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Look at the
getRegistryKeys
implementation. We already return empty array. I don't think we will hit this case.vscode-python/src/client/common/platform/registry.ts
Line 52 in 61b179b
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
vscode-python/src/client/common/platform/registry.ts
Lines 54 to 66 in 776a5ad
I think you're assuming that
new Registry(options).keys
at line 59 does not throw any errors and respects the callback. I checked the error trace user uploaded,It fails at
y.keys
in the extension code, which isnew Registry(options).keys
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see. Go it.