Skip to content

Commit a210e47

Browse files
authored
Add verbose logging for environment resolution failures in utils (#1221)
1 parent 265d130 commit a210e47

File tree

3 files changed

+35
-21
lines changed

3 files changed

+35
-21
lines changed

src/managers/builtin/utils.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
} from '../../api';
1111
import { showErrorMessageWithLogs } from '../../common/errors/utils';
1212
import { SysManagerStrings } from '../../common/localize';
13+
import { traceVerbose } from '../../common/logging';
1314
import { withProgress } from '../../common/window.apis';
1415
import {
1516
isNativeEnvInfo,
@@ -299,11 +300,16 @@ export async function resolveSystemPythonEnvironmentPath(
299300
api: PythonEnvironmentApi,
300301
manager: EnvironmentManager,
301302
): Promise<PythonEnvironment | undefined> {
302-
const resolved = await nativeFinder.resolve(fsPath);
303+
try {
304+
const resolved = await nativeFinder.resolve(fsPath);
303305

304-
// This is supposed to handle a python interpreter as long as we know some basic things about it
305-
if (resolved.executable && resolved.version && resolved.prefix) {
306-
const envInfo = getPythonInfo(resolved);
307-
return api.createPythonEnvironmentItem(envInfo, manager);
306+
// This is supposed to handle a python interpreter as long as we know some basic things about it
307+
if (resolved.executable && resolved.version && resolved.prefix) {
308+
const envInfo = getPythonInfo(resolved);
309+
return api.createPythonEnvironmentItem(envInfo, manager);
310+
}
311+
} catch (ex) {
312+
traceVerbose(`Failed to resolve env "${fsPath}": ${ex}`);
308313
}
314+
return undefined;
309315
}

src/managers/builtin/venvUtils.ts

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { l10n, LogOutputChannel, ProgressLocation, QuickPickItem, QuickPickItemK
55
import { EnvironmentManager, PythonEnvironment, PythonEnvironmentApi, PythonEnvironmentInfo } from '../../api';
66
import { ENVS_EXTENSION_ID } from '../../common/constants';
77
import { Common, VenvManagerStrings } from '../../common/localize';
8-
import { traceInfo } from '../../common/logging';
8+
import { traceInfo, traceVerbose } from '../../common/logging';
99
import { getWorkspacePersistentState } from '../../common/persistentState';
1010
import { EventNames } from '../../common/telemetry/constants';
1111
import { sendTelemetryEvent } from '../../common/telemetry/sender';
@@ -581,15 +581,19 @@ export async function resolveVenvPythonEnvironmentPath(
581581
manager: EnvironmentManager,
582582
baseManager: EnvironmentManager,
583583
): Promise<PythonEnvironment | undefined> {
584-
const resolved = await nativeFinder.resolve(fsPath);
585-
586-
if (
587-
resolved.kind === NativePythonEnvironmentKind.venv ||
588-
resolved.kind === NativePythonEnvironmentKind.venvUv ||
589-
resolved.kind === NativePythonEnvironmentKind.uvWorkspace
590-
) {
591-
const envInfo = await getPythonInfo(resolved);
592-
return api.createPythonEnvironmentItem(envInfo, manager);
584+
try {
585+
const resolved = await nativeFinder.resolve(fsPath);
586+
587+
if (
588+
resolved.kind === NativePythonEnvironmentKind.venv ||
589+
resolved.kind === NativePythonEnvironmentKind.venvUv ||
590+
resolved.kind === NativePythonEnvironmentKind.uvWorkspace
591+
) {
592+
const envInfo = await getPythonInfo(resolved);
593+
return api.createPythonEnvironmentItem(envInfo, manager);
594+
}
595+
} catch (ex) {
596+
traceVerbose(`Failed to resolve venv env "${fsPath}": ${ex}`);
593597
}
594598

595599
return resolveSystemPythonEnvironmentPath(fsPath, nativeFinder, api, baseManager);

src/managers/pipenv/pipenvUtils.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {
1212
PythonEnvironmentInfo,
1313
} from '../../api';
1414
import { ENVS_EXTENSION_ID } from '../../common/constants';
15-
import { traceError, traceInfo } from '../../common/logging';
15+
import { traceError, traceInfo, traceVerbose } from '../../common/logging';
1616
import { getWorkspacePersistentState } from '../../common/persistentState';
1717
import { untildify } from '../../common/utils/pathUtils';
1818
import { getSettingWorkspaceScope } from '../../features/settings/settingHelpers';
@@ -222,12 +222,16 @@ export async function resolvePipenvPath(
222222
api: PythonEnvironmentApi,
223223
manager: EnvironmentManager,
224224
): Promise<PythonEnvironment | undefined> {
225-
const resolved = await nativeFinder.resolve(fsPath);
225+
try {
226+
const resolved = await nativeFinder.resolve(fsPath);
226227

227-
// Resolve pipenv environments even if the pipenv CLI is not found.
228-
// This allows proper environment identification for read-only scenarios.
229-
if (resolved.kind === NativePythonEnvironmentKind.pipenv) {
230-
return await nativeToPythonEnv(resolved, api, manager);
228+
// Resolve pipenv environments even if the pipenv CLI is not found.
229+
// This allows proper environment identification for read-only scenarios.
230+
if (resolved.kind === NativePythonEnvironmentKind.pipenv) {
231+
return await nativeToPythonEnv(resolved, api, manager);
232+
}
233+
} catch (ex) {
234+
traceVerbose(`Failed to resolve pipenv env "${fsPath}": ${ex}`);
231235
}
232236

233237
return undefined;

0 commit comments

Comments
 (0)