-
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
Conversation
Kudos, SonarCloud Quality Gate passed!
|
Codecov Report
@@ Coverage Diff @@
## master #13369 +/- ##
==========================================
- Coverage 59.75% 59.68% -0.07%
==========================================
Files 670 670
Lines 37303 37347 +44
Branches 5296 5306 +10
==========================================
+ Hits 22290 22291 +1
- Misses 13878 13919 +41
- Partials 1135 1137 +2
Continue to review full report at Codecov.
|
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 []; |
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.
return resolve([]); |
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
async function getRegistryKeys(options: Options): Promise<string[]> { | |
// tslint:disable-next-line:no-require-imports | |
const Registry = require('winreg') as typeof import('winreg'); | |
// https://github.com/python/peps/blob/master/pep-0514.txt#L85 | |
return new Promise<string[]>((resolve) => { | |
new Registry(options).keys((error, result) => { | |
if (error || !Array.isArray(result)) { | |
return resolve([]); | |
} | |
resolve(result.filter((item) => typeof item.key === 'string').map((item) => item.key)); | |
}); | |
}); | |
} |
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,
console.ts:137 [Extension Host] Error Python Extension: 2020-07-15 14:50:32: Get Interpreters, Class name = m, completed in 9ms, has a falsy return value, Arg 1: <Uri:c:\Users\chmay\source\mkl\mkl_email_service>, Arg 2: {"onSuggestion":true}, Return Value: undefined Error: spawn EPERM
at ChildProcess.spawn (internal/child_process.js:394:11)
at spawn (child_process.js:553:9)
at y.keys (c:\Users\chmay\.vscode\extensions\ms-python.python-2020.6.91350\out\client\extension.js:1:621980)
at c:\Users\chmay\.vscode\extensions\ms-python.python-2020.6.91350\out\client\extension.js:1:617508
at new Promise (<anonymous>)
at c:\Users\chmay\.vscode\extensions\ms-python.python-2020.6.91350\out\client\extension.js:1:617483
at c.getKeys (c:\Users\chmay\.vscode\extensions\ms-python.python-2020.6.91350\out\client\extension.js:1:617615)
at b.getCompanies (c:\Users\chmay\.vscode\extensions\ms-python.python-2020.6.91350\out\client\extension.js:48:796340)
at b.getInterpretersFromRegistry (c:\Users\chmay\.vscode\extensions\ms-python.python-2020.6.91350\out\client\extension.js:48:795831)
It fails at y.keys
in the extension code, which is new 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.
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 comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above.
@@ -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 comment
The 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.
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.
LGTM
This feels more like a bandaid than a full fix, but I understand the constraints here.
For #12962
package-lock.json
has been regenerated by runningnpm install
(if dependencies have changed).