Skip to content

Commit afa631a

Browse files
committed
fix potential issue
1 parent 9148f5f commit afa631a

File tree

4 files changed

+37
-17
lines changed

4 files changed

+37
-17
lines changed

src/extension.ts

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ import { registerSystemPythonFeatures } from './managers/builtin/main';
9898
import { SysPythonManager } from './managers/builtin/sysPythonManager';
9999
import {
100100
createNativePythonFinder,
101+
isNativeEnvInfo,
101102
NativePythonEnvironmentKind,
102103
NativePythonFinder,
103104
} from './managers/common/nativePythonFinder';
@@ -137,6 +138,18 @@ async function checkPetManagerMismatch(
137138
['poetry', 'ms-python.python:poetry'],
138139
]);
139140

141+
// Use a single cached refresh to avoid triggering per-kind hard refreshes on cache miss
142+
let allEnvs;
143+
try {
144+
allEnvs = await nativeFinder.refresh(false);
145+
} catch {
146+
// PET query failed — don't block post-init
147+
return;
148+
}
149+
150+
// Filter to only environment entries (not manager entries)
151+
const envInfos = allEnvs.filter(isNativeEnvInfo);
152+
140153
// Group PET kinds by manager name to avoid double-counting (e.g. pyenv + pyenvVirtualEnv)
141154
const kindsByManager = new Map<string, NativePythonEnvironmentKind[]>();
142155
for (const [kind, managerName] of PET_KIND_TO_MANAGER) {
@@ -157,16 +170,8 @@ async function checkPetManagerMismatch(
157170
continue;
158171
}
159172

160-
// Manager not registered — check if PET found environments of any related kind
161-
let totalPetEnvs = 0;
162-
for (const kind of kinds) {
163-
try {
164-
const petEnvs = await nativeFinder.refresh(false, kind);
165-
totalPetEnvs += petEnvs.length;
166-
} catch {
167-
// PET query failed — don't block post-init; skip this kind
168-
}
169-
}
173+
// Manager not registered — count PET environments of any related kind
174+
const totalPetEnvs = envInfos.filter((e) => e.kind !== undefined && kinds.includes(e.kind)).length;
170175

171176
if (totalPetEnvs > 0) {
172177
sendTelemetryEvent(EventNames.MANAGER_DISCOVERY_MISMATCH, undefined, {

src/managers/conda/main.ts

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,18 @@ export async function registerCondaFeatures(
2525
// get Conda will return only ONE conda manager, that correlates to a single conda install
2626
condaPath = await getConda(nativeFinder);
2727
} catch (ex) {
28-
traceInfo('Conda not found, turning off conda features.', ex);
29-
sendTelemetryEvent(EventNames.MANAGER_REGISTRATION_SKIPPED, undefined, {
30-
managerName: 'conda',
31-
reason: 'tool_not_found',
32-
});
33-
await notifyMissingManagerIfDefault('ms-python.python:conda', projectManager, api);
34-
return;
28+
// Only treat the known "Conda not found" error as a skip;
29+
// other errors (e.g. PET timeout/crash) should propagate to safeRegister.
30+
if (ex instanceof Error && ex.message === 'Conda not found') {
31+
traceInfo('Conda not found, turning off conda features.', ex);
32+
sendTelemetryEvent(EventNames.MANAGER_REGISTRATION_SKIPPED, undefined, {
33+
managerName: 'conda',
34+
reason: 'tool_not_found',
35+
});
36+
await notifyMissingManagerIfDefault('ms-python.python:conda', projectManager, api);
37+
return;
38+
}
39+
throw ex;
3540
}
3641

3742
// Conda was found — errors below are real registration failures (let safeRegister handle them)

src/managers/pipenv/main.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { Disposable } from 'vscode';
22
import { PythonEnvironmentApi } from '../../api';
33
import { traceInfo } from '../../common/logging';
44
import { EventNames } from '../../common/telemetry/constants';
5+
import { classifyError } from '../../common/telemetry/errorClassifier';
56
import { sendTelemetryEvent } from '../../common/telemetry/sender';
67
import { getPythonApi } from '../../features/pythonApi';
78
import { PythonProjectManager } from '../../internal.api';
@@ -48,6 +49,10 @@ export async function registerPipenvFeatures(
4849
'Pipenv not found, turning off pipenv features. If you have pipenv installed in a non-standard location, set the "python.pipenvPath" setting.',
4950
ex,
5051
);
52+
sendTelemetryEvent(EventNames.MANAGER_REGISTRATION_FAILED, undefined, {
53+
managerName: 'pipenv',
54+
errorType: classifyError(ex),
55+
});
5156
await notifyMissingManagerIfDefault('ms-python.python:pipenv', projectManager, api);
5257
}
5358
}

src/managers/poetry/main.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { Disposable, LogOutputChannel } from 'vscode';
22
import { PythonEnvironmentApi } from '../../api';
33
import { traceInfo } from '../../common/logging';
44
import { EventNames } from '../../common/telemetry/constants';
5+
import { classifyError } from '../../common/telemetry/errorClassifier';
56
import { sendTelemetryEvent } from '../../common/telemetry/sender';
67
import { getPythonApi } from '../../features/pythonApi';
78
import { PythonProjectManager } from '../../internal.api';
@@ -46,6 +47,10 @@ export async function registerPoetryFeatures(
4647
}
4748
} catch (ex) {
4849
traceInfo('Poetry not found, turning off poetry features.', ex);
50+
sendTelemetryEvent(EventNames.MANAGER_REGISTRATION_FAILED, undefined, {
51+
managerName: 'poetry',
52+
errorType: classifyError(ex),
53+
});
4954
await notifyMissingManagerIfDefault('ms-python.python:poetry', projectManager, api);
5055
}
5156
}

0 commit comments

Comments
 (0)