Skip to content

Commit c256678

Browse files
author
Kartik Raj
authored
Prevent posix paths locator from crashing (#21657)
For #21310
1 parent 81ae205 commit c256678

File tree

1 file changed

+18
-14
lines changed

1 file changed

+18
-14
lines changed

src/client/pythonEnvironments/base/locators/lowLevel/posixKnownPathsLocator.ts

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -27,23 +27,27 @@ export class PosixKnownPathsLocator extends Locator<BasicEnvInfo> {
2727

2828
const iterator = async function* (kind: PythonEnvKind) {
2929
traceVerbose('Searching for interpreters in posix paths locator');
30-
// Filter out pyenv shims. They are not actual python binaries, they are used to launch
31-
// the binaries specified in .python-version file in the cwd. We should not be reporting
32-
// those binaries as environments.
33-
const knownDirs = (await commonPosixBinPaths()).filter((dirname) => !isPyenvShimDir(dirname));
34-
let pythonBinaries = await getPythonBinFromPosixPaths(knownDirs);
30+
try {
31+
// Filter out pyenv shims. They are not actual python binaries, they are used to launch
32+
// the binaries specified in .python-version file in the cwd. We should not be reporting
33+
// those binaries as environments.
34+
const knownDirs = (await commonPosixBinPaths()).filter((dirname) => !isPyenvShimDir(dirname));
35+
let pythonBinaries = await getPythonBinFromPosixPaths(knownDirs);
3536

36-
// Filter out MacOS system installs of Python 2 if necessary.
37-
if (isMacPython2Deprecated) {
38-
pythonBinaries = pythonBinaries.filter((binary) => !isMacDefaultPythonPath(binary));
39-
}
37+
// Filter out MacOS system installs of Python 2 if necessary.
38+
if (isMacPython2Deprecated) {
39+
pythonBinaries = pythonBinaries.filter((binary) => !isMacDefaultPythonPath(binary));
40+
}
4041

41-
for (const bin of pythonBinaries) {
42-
try {
43-
yield { executablePath: bin, kind, source: [PythonEnvSource.PathEnvVar] };
44-
} catch (ex) {
45-
traceError(`Failed to process environment: ${bin}`, ex);
42+
for (const bin of pythonBinaries) {
43+
try {
44+
yield { executablePath: bin, kind, source: [PythonEnvSource.PathEnvVar] };
45+
} catch (ex) {
46+
traceError(`Failed to process environment: ${bin}`, ex);
47+
}
4648
}
49+
} catch (ex) {
50+
traceError('Failed to process posix paths', ex);
4751
}
4852
traceVerbose('Finished searching for interpreters in posix paths locator');
4953
};

0 commit comments

Comments
 (0)