Skip to content

Commit e5412bc

Browse files
author
Kartik Raj
authored
Add more logging when resolving environments (#20165)
For microsoft#20147
1 parent 0e633ed commit e5412bc

File tree

7 files changed

+21
-14
lines changed

7 files changed

+21
-14
lines changed

src/client/common/process/internal/scripts/index.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,18 +43,16 @@ export type InterpreterInfoJson = {
4343

4444
export const OUTPUT_MARKER_SCRIPT = path.join(_SCRIPTS_DIR, 'get_output_via_markers.py');
4545

46-
export function interpreterInfo(): [string[], (out: string) => InterpreterInfoJson | undefined] {
46+
export function interpreterInfo(): [string[], (out: string) => InterpreterInfoJson] {
4747
const script = path.join(SCRIPTS_DIR, 'interpreterInfo.py');
4848
const args = [script];
4949

50-
function parse(out: string): InterpreterInfoJson | undefined {
51-
let json: InterpreterInfoJson | undefined;
50+
function parse(out: string): InterpreterInfoJson {
5251
try {
53-
json = JSON.parse(out);
52+
return JSON.parse(out);
5453
} catch (ex) {
5554
throw Error(`python ${args} returned bad JSON (${out}) (${ex})`);
5655
}
57-
return json;
5856
}
5957

6058
return [args, parse];

src/client/proposedApi.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,15 +124,15 @@ export function buildProposedApi(
124124
const disposables = serviceContainer.get<IDisposableRegistry>(IDisposableRegistry);
125125
const extensions = serviceContainer.get<IExtensions>(IExtensions);
126126
const envVarsProvider = serviceContainer.get<IEnvironmentVariablesProvider>(IEnvironmentVariablesProvider);
127-
function sendApiTelemetry(apiName: string) {
127+
function sendApiTelemetry(apiName: string, args?: unknown) {
128128
extensions
129129
.determineExtensionFromCallStack()
130130
.then((info) => {
131131
sendTelemetryEvent(EventName.PYTHON_ENVIRONMENTS_API, undefined, {
132132
apiName,
133133
extensionId: info.extensionId,
134134
});
135-
traceVerbose(`Extension ${info.extensionId} accessed ${apiName}`);
135+
traceVerbose(`Extension ${info.extensionId} accessed ${apiName} with args: ${JSON.stringify(args)}`);
136136
})
137137
.ignoreErrors();
138138
}
@@ -247,7 +247,7 @@ export function buildProposedApi(
247247
}
248248
path = fullyQualifiedPath;
249249
}
250-
sendApiTelemetry('resolveEnvironment');
250+
sendApiTelemetry('resolveEnvironment', env);
251251
return resolveEnvironment(path, discoveryApi);
252252
},
253253
get known(): Environment[] {

src/client/pythonEnvironments/base/info/interpreter.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,13 +89,16 @@ export async function getInterpreterInfo(
8989
const result = await shellExecute(quoted, { timeout: timeout ?? 15000 });
9090
if (result.stderr) {
9191
traceError(
92-
`Stderr when executing script with ${argv} stderr: ${result.stderr}, still attempting to parse output`,
92+
`Stderr when executing script with >> ${quoted} << stderr: ${result.stderr}, still attempting to parse output`,
9393
);
9494
}
95-
const json = parse(result.stdout);
96-
if (!json) {
95+
let json: InterpreterInfoJson;
96+
try {
97+
json = parse(result.stdout);
98+
} catch (ex) {
99+
traceError(`Failed to parse interpreter information for >> ${quoted} << with ${ex}`);
97100
return undefined;
98101
}
99-
traceInfo(`Found interpreter for ${argv}`);
102+
traceInfo(`Found interpreter for >> ${quoted} <<: ${JSON.stringify(json)}`);
100103
return extractInterpreterInfo(python.pythonExecutable, json);
101104
}

src/client/pythonEnvironments/base/locators/composite/envsCollectionCache.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ export class PythonEnvInfoCache extends PythonEnvsWatcher<PythonEnvCollectionCha
211211

212212
async function validateInfo(env: PythonEnvInfo) {
213213
const { ctime, mtime } = await getFileInfo(env.executable.filename);
214-
if (ctime === env.executable.ctime && mtime === env.executable.mtime) {
214+
if (ctime !== -1 && mtime !== -1 && ctime === env.executable.ctime && mtime === env.executable.mtime) {
215215
return true;
216216
}
217217
env.executable.ctime = ctime;

src/client/pythonEnvironments/base/locators/composite/envsCollectionService.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { Event, EventEmitter } from 'vscode';
55
import '../../../../common/extensions';
66
import { createDeferred, Deferred } from '../../../../common/utils/async';
77
import { StopWatch } from '../../../../common/utils/stopWatch';
8-
import { traceError } from '../../../../logging';
8+
import { traceError, traceVerbose } from '../../../../logging';
99
import { sendTelemetryEvent } from '../../../../telemetry';
1010
import { EventName } from '../../../../telemetry/constants';
1111
import { normalizePath } from '../../../common/externalDependencies';
@@ -94,6 +94,7 @@ export class EnvsCollectionService extends PythonEnvsWatcher<PythonEnvCollection
9494
traceError(`Failed to resolve ${path}`, ex);
9595
return undefined;
9696
});
97+
traceVerbose(`Resolved ${path} to ${JSON.stringify(resolved)}`);
9798
if (resolved) {
9899
this.cache.addEnv(resolved, true);
99100
}

src/client/pythonEnvironments/base/locators/composite/envsResolver.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ export class PythonEnvsResolver implements IResolvingLocator {
5252
const kind = await identifyEnvironment(path);
5353
const environment = await resolveBasicEnv({ kind, executablePath, envPath });
5454
const info = await this.environmentInfoService.getEnvironmentInfo(environment);
55+
traceVerbose(
56+
`Environment resolver resolved ${path} for ${JSON.stringify(environment)} to ${JSON.stringify(info)}`,
57+
);
5558
if (!info) {
5659
return undefined;
5760
}

src/client/pythonEnvironments/common/externalDependencies.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { IDisposable, IConfigurationService } from '../../common/types';
1010
import { chain, iterable } from '../../common/utils/async';
1111
import { getOSType, OSType } from '../../common/utils/platform';
1212
import { IServiceContainer } from '../../ioc/types';
13+
import { traceError } from '../../logging';
1314

1415
let internalServiceContainer: IServiceContainer;
1516
export function initializeExternalDependencies(serviceContainer: IServiceContainer): void {
@@ -116,6 +117,7 @@ export async function getFileInfo(filePath: string): Promise<{ ctime: number; mt
116117
} catch (ex) {
117118
// This can fail on some cases, such as, `reparse points` on windows. So, return the
118119
// time as -1. Which we treat as not set in the extension.
120+
traceError(`Failed to get file info for ${filePath}`, ex);
119121
return { ctime: -1, mtime: -1 };
120122
}
121123
}

0 commit comments

Comments
 (0)