Skip to content

Commit 4ee198d

Browse files
committed
Add logging for improved diagnostics (#3678)
1 parent fca6cee commit 4ee198d

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

news/3 Code Health/3460.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add logging for improved diagnostics.

src/client/common/process/pythonProcess.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { IServiceContainer } from '../../ioc/types';
77
import { EXTENSION_ROOT_DIR } from '../constants';
88
import { ErrorUtils } from '../errors/errorUtils';
99
import { ModuleNotInstalledError } from '../errors/moduleNotInstalledError';
10+
import { traceError } from '../logger';
1011
import { IFileSystem } from '../platform/types';
1112
import { Architecture } from '../utils/platform';
1213
import { ExecutionResult, InterpreterInfomation, IProcessService, IPythonExecutionService, ObservableExecutionResult, PythonVersionInfo, SpawnOptions } from './types';
@@ -33,7 +34,13 @@ export class PythonExecutionService implements IPythonExecutionService {
3334
.then(output => output.stdout.trim())
3435
]);
3536

36-
const json = JSON.parse(jsonValue) as { versionInfo: PythonVersionInfo; sysPrefix: string; sysVersion: string; is64Bit: boolean };
37+
let json: { versionInfo: PythonVersionInfo; sysPrefix: string; sysVersion: string; is64Bit: boolean };
38+
try {
39+
json = JSON.parse(jsonValue);
40+
} catch (ex) {
41+
traceError(`Failed to parse interpreter information for '${this.pythonPath}' with JSON ${jsonValue}`, ex);
42+
return;
43+
}
3744
const version_info = json.versionInfo;
3845
// Exclude PII from `version_info` to ensure we don't send this up via telemetry.
3946
for (let index = 0; index < 3; index += 1) {
@@ -53,7 +60,7 @@ export class PythonExecutionService implements IPythonExecutionService {
5360
sysPrefix: json.sysPrefix
5461
};
5562
} catch (ex) {
56-
console.error(`Failed to get interpreter information for '${this.pythonPath}'`, ex);
63+
traceError(`Failed to get interpreter information for '${this.pythonPath}'`, ex);
5764
}
5865
}
5966
public async getExecutablePath(): Promise<string> {

0 commit comments

Comments
 (0)