From a76e7ef13e751a1b94ed171ae9a1775c7660d257 Mon Sep 17 00:00:00 2001 From: Eleanor Boyd Date: Tue, 17 Dec 2024 13:34:38 -0800 Subject: [PATCH] remove console. in production code (#24629) closes https://github.com/microsoft/vscode-python/issues/9721 --------- Co-authored-by: Daniel Imms <2193314+Tyriar@users.noreply.github.com> --- src/client/browser/extension.ts | 4 ++-- src/client/common/process/worker/workerRawProcessApis.ts | 3 ++- src/client/common/utils/resourceLifecycle.ts | 5 +++-- src/client/deprecatedProposedApi.ts | 4 ++-- src/client/repl/pythonServer.ts | 2 +- src/client/telemetry/index.ts | 4 ++-- src/client/testing/testController/common/utils.ts | 4 ++-- .../testing/testController/pytest/pytestExecutionAdapter.ts | 3 --- 8 files changed, 14 insertions(+), 15 deletions(-) diff --git a/src/client/browser/extension.ts b/src/client/browser/extension.ts index 35854d141cad..132618430551 100644 --- a/src/client/browser/extension.ts +++ b/src/client/browser/extension.ts @@ -139,7 +139,7 @@ async function runPylance( await client.start(); } catch (e) { - console.log(e); + console.log(e); // necessary to use console.log for browser } } @@ -200,7 +200,7 @@ function sendTelemetryEventBrowser( break; } } catch (exception) { - console.error(`Failed to serialize ${prop} for ${eventName}`, exception); + console.error(`Failed to serialize ${prop} for ${eventName}`, exception); // necessary to use console.log for browser } }); } diff --git a/src/client/common/process/worker/workerRawProcessApis.ts b/src/client/common/process/worker/workerRawProcessApis.ts index 5b04aaa40b0a..cfae9b1e6471 100644 --- a/src/client/common/process/worker/workerRawProcessApis.ts +++ b/src/client/common/process/worker/workerRawProcessApis.ts @@ -17,6 +17,7 @@ import { StdErrError, ExecutionResult, } from './types'; +import { traceWarn } from '../../../logging'; const PS_ERROR_SCREEN_BOGUS = /your [0-9]+x[0-9]+ screen size is bogus\. expect trouble/; @@ -208,6 +209,6 @@ function killPid(pid: number): void { process.kill(pid); } } catch { - console.warn('Unable to kill process with pid', pid); + traceWarn('Unable to kill process with pid', pid); } } diff --git a/src/client/common/utils/resourceLifecycle.ts b/src/client/common/utils/resourceLifecycle.ts index f41efebc12cb..b5d1a9a1c83a 100644 --- a/src/client/common/utils/resourceLifecycle.ts +++ b/src/client/common/utils/resourceLifecycle.ts @@ -2,6 +2,7 @@ // Licensed under the MIT License. // eslint-disable-next-line max-classes-per-file +import { traceWarn } from '../../logging'; import { IDisposable } from '../types'; import { Iterable } from './iterable'; @@ -32,7 +33,7 @@ export function dispose(arg: T | Iterable | undefined) try { d.dispose(); } catch (e) { - console.warn(`dispose() failed for ${d}`, e); + traceWarn(`dispose() failed for ${d}`, e); } } } @@ -149,7 +150,7 @@ export class DisposableStore implements IDisposable { if (this._isDisposed) { if (!DisposableStore.DISABLE_DISPOSED_WARNING) { - console.warn( + traceWarn( new Error( 'Trying to add a disposable to a DisposableStore that has already been disposed of. The added object will be leaked!', ).stack, diff --git a/src/client/deprecatedProposedApi.ts b/src/client/deprecatedProposedApi.ts index e63670e4bf1b..d0003c895517 100644 --- a/src/client/deprecatedProposedApi.ts +++ b/src/client/deprecatedProposedApi.ts @@ -13,7 +13,7 @@ import { } from './deprecatedProposedApiTypes'; import { IInterpreterService } from './interpreter/contracts'; import { IServiceContainer } from './ioc/types'; -import { traceVerbose } from './logging'; +import { traceVerbose, traceWarn } from './logging'; import { PythonEnvInfo } from './pythonEnvironments/base/info'; import { getEnvPath } from './pythonEnvironments/base/info/env'; import { GetRefreshEnvironmentsOptions, IDiscoveryAPI } from './pythonEnvironments/base/locator'; @@ -74,7 +74,7 @@ export function buildDeprecatedProposedApi( }); traceVerbose(`Extension ${info.extensionId} accessed ${apiName}`); if (warnLog && !warningLogged.has(info.extensionId)) { - console.warn( + traceWarn( `${info.extensionId} extension is using deprecated python APIs which will be removed soon.`, ); warningLogged.add(info.extensionId); diff --git a/src/client/repl/pythonServer.ts b/src/client/repl/pythonServer.ts index 0f500f0431bc..570433714f98 100644 --- a/src/client/repl/pythonServer.ts +++ b/src/client/repl/pythonServer.ts @@ -38,7 +38,7 @@ class PythonServerImpl implements PythonServer, Disposable { private initialize(): void { this.disposables.push( this.connection.onNotification('log', (message: string) => { - console.log('Log:', message); + traceLog('Log:', message); }), ); this.connection.listen(); diff --git a/src/client/telemetry/index.ts b/src/client/telemetry/index.ts index 357f6e60768a..ba7e60bd6763 100644 --- a/src/client/telemetry/index.ts +++ b/src/client/telemetry/index.ts @@ -136,7 +136,7 @@ export function sendTelemetryEvent

{ - console.log(`Test Result named pipe ${pipeName} cancelled`); + traceLog(`Test Result named pipe ${pipeName} cancelled`); disposable.dispose(); }), ); @@ -345,7 +345,7 @@ export async function hasSymlinkParent(currentPath: string): Promise { // Recurse up the directory tree return await hasSymlinkParent(parentDirectory); } catch (error) { - console.error('Error checking symlinks:', error); + traceError('Error checking symlinks:', error); return false; } } diff --git a/src/client/testing/testController/pytest/pytestExecutionAdapter.ts b/src/client/testing/testController/pytest/pytestExecutionAdapter.ts index 6413baf8baee..b408280a576e 100644 --- a/src/client/testing/testController/pytest/pytestExecutionAdapter.ts +++ b/src/client/testing/testController/pytest/pytestExecutionAdapter.ts @@ -283,9 +283,6 @@ export class PytestTestExecutionAdapter implements ITestExecutionAdapter { runInstance, ); } - // this doesn't work, it instead directs us to the noop one which is defined first - // potentially this is due to the server already being close, if this is the case? - console.log('right before serverDispose'); } // deferredTillEOT is resolved when all data sent on stdout and stderr is received, close event is only called when this occurs