From b31b786db7aa43b8f0ba440eb8abe1f36aa14d04 Mon Sep 17 00:00:00 2001 From: Gal Zahavi <38544478+galz10@users.noreply.github.com> Date: Wed, 29 Oct 2025 13:20:11 -0700 Subject: [PATCH] refactor: Replace console.error with structured logging and feedback (#12175) --- packages/cli/src/config/settings.ts | 8 ++++---- packages/cli/src/ui/utils/clipboardUtils.ts | 4 ++-- packages/core/src/tools/shell.ts | 8 ++++---- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/packages/cli/src/config/settings.ts b/packages/cli/src/config/settings.ts index 00cd27a7f7..e22ac7eb2a 100644 --- a/packages/cli/src/config/settings.ts +++ b/packages/cli/src/config/settings.ts @@ -617,10 +617,10 @@ export function loadSettings( 'utf-8', ); } catch (e) { - console.error( - `Error migrating settings file on disk: ${getErrorMessage( - e, - )}`, + coreEvents.emitFeedback( + 'error', + 'Failed to migrate settings file.', + e, ); } } else { diff --git a/packages/cli/src/ui/utils/clipboardUtils.ts b/packages/cli/src/ui/utils/clipboardUtils.ts index 85582ad621..86da766efa 100644 --- a/packages/cli/src/ui/utils/clipboardUtils.ts +++ b/packages/cli/src/ui/utils/clipboardUtils.ts @@ -6,7 +6,7 @@ import * as fs from 'node:fs/promises'; import * as path from 'node:path'; -import { spawnAsync } from '@google/gemini-cli-core'; +import { debugLogger, spawnAsync } from '@google/gemini-cli-core'; /** * Checks if the system clipboard contains an image (macOS only for now) @@ -105,7 +105,7 @@ export async function saveClipboardImage( // No format worked return null; } catch (error) { - console.error('Error saving clipboard image:', error); + debugLogger.warn('Error saving clipboard image:', error); return null; } } diff --git a/packages/core/src/tools/shell.ts b/packages/core/src/tools/shell.ts index 11c028b7fc..2a5bc4bfc5 100644 --- a/packages/core/src/tools/shell.ts +++ b/packages/core/src/tools/shell.ts @@ -9,7 +9,7 @@ import path from 'node:path'; import os, { EOL } from 'node:os'; import crypto from 'node:crypto'; import type { Config } from '../config/config.js'; -import type { AnyToolInvocation } from '../index.js'; +import { debugLogger, type AnyToolInvocation } from '../index.js'; import { ToolErrorType } from './tool-error.js'; import type { ToolInvocation, @@ -226,7 +226,7 @@ export class ShellToolInvocation extends BaseToolInvocation< .filter(Boolean); for (const line of pgrepLines) { if (!/^\d+$/.test(line)) { - console.error(`pgrep: ${line}`); + debugLogger.error(`pgrep: ${line}`); } const pid = Number(line); if (pid !== result.pid) { @@ -235,7 +235,7 @@ export class ShellToolInvocation extends BaseToolInvocation< } } else { if (!signal.aborted) { - console.error('missing pgrep output'); + debugLogger.error('missing pgrep output'); } } } @@ -424,7 +424,7 @@ export class ShellTool extends BaseDeclarativeTool< const commandCheck = isCommandAllowed(params.command, this.config); if (!commandCheck.allowed) { if (!commandCheck.reason) { - console.error( + debugLogger.error( 'Unexpected: isCommandAllowed returned false without a reason', ); return `Command is not allowed: ${params.command}`;