From b40f67b76ae49049e979592a37dd122e1bcd7d71 Mon Sep 17 00:00:00 2001 From: Abhi <43648792+abhipatel12@users.noreply.github.com> Date: Wed, 22 Oct 2025 16:09:10 -0400 Subject: [PATCH] extract console error to util func (#11675) --- packages/a2a-server/src/config/settings.ts | 7 +++-- .../src/ui/components/SettingsDialog.test.tsx | 31 ------------------- packages/cli/src/ui/utils/CodeColorizer.tsx | 3 +- .../cli/src/zed-integration/zedIntegration.ts | 6 ++-- packages/core/src/config/config.ts | 23 ++++---------- packages/core/src/core/client.test.ts | 3 +- packages/core/src/tools/memoryTool.ts | 2 +- packages/core/src/utils/summarizer.test.ts | 4 --- packages/core/src/utils/summarizer.ts | 3 +- 9 files changed, 19 insertions(+), 63 deletions(-) diff --git a/packages/a2a-server/src/config/settings.ts b/packages/a2a-server/src/config/settings.ts index ad7ee213e6..4ecab9e34c 100644 --- a/packages/a2a-server/src/config/settings.ts +++ b/packages/a2a-server/src/config/settings.ts @@ -10,6 +10,7 @@ import { homedir } from 'node:os'; import type { MCPServerConfig } from '@google/gemini-cli-core'; import { + debugLogger, GEMINI_DIR, getErrorMessage, type TelemetrySettings, @@ -97,10 +98,10 @@ export function loadSettings(workspaceDir: string): Settings { } if (settingsErrors.length > 0) { - console.error('Errors loading settings:'); + debugLogger.error('Errors loading settings:'); for (const error of settingsErrors) { - console.error(` Path: ${error.path}`); - console.error(` Message: ${error.message}`); + debugLogger.error(` Path: ${error.path}`); + debugLogger.error(` Message: ${error.message}`); } } diff --git a/packages/cli/src/ui/components/SettingsDialog.test.tsx b/packages/cli/src/ui/components/SettingsDialog.test.tsx index 8a71220c34..24909fcbfd 100644 --- a/packages/cli/src/ui/components/SettingsDialog.test.tsx +++ b/packages/cli/src/ui/components/SettingsDialog.test.tsx @@ -224,37 +224,11 @@ const TOOLS_SHELL_FAKE_SCHEMA: SettingsSchemaType = { }, } as unknown as SettingsSchemaType; -// Helper function to simulate key presses (commented out for now) -// const simulateKeyPress = async (keyData: Partial & { name: string }) => { -// if (currentKeypressHandler) { -// const key: Key = { -// ctrl: false, -// meta: false, -// shift: false, -// paste: false, -// sequence: keyData.sequence || keyData.name, -// ...keyData, -// }; -// currentKeypressHandler(key); -// // Allow React to process the state update -// await new Promise(resolve => setTimeout(resolve, 10)); -// } -// }; - -// Mock console.log to avoid noise in tests -// const originalConsoleLog = console.log; -// const originalConsoleError = console.error; - describe('SettingsDialog', () => { // Simple delay function for remaining tests that need gradual migration const wait = (ms = 50) => new Promise((resolve) => setTimeout(resolve, ms)); beforeEach(() => { - // Reset keypress mock state (variables are commented out) - // currentKeypressHandler = null; - // isKeypressActive = false; - // console.log = vi.fn(); - // console.error = vi.fn(); mockToggleVimEnabled.mockResolvedValue(true); }); @@ -262,11 +236,6 @@ describe('SettingsDialog', () => { TEST_ONLY.clearFlattenedSchema(); vi.clearAllMocks(); vi.resetAllMocks(); - // Reset keypress mock state (variables are commented out) - // currentKeypressHandler = null; - // isKeypressActive = false; - // console.log = originalConsoleLog; - // console.error = originalConsoleError; }); describe('Initial Rendering', () => { diff --git a/packages/cli/src/ui/utils/CodeColorizer.tsx b/packages/cli/src/ui/utils/CodeColorizer.tsx index 021227b89b..00d1c76787 100644 --- a/packages/cli/src/ui/utils/CodeColorizer.tsx +++ b/packages/cli/src/ui/utils/CodeColorizer.tsx @@ -21,6 +21,7 @@ import { MINIMUM_MAX_HEIGHT, } from '../components/shared/MaxSizedBox.js'; import type { LoadedSettings } from '../../config/settings.js'; +import { debugLogger } from '@google/gemini-cli-core'; // Configure theming and parsing utilities. const lowlight = createLowlight(common); @@ -191,7 +192,7 @@ export function colorizeCode( ); } catch (error) { - console.error( + debugLogger.warn( `[colorizeCode] Error highlighting code for language "${language}":`, error, ); diff --git a/packages/cli/src/zed-integration/zedIntegration.ts b/packages/cli/src/zed-integration/zedIntegration.ts index d56b805044..29739850ae 100644 --- a/packages/cli/src/zed-integration/zedIntegration.ts +++ b/packages/cli/src/zed-integration/zedIntegration.ts @@ -158,7 +158,7 @@ class GeminiAgent { ); isAuthenticated = true; } catch (e) { - console.error(`Authentication failed: ${e}`); + debugLogger.error(`Authentication failed: ${e}`); } } @@ -660,7 +660,7 @@ class Session { ); } } catch (globError) { - console.error( + debugLogger.error( `Error during glob search for ${pathName}: ${getErrorMessage(globError)}`, ); } @@ -670,7 +670,7 @@ class Session { ); } } else { - console.error( + debugLogger.error( `Error stating path ${pathName}. Path ${pathName} will be skipped.`, ); } diff --git a/packages/core/src/config/config.ts b/packages/core/src/config/config.ts index e6e859ee00..b7d1fa7add 100644 --- a/packages/core/src/config/config.ts +++ b/packages/core/src/config/config.ts @@ -1199,24 +1199,13 @@ export class Config { !allowedTools || allowedTools.includes(definition.name); if (isAllowed && !isExcluded) { - try { - const messageBusEnabled = this.getEnableMessageBusIntegration(); - const wrapper = new SubagentToolWrapper( - definition, - this, - messageBusEnabled ? this.getMessageBus() : undefined, - ); - registry.registerTool(wrapper); - } catch (error) { - console.error( - `Failed to wrap agent '${definition.name}' as a tool:`, - error, - ); - } - } else if (this.getDebugMode()) { - debugLogger.log( - `[Config] Skipping registration of agent '${definition.name}' due to allow/exclude configuration.`, + const messageBusEnabled = this.getEnableMessageBusIntegration(); + const wrapper = new SubagentToolWrapper( + definition, + this, + messageBusEnabled ? this.getMessageBus() : undefined, ); + registry.registerTool(wrapper); } } } diff --git a/packages/core/src/core/client.test.ts b/packages/core/src/core/client.test.ts index b70266d138..c273ff00d7 100644 --- a/packages/core/src/core/client.test.ts +++ b/packages/core/src/core/client.test.ts @@ -1502,9 +1502,8 @@ ${JSON.stringify( break; } } - } catch (error) { + } catch (_) { // If the test framework times out, that also demonstrates the infinite loop - console.error('Test timed out or errored:', error); } // Assert that the fix works - the loop should stop at MAX_TURNS diff --git a/packages/core/src/tools/memoryTool.ts b/packages/core/src/tools/memoryTool.ts index 38d1362d54..05b6c886d8 100644 --- a/packages/core/src/tools/memoryTool.ts +++ b/packages/core/src/tools/memoryTool.ts @@ -267,7 +267,7 @@ class MemoryToolInvocation extends BaseToolInvocation< } catch (error) { const errorMessage = error instanceof Error ? error.message : String(error); - console.error( + console.warn( `[MemoryTool] Error executing save_memory for fact "${fact}": ${errorMessage}`, ); return { diff --git a/packages/core/src/utils/summarizer.test.ts b/packages/core/src/utils/summarizer.test.ts index 33fa9bc029..edc3860a0a 100644 --- a/packages/core/src/utils/summarizer.test.ts +++ b/packages/core/src/utils/summarizer.test.ts @@ -107,10 +107,6 @@ describe('summarizers', () => { expect(mockGeminiClient.generateContent).toHaveBeenCalledTimes(1); expect(result).toBe(longText); - expect(console.error).toHaveBeenCalledWith( - 'Failed to summarize tool output.', - error, - ); }); it('should construct the correct prompt for summarization', async () => { diff --git a/packages/core/src/utils/summarizer.ts b/packages/core/src/utils/summarizer.ts index 14076b5c2d..f112013fce 100644 --- a/packages/core/src/utils/summarizer.ts +++ b/packages/core/src/utils/summarizer.ts @@ -13,6 +13,7 @@ import type { import type { GeminiClient } from '../core/client.js'; import { DEFAULT_GEMINI_FLASH_LITE_MODEL } from '../config/models.js'; import { getResponseText, partToString } from './partUtils.js'; +import { debugLogger } from './debugLogger.js'; /** * A function that summarizes the result of a tool execution. @@ -90,7 +91,7 @@ export async function summarizeToolOutput( )) as unknown as GenerateContentResponse; return getResponseText(parsedResponse) || textToSummarize; } catch (error) { - console.error('Failed to summarize tool output.', error); + debugLogger.warn('Failed to summarize tool output.', error); return textToSummarize; } }