From 8abfea62dfe6d47d05053a68ea79d472006182c0 Mon Sep 17 00:00:00 2001 From: Don Jayamanne Date: Thu, 13 Dec 2018 08:07:15 -0800 Subject: [PATCH] Add logging for improved diagnostics --- news/3 Code Health/3460.md | 1 + src/client/common/process/pythonProcess.ts | 11 +++++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) create mode 100644 news/3 Code Health/3460.md diff --git a/news/3 Code Health/3460.md b/news/3 Code Health/3460.md new file mode 100644 index 000000000000..13f0756912ff --- /dev/null +++ b/news/3 Code Health/3460.md @@ -0,0 +1 @@ +Add logging for improved diagnostics. diff --git a/src/client/common/process/pythonProcess.ts b/src/client/common/process/pythonProcess.ts index 0211434fb12a..6c57965ceeef 100644 --- a/src/client/common/process/pythonProcess.ts +++ b/src/client/common/process/pythonProcess.ts @@ -7,6 +7,7 @@ import { IServiceContainer } from '../../ioc/types'; import { EXTENSION_ROOT_DIR } from '../constants'; import { ErrorUtils } from '../errors/errorUtils'; import { ModuleNotInstalledError } from '../errors/moduleNotInstalledError'; +import { traceError } from '../logger'; import { IFileSystem } from '../platform/types'; import { Architecture } from '../utils/platform'; import { ExecutionResult, InterpreterInfomation, IProcessService, IPythonExecutionService, ObservableExecutionResult, PythonVersionInfo, SpawnOptions } from './types'; @@ -33,7 +34,13 @@ export class PythonExecutionService implements IPythonExecutionService { .then(output => output.stdout.trim()) ]); - const json = JSON.parse(jsonValue) as { versionInfo: PythonVersionInfo; sysPrefix: string; sysVersion: string; is64Bit: boolean }; + let json: { versionInfo: PythonVersionInfo; sysPrefix: string; sysVersion: string; is64Bit: boolean }; + try { + json = JSON.parse(jsonValue); + } catch (ex) { + traceError(`Failed to parse interpreter information for '${this.pythonPath}' with JSON ${jsonValue}`, ex); + return; + } const version_info = json.versionInfo; // Exclude PII from `version_info` to ensure we don't send this up via telemetry. for (let index = 0; index < 3; index += 1) { @@ -53,7 +60,7 @@ export class PythonExecutionService implements IPythonExecutionService { sysPrefix: json.sysPrefix }; } catch (ex) { - console.error(`Failed to get interpreter information for '${this.pythonPath}'`, ex); + traceError(`Failed to get interpreter information for '${this.pythonPath}'`, ex); } } public async getExecutablePath(): Promise {