From 523274dbf34c6ea31c1060eae759aa06673b2f07 Mon Sep 17 00:00:00 2001 From: Sehoon Shon Date: Wed, 29 Oct 2025 18:27:17 -0400 Subject: [PATCH] Standardize error logging with coreEvents.emitFeedback (#12199) --- packages/cli/src/utils/commentJson.test.ts | 21 ++++++++++----------- packages/cli/src/utils/commentJson.ts | 8 +++++--- packages/cli/src/zed-integration/acp.ts | 3 ++- 3 files changed, 17 insertions(+), 15 deletions(-) diff --git a/packages/cli/src/utils/commentJson.test.ts b/packages/cli/src/utils/commentJson.test.ts index 4186a82802..e92b19cb63 100644 --- a/packages/cli/src/utils/commentJson.test.ts +++ b/packages/cli/src/utils/commentJson.test.ts @@ -9,6 +9,13 @@ import * as fs from 'node:fs'; import * as path from 'node:path'; import * as os from 'node:os'; import { updateSettingsFilePreservingFormat } from './commentJson.js'; +import { coreEvents } from '@google/gemini-cli-core'; + +vi.mock('@google/gemini-cli-core', () => ({ + coreEvents: { + emitFeedback: vi.fn(), + }, +})); describe('commentJson', () => { let tempDir: string; @@ -158,28 +165,20 @@ describe('commentJson', () => { fs.writeFileSync(testFilePath, corruptedContent, 'utf-8'); - const consoleSpy = vi - .spyOn(console, 'error') - .mockImplementation(() => {}); - expect(() => { updateSettingsFilePreservingFormat(testFilePath, { model: 'gemini-2.5-flash', }); }).not.toThrow(); - expect(consoleSpy).toHaveBeenCalledWith( - 'Error parsing settings file:', + expect(coreEvents.emitFeedback).toHaveBeenCalledWith( + 'error', + 'Error parsing settings file. Please check the JSON syntax.', expect.any(Error), ); - expect(consoleSpy).toHaveBeenCalledWith( - 'Settings file may be corrupted. Please check the JSON syntax.', - ); const unchangedContent = fs.readFileSync(testFilePath, 'utf-8'); expect(unchangedContent).toBe(corruptedContent); - - consoleSpy.mockRestore(); }); it('should handle array updates while preserving comments', () => { diff --git a/packages/cli/src/utils/commentJson.ts b/packages/cli/src/utils/commentJson.ts index 05b3e8dab0..5c1f9bebb2 100644 --- a/packages/cli/src/utils/commentJson.ts +++ b/packages/cli/src/utils/commentJson.ts @@ -6,6 +6,7 @@ import * as fs from 'node:fs'; import { parse, stringify } from 'comment-json'; +import { coreEvents } from '@google/gemini-cli-core'; /** * Type representing an object that may contain Symbol keys for comments. @@ -30,9 +31,10 @@ export function updateSettingsFilePreservingFormat( try { parsed = parse(originalContent) as Record; } catch (error) { - console.error('Error parsing settings file:', error); - console.error( - 'Settings file may be corrupted. Please check the JSON syntax.', + coreEvents.emitFeedback( + 'error', + 'Error parsing settings file. Please check the JSON syntax.', + error, ); return; } diff --git a/packages/cli/src/zed-integration/acp.ts b/packages/cli/src/zed-integration/acp.ts index a260c61e5f..10a993f5fa 100644 --- a/packages/cli/src/zed-integration/acp.ts +++ b/packages/cli/src/zed-integration/acp.ts @@ -11,6 +11,7 @@ import * as schema from './schema.js'; export * from './schema.js'; import type { WritableStream, ReadableStream } from 'node:stream/web'; +import { coreEvents } from '@google/gemini-cli-core'; export class AgentSideConnection implements Client { #connection: Connection; @@ -281,7 +282,7 @@ class Connection { }) .catch((error) => { // Continue processing writes on error - console.error('ACP write error:', error); + coreEvents.emitFeedback('error', 'ACP write error.', error); }); return this.#writeQueue; }